minor whitespace, variable and method renames

This commit is contained in:
The MMGen Project 2025-04-21 14:01:16 +00:00
commit 3297f414a8
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
10 changed files with 54 additions and 53 deletions

View file

@ -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

View file

@ -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)

View file

@ -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'])

View file

@ -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:

View file

@ -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'])

View file

@ -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

View file

@ -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

View file

@ -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 '')

View file

@ -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')

View file

@ -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')