From 3d70d6eda9e5f6de625673ebe75b853db465f28d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 26 Apr 2025 10:38:50 +0000 Subject: [PATCH] proto.eth.contract: TokenAddr -> ContractAddr --- mmgen/addr.py | 2 +- mmgen/exception.py | 2 +- mmgen/proto/eth/contract.py | 4 ++-- mmgen/proto/eth/tw/ctl.py | 6 +++--- mmgen/proto/eth/tx/online.py | 4 ++-- mmgen/proto/eth/tx/signed.py | 4 ++-- mmgen/proto/eth/tx/unsigned.py | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mmgen/addr.py b/mmgen/addr.py index f6c8e195..40f0b451 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -195,7 +195,7 @@ class CoinAddr(HiliteStr, InitErrors, MMGenObject): def is_coin_addr(proto, s): return get_obj(CoinAddr, proto=proto, addr=s, silent=True, return_bool=True) -class TokenAddr(CoinAddr): +class ContractAddr(CoinAddr): color = 'blue' def ViewKey(proto, viewkey_str): diff --git a/mmgen/exception.py b/mmgen/exception.py index 66565a2d..7dfcb941 100755 --- a/mmgen/exception.py +++ b/mmgen/exception.py @@ -55,7 +55,7 @@ class TestSuiteException(Exception): mmcode = 1 class TestSuiteSpawnedScriptException(Exception): mmcode = 1 # 2: yellow hl, message only -class InvalidTokenAddress(Exception): mmcode = 2 +class InvalidContractAddress(Exception): mmcode = 2 class UnrecognizedTokenSymbol(Exception): mmcode = 2 class TokenNotInBlockchain(Exception): mmcode = 2 class TokenNotInWallet(Exception): mmcode = 2 diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index bd11dc39..58a286af 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -29,7 +29,7 @@ from . import erigon_sleep from ...util import msg, pp_msg, die from ...base_obj import AsyncInit from ...obj import CoinTxID -from ...addr import CoinAddr, TokenAddr +from ...addr import CoinAddr, ContractAddr def parse_abi(s): return [s[:8]] + [s[8+x*64:8+(x+1)*64] for x in range(len(s[8:])//64)] @@ -101,7 +101,7 @@ class Token(Contract): self.keccak_256 = get_keccak(cfg) self.cfg = cfg self.proto = proto - self.addr = TokenAddr(proto, addr) + self.addr = ContractAddr(proto, addr) self.rpc = rpc if decimals: assert isinstance(decimals, int), f'decimals param must be int instance, not {type(decimals)}' diff --git a/mmgen/proto/eth/tw/ctl.py b/mmgen/proto/eth/tw/ctl.py index 53b07c0b..2753c88b 100755 --- a/mmgen/proto/eth/tw/ctl.py +++ b/mmgen/proto/eth/tw/ctl.py @@ -183,15 +183,15 @@ class EthereumTokenTwCtl(EthereumTwCtl): if self.importing and token_addr: if not is_coin_addr(proto, token_addr): - die('InvalidTokenAddress', f'{token_addr!r}: invalid token address') + die('InvalidContractAddress', f'{token_addr!r}: invalid token address') else: assert token_addr is None, 'EthereumTokenTwCtl_chk1' token_addr = await self.sym2addr(proto.tokensym) # returns None on failure if not is_coin_addr(proto, token_addr): die('UnrecognizedTokenSymbol', f'Specified token {proto.tokensym!r} could not be resolved!') - from ....addr import TokenAddr - self.token = TokenAddr(proto, token_addr) + from ....addr import ContractAddr + self.token = ContractAddr(proto, token_addr) if self.token not in self.data['tokens']: if self.importing: diff --git a/mmgen/proto/eth/tx/online.py b/mmgen/proto/eth/tx/online.py index 511a58b7..312da93d 100755 --- a/mmgen/proto/eth/tx/online.py +++ b/mmgen/proto/eth/tx/online.py @@ -49,12 +49,12 @@ class OnlineSigned(Signed, TxBase.OnlineSigned): class TokenOnlineSigned(TokenSigned, OnlineSigned): def parse_txfile_serialized_data(self): - from ....addr import TokenAddr + from ....addr import ContractAddr from ..contract import Token OnlineSigned.parse_txfile_serialized_data(self) o = self.txobj assert self.twctl.token == o['to'] - o['token_addr'] = TokenAddr(self.proto, o['to']) + o['token_addr'] = ContractAddr(self.proto, o['to']) o['decimals'] = self.twctl.decimals t = Token(self.cfg, self.proto, o['token_addr'], decimals=o['decimals']) o['amt'] = t.transferdata2amt(o['data']) diff --git a/mmgen/proto/eth/tx/signed.py b/mmgen/proto/eth/tx/signed.py index 408a3720..a684bd00 100755 --- a/mmgen/proto/eth/tx/signed.py +++ b/mmgen/proto/eth/tx/signed.py @@ -14,7 +14,7 @@ proto.eth.tx.signed: Ethereum signed transaction class from ....tx import signed as TxBase from ....obj import CoinTxID, ETHNonce, HexStr -from ....addr import CoinAddr, TokenAddr +from ....addr import CoinAddr, ContractAddr from .completed import Completed, TokenCompleted class Signed(Completed, TxBase.Signed): @@ -40,7 +40,7 @@ class Signed(Completed, TxBase.Signed): 'data': HexStr(d['data']) } if o['data'] and not o['to']: # token- or contract-creating transaction # NB: could be a non-token contract address: - o['token_addr'] = TokenAddr(self.proto, etx.creates.hex()) + o['token_addr'] = ContractAddr(self.proto, etx.creates.hex()) self.disable_fee_check = True txid = CoinTxID(etx.hash.hex()) assert txid == self.coin_txid, "txid in tx.serialized doesn't match value in MMGen transaction file" diff --git a/mmgen/proto/eth/tx/unsigned.py b/mmgen/proto/eth/tx/unsigned.py index 6d9b3a05..410fc66a 100755 --- a/mmgen/proto/eth/tx/unsigned.py +++ b/mmgen/proto/eth/tx/unsigned.py @@ -17,7 +17,7 @@ import json from ....tx import unsigned as TxBase from ....util import msg, msg_r, die from ....obj import CoinTxID, ETHNonce, Int, HexStr -from ....addr import CoinAddr, TokenAddr +from ....addr import CoinAddr, ContractAddr from ..contract import Token from .completed import Completed, TokenCompleted @@ -63,7 +63,7 @@ class Unsigned(Completed, TxBase.Unsigned): if not self.is_swap: raise ValueError('contract-creating transaction cannot have to-address') else: - self.txobj['token_addr'] = TokenAddr(self.proto, etx.creates.hex()) + self.txobj['token_addr'] = ContractAddr(self.proto, etx.creates.hex()) async def sign(self, tx_num_str, keys): # return TX object or False; don't exit or raise exception @@ -105,7 +105,7 @@ class TokenUnsigned(TokenCompleted, Unsigned): def parse_txfile_serialized_data(self): d = Unsigned.parse_txfile_serialized_data(self) o = self.txobj - o['token_addr'] = TokenAddr(self.proto, d['token_addr']) + o['token_addr'] = ContractAddr(self.proto, d['token_addr']) o['decimals'] = Int(d['decimals']) o['token_to'] = o['to']