tw, swap: minor fixes and cleanups

This commit is contained in:
The MMGen Project 2025-05-07 18:24:02 +00:00
commit 2f7a15e9b0
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
9 changed files with 41 additions and 11 deletions

View file

@ -73,7 +73,8 @@ class BitcoinTwAddresses(TwAddresses, BitcoinTwRPC):
label = get_obj(TwLabel, proto=self.proto, text=d['label'])
if label:
assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!'
addrs[label.mmid]['recvd'] = coin_amt(d['amount'])
amt = coin_amt(d['amount'])
addrs[label.mmid]['recvd'] = amt
addrs[label.mmid]['confs'] = d['confirmations']
qmsg('done')

View file

@ -74,8 +74,7 @@ class EthereumTwAddresses(TwAddresses, EthereumTwView, EthereumTwRPC):
addrs[e.label.mmid] = {
'addr': e.coinaddr,
'amt': bal,
'recvd': bal, # since it’s nearly impossible to empty an Ethereum account,
# we consider a used account to be any account with a balance
'recvd': bal, # current bal only, CF btc.tw.addresses.get_rpc_data()
'confs': 0,
'lbl': e.label}
self.total += bal

View file

@ -104,7 +104,7 @@ class Base(TxBase):
assert d[3].hex() == o[to_key], f'{d[3].hex()}: invalid ‘to’ address in serialized data'
if not self.is_token:
if o['amt']:
assert int(d[4].hex(), 16) == o['amt'].to_unit('wei'), (
assert int(d[4].hex(), 16) == o['amt'].toWei(), (
f'{d[4].hex()}: invalid amt in serialized data')
if self.is_swap:
assert d[5] == self.swap_memo.encode(), (

View file

@ -14,7 +14,7 @@ proto.eth.tx.info: Ethereum transaction info class
from ....tx.info import TxInfo
from ....util import fmt, pp_fmt
from ....color import pink, yellow, blue, cyan
from ....color import yellow, blue, cyan, pink
from ....addr import MMGenID
class TxInfo(TxInfo):
@ -37,7 +37,7 @@ class TxInfo(TxInfo):
{toaddr} {t}{t_mmid}{tvault}
Amount: {a} {c}
Gas price: {g} Gwei
Start gas: {G} Kwei
Gas limit: {G}
Nonce: {n}
Data: {d}
""".strip().replace('\t', '') + ('\nMemo: {m}' if tx.is_swap else '')

View file

@ -53,7 +53,7 @@ class TokenSigned(TokenCompleted, Signed):
def parse_txfile_serialized_data(self):
raise NotImplementedError(
'Signed transaction files cannot be parsed offline, because tracking wallet is required!')
'Signed token transaction files cannot be parsed offline, because tracking wallet is required!')
class AutomountSigned(TxBase.AutomountSigned, Signed):
pass

View file

@ -25,7 +25,7 @@ class THORChainSwapAsset(SwapAsset):
'DOGE': _ad('Dogecoin', 'DOGE', None, 'd', False),
'RUNE': _ad('Rune (THORChain)', 'RUNE', 'THOR.RUNE', 'r', False),
'ETH.AAVE': _ad('Aave (ETH)', None, 'ETH.AAVE', None, True),
'ETH.DAI': _ad('Sky Dollar (USDS) (ETH)', None, 'ETH.DAI', None, True),
'ETH.DAI': _ad('MakerDAO USD (ETH)', None, 'ETH.DAI', None, True),
'ETH.DPI': _ad('DeFi Pulse Index (ETH)', None, 'ETH.DPI', None, True),
'ETH.FOX': _ad('ShapeShift FOX (ETH)', None, 'ETH.FOX', None, True),
'ETH.GUSD': _ad('Gemini Dollar (ETH)', None, 'ETH.GUSD', None, True),

View file

@ -47,7 +47,16 @@ class TwAddresses(TwView):
fmt_method = 'gen_display'
class TwAddress(MMGenListItem):
valid_attrs = {'twmmid', 'addr', 'al_id', 'confs', 'comment', 'amt', 'recvd', 'date', 'skip'}
valid_attrs = {
'twmmid',
'addr',
'al_id',
'confs',
'comment',
'amt',
'recvd',
'date',
'skip'}
invalid_attrs = {'proto'}
twmmid = ImmutableAttr(TwMMGenID, include_proto=True) # contains confs,txid(unused),date(unused),al_id

View file

@ -300,6 +300,13 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe
def bal4(self):
return self._bal_check(pat=rf'{dfl_sid}:E:12\s+4444\.3333\s')
def token_fund_user(self):
return self._token_transfer_ops(
op = 'fund_user',
mm_idxs = [1],
token_addr = 'token_addr1',
amt = self.token_fund_amt)
def token_txdo1(self):
return self._token_txcreate(cmd='txdo', args=[f'{dfl_sid}:E:2,1.23456', dfl_words_file])

View file

@ -104,7 +104,7 @@ class CmdTestEthSwapMethods:
def token_bal2(self):
return self._token_bal_check(pat=rf'{eth_inbound_addr}\s+\S+\s+87.654321\s')
async def _swaptxmemo(self, chk):
async def _check_token_swaptx_memo(self, chk):
from mmgen.proto.eth.contract import Contract
self.spawn(msg_only=True)
addr = get_data_from_file(self.cfg, thorchain_router_addr_file, quiet=True).strip()
@ -230,6 +230,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest):
('eth_swaptxcreate3', ''),
('eth_swaptxsign3', ''),
('eth_swaptxsend3', ''),
('eth_swaptxmemo3', ''),
# MM1 -> BTC
('eth_swaptxcreate4', ''),
('eth_swaptxsign4', ''),
@ -369,6 +370,7 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev
('swaptxcreate3', 'creating an ETH->MM1 swap transaction'),
('swaptxsign3', 'signing the transaction'),
('swaptxsend3', 'sending the transaction'),
('swaptxmemo3', 'the memo of the sent transaction'),
# MM1 -> BTC
('swaptxcreate4', 'creating an MM1->BTC swap transaction'),
@ -406,6 +408,18 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev
t = self._swaptxcreate(['ETH', '8.765', 'ETH.MM1', f'{dfl_sid}:E:5'])
return self._swaptxcreate_ui_common(t)
async def swaptxmemo3(self):
self.spawn(msg_only=True)
import json
fn = self.get_file_with_ext('sigtx')
tx = json.loads(get_data_from_file(self.cfg, fn, quiet=True).strip())
txid = tx['MMGenTransaction']['coin_txid']
chk = '=:ETH.MM1:0x48596c861c970eb4ca72c5082ff7fecd8ee5be9d:0/1/0' # E:5
imsg(f'TxID: {txid}\nmemo: {chk}')
res = await (await self.rpc).call('eth_getTransactionByHash', '0x' + txid)
chk_equal(bytes.fromhex(res['input'].removeprefix('0x')).decode(), chk)
return 'ok'
def swaptxcreate4(self):
t = self._swaptxcreate(['ETH.MM1', '87.654321', 'BTC', f'{dfl_sid}:C:2'])
return self._swaptxcreate_ui_common(t)
@ -425,7 +439,7 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev
def swaptxmemo4(self):
self.mining_delay()
return self._swaptxmemo('=:b:mkQsXA7mqDtnUpkaXMbDtAL1KMeof4GPw3:0/1/0')
return self._check_token_swaptx_memo('=:b:mkQsXA7mqDtnUpkaXMbDtAL1KMeof4GPw3:0/1/0')
def swaptxreceipt4(self):
return self._swaptxsend(add_opts=['--receipt'], spawn_only=True)