From 3297f414a8883f14292080aaa8211afcb8f42c41 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 21 Apr 2025 14:01:16 +0000 Subject: [PATCH] minor whitespace, variable and method renames --- mmgen/proto/btc/tx/completed.py | 2 +- mmgen/proto/eth/contract.py | 4 +- mmgen/proto/eth/tx/completed.py | 2 +- mmgen/proto/eth/tx/new.py | 2 +- mmgen/proto/eth/tx/status.py | 4 +- mmgen/proto/eth/tx/unsigned.py | 4 +- mmgen/tx/base.py | 1 - mmgen/tx/completed.py | 6 +-- mmgen/tx/sign.py | 10 ++--- test/cmdtest_d/ethswap.py | 72 ++++++++++++++++----------------- 10 files changed, 54 insertions(+), 53 deletions(-) diff --git a/mmgen/proto/btc/tx/completed.py b/mmgen/proto/btc/tx/completed.py index d5c33a09..174319ae 100755 --- a/mmgen/proto/btc/tx/completed.py +++ b/mmgen/proto/btc/tx/completed.py @@ -20,7 +20,7 @@ from .base import Base, decodeScriptPubKey class Completed(Base, TxBase.Completed): fn_fee_unit = 'satoshi' - def get_tx_usr_data(self): + def get_swap_memo_maybe(self): if o := self.data_output: return o.data diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index 48120944..bd11dc39 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -146,7 +146,7 @@ class Token(Contract): int(parse_abi(data)[-1], 16) * self.base_unit, from_decimal = True) - def create_token_data(self, to_addr, amt, *, op): + def create_transfer_data(self, to_addr, amt, *, op): assert op in ('transfer', 'approve'), f'{op}: invalid operation (not ‘transfer’ or ‘approve’)' return ( self.create_method_id(f'{op}(address,uint256)') @@ -160,7 +160,7 @@ class Token(Contract): gas = gas, gasPrice = gasPrice, nonce = int(nonce, 16), - data = self.create_token_data(to_addr, amt, op='transfer')) + data = self.create_transfer_data(to_addr, amt, op='transfer')) res = await self.txsign(tx_in, key, from_addr) return await self.txsend(res.txhex) diff --git a/mmgen/proto/eth/tx/completed.py b/mmgen/proto/eth/tx/completed.py index df88998d..945a1a42 100755 --- a/mmgen/proto/eth/tx/completed.py +++ b/mmgen/proto/eth/tx/completed.py @@ -18,7 +18,7 @@ from .base import Base, TokenBase class Completed(Base, TxBase.Completed): fn_fee_unit = 'Mwei' - def get_tx_usr_data(self): + def get_swap_memo_maybe(self): o = self.txobj if o['to'] and o['data']: return bytes.fromhex(o['data']) diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index e58a35e8..839acec8 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -216,7 +216,7 @@ class TokenNew(TokenBase, New): o['token_addr'] = t.addr o['decimals'] = t.decimals o['token_to'] = o['to'] - o['data'] = t.create_token_data(o['token_to'], o['amt'], op='transfer') + o['data'] = t.create_transfer_data(o['token_to'], o['amt'], op='transfer') def update_change_output(self, funds_left): if self.outputs[0].is_chg: diff --git a/mmgen/proto/eth/tx/status.py b/mmgen/proto/eth/tx/status.py index add8e08e..a50ba0a3 100755 --- a/mmgen/proto/eth/tx/status.py +++ b/mmgen/proto/eth/tx/status.py @@ -39,7 +39,9 @@ class Status(TxBase.Status): return '0x'+tx.coin_txid in pool async def is_in_wallet(): - d = await tx.rpc.call('eth_getTransactionReceipt', '0x'+tx.coin_txid) + d = await tx.rpc.call( + 'eth_getTransactionReceipt', + '0x' + tx.coin_txid) if d and 'blockNumber' in d and d['blockNumber'] is not None: from collections import namedtuple receipt_info = namedtuple('receipt_info', ['confs', 'exec_status', 'rx']) diff --git a/mmgen/proto/eth/tx/unsigned.py b/mmgen/proto/eth/tx/unsigned.py index 1bfe0850..d4161609 100755 --- a/mmgen/proto/eth/tx/unsigned.py +++ b/mmgen/proto/eth/tx/unsigned.py @@ -108,7 +108,7 @@ class TokenUnsigned(TokenCompleted, Unsigned): o['token_addr'] = TokenAddr(self.proto, d['token_addr']) o['decimals'] = Int(d['decimals']) t = Token(self.cfg, self.proto, o['token_addr'], decimals=o['decimals']) - o['data'] = t.create_token_data(o['to'], o['amt'], op='transfer') + o['data'] = t.create_transfer_data(o['to'], o['amt'], op='transfer') o['token_to'] = t.transferdata2sendaddr(o['data']) async def do_sign(self, o, wif): @@ -117,7 +117,7 @@ class TokenUnsigned(TokenCompleted, Unsigned): gas = self.gas, gasPrice = o['gasPrice'], nonce = o['nonce'], - data = t.create_token_data(o['to'], o['amt'], op='transfer')) + data = t.create_transfer_data(o['to'], o['amt'], op='transfer')) res = await t.txsign(tx_in, wif, o['from'], chain_id=o['chainId']) self.serialized = res.txhex self.coin_txid = res.txid diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index c0653a8e..498ad005 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -223,7 +223,6 @@ class Base(MMGenObject): keypress_confirm(self.cfg, 'Continue?', default_yes=True, do_exit=True) # swap methods: - @cached_property def swap_proto_mod(self): from .new_swap import get_swap_proto_mod diff --git a/mmgen/tx/completed.py b/mmgen/tx/completed.py index 346d69d2..7d69839e 100755 --- a/mmgen/tx/completed.py +++ b/mmgen/tx/completed.py @@ -70,11 +70,11 @@ class Completed(Base): return cls def check_swap_memo(self): - if data := self.get_tx_usr_data(): + if memo_bytes := self.get_swap_memo_maybe(): from ..swap.proto.thorchain import Memo - if Memo.is_partial_memo(data): + if Memo.is_partial_memo(memo_bytes): from ..protocol import init_proto - text = data.decode('ascii') + text = memo_bytes.decode('ascii') p = Memo.parse(text) assert p.function == 'SWAP', f'‘{p.function}’: unsupported function in swap memo ‘{text}’' aname = p.chain + (f'.{p.asset}' if p.asset != p.chain else '') diff --git a/mmgen/tx/sign.py b/mmgen/tx/sign.py index 9f545907..b4d7d0dd 100755 --- a/mmgen/tx/sign.py +++ b/mmgen/tx/sign.py @@ -178,18 +178,18 @@ async def txsign(cfg_parm, tx, seed_files, kl, kal, *, tx_num_str='', passwd_fil sep + sep.join(missing))) keys += tmp.data - sm_output = tx.check_swap_memo() # do this for non-swap transactions too! + memo_output = tx.check_swap_memo() # do this for non-swap transactions too! if cfg.mmgen_keys_from_file: keys += add_keys('inputs', tx.inputs, keyaddr_list=kal) add_keys('outputs', tx.outputs, keyaddr_list=kal) - if sm_output: - add_keys('swap destination address', [sm_output], keyaddr_list=kal) + if memo_output: + add_keys('swap destination address', [memo_output], keyaddr_list=kal) keys += add_keys('inputs', tx.inputs, seed_files, saved_seeds) add_keys('outputs', tx.outputs, seed_files, saved_seeds) - if sm_output: - add_keys('swap destination address', [sm_output], seed_files, saved_seeds) + if memo_output: + add_keys('swap destination address', [memo_output], seed_files, saved_seeds) # this (boolean) attr isn't needed in transaction file tx.delete_attrs('inputs', 'have_wif') diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index b2f039fa..0b334114 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -112,14 +112,14 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ), 'token_init': ( 'deploying tokens and initializing the ETH token tracking wallet', - ('eth_token_compile1', ''), - ('eth_token_deploy_a', ''), - ('eth_token_deploy_b', ''), - ('eth_token_deploy_c', ''), - ('eth_token_fund_user', ''), - ('eth_token_addrgen', ''), - ('eth_token_addrimport', ''), - ('eth_token_bal1', ''), + ('eth_token_compile1', ''), + ('eth_token_deploy_a', ''), + ('eth_token_deploy_b', ''), + ('eth_token_deploy_c', ''), + ('eth_token_fund_user', ''), + ('eth_token_addrgen', ''), + ('eth_token_addrimport', ''), + ('eth_token_bal1', ''), ), 'token_swap': ( 'token swap operations (BTC -> MM1)', @@ -153,9 +153,9 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ), 'eth_token_swap': ( 'swap operations (ETH <-> MM1)', - ('eth_swaptxcreate3', ''), - ('eth_swaptxsign3', ''), - ('eth_swaptxsend3', ''), + ('eth_swaptxcreate3', ''), + ('eth_swaptxsign3', ''), + ('eth_swaptxsend3', ''), ), } @@ -204,8 +204,8 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): def swaptxsend1(self): return self._swaptxsend() - swaptxsign2 = swaptxsign3 = swaptxsign1 - swaptxsend2 = swaptxsend3 = swaptxsend1 + swaptxsign3 = swaptxsign2 = swaptxsign1 + swaptxsend3 = swaptxsend2 = swaptxsend1 def swaptxbump1(self): # create one-output TX back to self to rescue funds return self._swaptxbump('40s', output_args=[f'{dfl_sid}:B:1']) @@ -248,26 +248,26 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev }[k] cmd_group_in = CmdTestEthdev.cmd_group_in + ( - ('fund_mmgen_addr1', 'funding user address :1)'), - ('fund_mmgen_addr2', 'funding user address :11)'), - ('swaptxcreate1', 'creating an ETH->BTC swap transaction'), - ('swaptxcreate2', 'creating an ETH->BTC swap transaction (specific address, trade limit)'), - ('swaptxsign1', 'signing the transaction'), - ('swaptxsend1', 'sending the transaction'), - ('swaptxstatus1', 'getting the transaction status (with --verbose)'), - ('swaptxcreate3', 'creating an ETH->MM1 swap transaction'), - ('swaptxsign3', 'signing the transaction'), - ('swaptxsend3', 'sending the transaction'), - ('bal1', 'the ETH balance'), - ('bal2', 'the ETH balance'), - ('token_compile1', 'compiling ERC20 token #1'), - ('token_deploy_a', 'deploying ERC20 token MM1 (SafeMath)'), - ('token_deploy_b', 'deploying ERC20 token MM1 (Owned)'), - ('token_deploy_c', 'deploying ERC20 token MM1 (Token)'), - ('token_fund_user', 'transferring token funds from dev to user'), - ('token_addrgen', 'generating token addresses'), - ('token_addrimport', 'importing token addresses using token address (MM1)'), - ('token_bal1', 'the token balance'), + ('fund_mmgen_addr1', 'funding user address :1)'), + ('fund_mmgen_addr2', 'funding user address :11)'), + ('swaptxcreate1', 'creating an ETH->BTC swap transaction'), + ('swaptxcreate2', 'creating an ETH->BTC swap transaction (spec address, trade limit)'), + ('swaptxsign1', 'signing the transaction'), + ('swaptxsend1', 'sending the transaction'), + ('swaptxstatus1', 'getting the transaction status (with --verbose)'), + ('swaptxcreate3', 'creating an ETH->MM1 swap transaction'), + ('swaptxsign3', 'signing the transaction'), + ('swaptxsend3', 'sending the transaction'), + ('bal1', 'the ETH balance'), + ('bal2', 'the ETH balance'), + ('token_compile1', 'compiling ERC20 token #1'), + ('token_deploy_a', 'deploying ERC20 token MM1 (SafeMath)'), + ('token_deploy_b', 'deploying ERC20 token MM1 (Owned)'), + ('token_deploy_c', 'deploying ERC20 token MM1 (Token)'), + ('token_fund_user', 'transferring token funds from dev to user'), + ('token_addrgen', 'generating token addresses'), + ('token_addrimport', 'importing token addresses using token address (MM1)'), + ('token_bal1', 'the token balance'), ) def swaptxcreate1(self): @@ -292,13 +292,13 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev def swaptxsend1(self): return self._swaptxsend() - swaptxsign3 = swaptxsign1 - swaptxsend3 = swaptxsend1 - def swaptxstatus1(self): self.mining_delay() return self._swaptxsend(add_opts=['--verbose', '--status'], status=True) + swaptxsign3 = swaptxsign1 + swaptxsend3 = swaptxsend1 + def bal1(self): return self.bal('swap1')