proto.eth.tx: new swap_memo attribute
This commit is contained in:
parent
3297f414a8
commit
d9e9fd6e4f
6 changed files with 14 additions and 21 deletions
|
|
@ -19,9 +19,7 @@ class Completed(Base, TxBase.Completed):
|
|||
fn_fee_unit = 'Mwei'
|
||||
|
||||
def get_swap_memo_maybe(self):
|
||||
o = self.txobj
|
||||
if o['to'] and o['data']:
|
||||
return bytes.fromhex(o['data'])
|
||||
return self.swap_memo.encode() if getattr(self, 'swap_memo', None) else None
|
||||
|
||||
@property
|
||||
def send_amt(self):
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class TxInfo(TxInfo):
|
|||
Start gas: {G} Kwei
|
||||
Nonce: {n}
|
||||
Data: {d}
|
||||
""".strip().replace('\t', '')
|
||||
""".strip().replace('\t', '') + ('\nMemo: {m}' if tx.is_swap else '')
|
||||
t = tx.txobj
|
||||
td = t['data']
|
||||
to_addr = t[self.to_addr_key]
|
||||
|
|
@ -49,10 +49,8 @@ class TxInfo(TxInfo):
|
|||
t = to_addr.hl(0) if to_addr else blue('None'),
|
||||
a = t['amt'].hl(),
|
||||
n = t['nonce'].hl(),
|
||||
d = (
|
||||
blue('None') if not td
|
||||
else pink(bytes.fromhex(td).decode()) if tx.is_swap
|
||||
else '{}... ({} bytes)'.format(td[:40], len(td)//2)),
|
||||
d = blue('None') if not td else '{}... ({} bytes)'.format(td[:40], len(td)//2),
|
||||
m = pink(tx.swap_memo) if tx.is_swap else None,
|
||||
c = tx.proto.dcoin if len(tx.outputs) else '',
|
||||
g = yellow(tx.pretty_fmt_fee(t['gasPrice'].to_unit('Gwei'))),
|
||||
G = yellow(tx.pretty_fmt_fee(t['startGas'].to_unit('Kwei'))),
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class New(Base, TxBase.New):
|
|||
async def create_serialized(self, *, locktime=None):
|
||||
assert len(self.inputs) == 1, 'Transaction has more than one input!'
|
||||
o_num = len(self.outputs)
|
||||
o_ok = 0 if self.usr_contract_data and not self.is_swap else 1
|
||||
o_ok = 0 if self.usr_contract_data else 1
|
||||
assert o_num == o_ok, f'Transaction has {o_num} output{suf(o_num)} (should have {o_ok})'
|
||||
await self.make_txobj()
|
||||
odict = {k:v if v is None else str(v) for k, v in self.txobj.items() if k != 'token_to'}
|
||||
|
|
@ -97,8 +97,8 @@ class New(Base, TxBase.New):
|
|||
data_arg = cmd_args.pop()
|
||||
lc = 1
|
||||
assert data_arg.startswith('data:'), f'{data_arg}: invalid data arg (must start with "data:")'
|
||||
self.usr_contract_data = data_arg.removeprefix('data:').encode()
|
||||
self.set_gas_with_data(self.usr_contract_data)
|
||||
self.swap_memo = data_arg.removeprefix('data:')
|
||||
self.set_gas_with_data(self.swap_memo.encode())
|
||||
|
||||
if lc == 0 and self.usr_contract_data and 'Token' not in self.name:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -19,15 +19,13 @@ class NewSwap(New, TxNewSwap):
|
|||
desc = 'Ethereum swap transaction'
|
||||
|
||||
def update_data_output(self, trade_limit):
|
||||
data = bytes.fromhex(self.txobj['data']) if self.is_bump else self.usr_contract_data
|
||||
parsed_memo = self.swap_proto_mod.Memo.parse(data.decode())
|
||||
memo = self.swap_proto_mod.Memo(
|
||||
parsed_memo = self.swap_proto_mod.Memo.parse(self.swap_memo)
|
||||
self.swap_memo = str(self.swap_proto_mod.Memo(
|
||||
self.recv_proto,
|
||||
self.recv_asset,
|
||||
self.recv_proto.coin_addr(parsed_memo.address),
|
||||
trade_limit = trade_limit)
|
||||
self.usr_contract_data = str(memo).encode()
|
||||
self.set_gas_with_data(self.usr_contract_data)
|
||||
trade_limit = trade_limit))
|
||||
self.set_gas_with_data(self.swap_memo.encode())
|
||||
|
||||
@property
|
||||
def vault_idx(self):
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ class Base(MMGenObject):
|
|||
'swap_proto': None,
|
||||
'swap_quote_expiry': None,
|
||||
'swap_recv_addr_mmid': None,
|
||||
'swap_recv_asset_spec': None}
|
||||
'swap_recv_asset_spec': None,
|
||||
'swap_memo': None}
|
||||
file_format = 'json'
|
||||
non_mmgen_inputs_msg = f"""
|
||||
This transaction includes inputs with non-{gc.proj_name} addresses. When
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ class TxInfo:
|
|||
|
||||
if tx.is_swap:
|
||||
from ..swap.proto.thorchain import Memo, name
|
||||
data = (
|
||||
(tx.usr_contract_data or bytes.fromhex(tx.txobj['data'])) if tx.proto.is_evm
|
||||
else tx.data_output.data)
|
||||
data = tx.swap_memo.encode() if tx.proto.is_evm else tx.data_output.data
|
||||
if Memo.is_partial_memo(data):
|
||||
recv_mmid = getattr(tx, 'swap_recv_addr_mmid', None)
|
||||
p = Memo.parse(data.decode('ascii'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue