tx.new, tx.new_swap, tx.info: minor cleanups
This commit is contained in:
parent
f6f56b9e1f
commit
0b3982fcbf
8 changed files with 20 additions and 23 deletions
|
|
@ -23,13 +23,14 @@ class TxInfo(VmTxInfo, TxInfo):
|
|||
def format_body(self, blockcount, nonmm_str, max_mmwid, enl, *, terse, sort):
|
||||
tx = self.tx
|
||||
t = tx.txobj
|
||||
has_memo = tx.is_swap
|
||||
fs = """
|
||||
From: {f}{f_mmid}
|
||||
Amount: {a} {c}
|
||||
Gas limit: {G}
|
||||
Sequence: {N}
|
||||
Memo: {m}
|
||||
""" if tx.is_swap else """
|
||||
""" if has_memo else """
|
||||
From: {f}{f_mmid}
|
||||
To: {t}{t_mmid}
|
||||
Amount: {a} {c}
|
||||
|
|
@ -38,14 +39,14 @@ class TxInfo(VmTxInfo, TxInfo):
|
|||
"""
|
||||
return fs.strip().replace('\t', '').format(
|
||||
f = t['from'].hl(0),
|
||||
t = None if tx.is_swap else t['to'].hl(0),
|
||||
t = None if has_memo else t['to'].hl(0),
|
||||
a = t['amt'].hl(),
|
||||
N = NonNegativeInt(t['sequence']).hl(),
|
||||
m = pink(tx.swap_memo) if tx.is_swap else None,
|
||||
m = pink(tx.swap_memo) if has_memo else None,
|
||||
c = tx.proto.dcoin if tx.outputs else '',
|
||||
G = NonNegativeInt(tx.total_gas).hl(),
|
||||
f_mmid = mmid_disp(tx.inputs[0], nonmm_str),
|
||||
t_mmid = None if tx.is_swap else mmid_disp(tx.outputs[0], nonmm_str)) + '\n\n'
|
||||
t_mmid = None if has_memo else mmid_disp(tx.outputs[0], nonmm_str)) + '\n\n'
|
||||
|
||||
def format_abs_fee(self, iwidth, /, *, color=None):
|
||||
return self.tx.fee.fmt(iwidth, color=color)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class New(VmNew, Base, TxBase.New):
|
|||
self.txobj = {
|
||||
'from': self.inputs[0].addr,
|
||||
'to': self.outputs[0].addr if self.outputs else None,
|
||||
'amt': self.outputs[0].amt if self.outputs else self.swap_amt,
|
||||
'amt': self.sum_outputs(),
|
||||
'gas': self.gas,
|
||||
'account_number': int(acct_info['account_number']),
|
||||
'sequence': int(acct_info['sequence']),
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ class Base(MMGenObject):
|
|||
locktime = None
|
||||
chain = None
|
||||
signed = False
|
||||
is_bump = False
|
||||
is_swap = False
|
||||
is_compat = False
|
||||
has_comment = True
|
||||
|
|
@ -151,13 +150,8 @@ class Base(MMGenObject):
|
|||
return sum(e.amt for e in self.inputs)
|
||||
|
||||
def sum_outputs(self, *, exclude=None):
|
||||
if exclude is None:
|
||||
olist = self.outputs
|
||||
else:
|
||||
olist = self.outputs[:exclude] + self.outputs[exclude+1:]
|
||||
if not olist:
|
||||
return self.proto.coin_amt('0')
|
||||
return sum(e.amt for e in olist)
|
||||
olist = self.outputs if exclude is None else self.outputs[:exclude] + self.outputs[exclude+1:]
|
||||
return sum(e.amt for e in olist) if olist else self.proto.coin_amt('0')
|
||||
|
||||
def _chg_output_ops(self, op, attr):
|
||||
is_chgs = [getattr(x, attr) for x in self.outputs]
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Bump(Completed, NewSwap):
|
|||
if check_sent and not self.coin_txid:
|
||||
die(1, f'Transaction {self.txid!r} was not broadcast to the network')
|
||||
|
||||
self.coin_txid = ''
|
||||
self.coin_txid = None
|
||||
self.sent_timestamp = None
|
||||
|
||||
async def get_inputs(self, outputs_sum):
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ class New(Base):
|
|||
|
||||
fee_is_approximate = False
|
||||
is_sweep = False
|
||||
is_bump = False
|
||||
msg_wallet_low_coin = 'Wallet has insufficient funds for this transaction ({} {} needed)'
|
||||
msg_no_change_output = """
|
||||
ERROR: No change address specified. If you wish to create a transaction with
|
||||
|
|
|
|||
|
|
@ -137,10 +137,10 @@ class CmdTestEthdevMethods:
|
|||
t.expect(f"'{addr}' deleted")
|
||||
return t
|
||||
|
||||
def _addrgen(self, addrs='1-3,11-13,21-23', no_msg=False):
|
||||
def _addrgen(self, addrs='1-3,11-13,21-23', no_msg=False, coin=None):
|
||||
t = self.spawn(
|
||||
'mmgen-addrgen',
|
||||
[f'--coin={self.proto.coin}'] + self.eth_opts + [dfl_words_file, addrs],
|
||||
[f'--coin={coin or self.proto.coin}'] + self.eth_opts + [dfl_words_file, addrs],
|
||||
no_msg = no_msg,
|
||||
no_passthru_opts = True)
|
||||
t.written_to_file('Addresses')
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@ class CmdTestRuneMethods:
|
|||
t.expect(prompt, 'q')
|
||||
return t
|
||||
|
||||
def _rune_txcreate(self, add_opts=[]):
|
||||
t = self.spawn('mmgen-txcreate', self.rune_opts + add_opts + ['98831F3A:X:2,54.321'])
|
||||
t.expect(self.menu_prompt, 'q')
|
||||
def _rune_txcreate(self, args=['98831F3A:X:2,54.321'], add_opts=[], append_args=[], menu_prompt=None):
|
||||
t = self.spawn('mmgen-txcreate', self.rune_opts + add_opts + args + append_args)
|
||||
t.expect(menu_prompt or self.menu_prompt, 'q')
|
||||
t.expect('spend from: ', '3\n')
|
||||
t.expect('(y/N): ', 'y') # add comment?
|
||||
t.expect('Comment: ', 'RUNE Boy\n')
|
||||
t.expect('Comment: ', 'THOR Chad #1\n')
|
||||
t.expect('view: ', 'y')
|
||||
t.expect('to continue: ', 'z')
|
||||
t.expect('(y/N): ', 'y') # save?
|
||||
|
|
|
|||
|
|
@ -100,8 +100,9 @@ class CmdTestSwapMethods:
|
|||
reload_quote = False,
|
||||
sign_and_send = False,
|
||||
need_passphrase = True,
|
||||
expect = None):
|
||||
t.expect(self.menu_prompt, 'q')
|
||||
menu_prompt = None,
|
||||
expect = None):
|
||||
t.expect(menu_prompt or self.menu_prompt, 'q')
|
||||
t.expect(self.input_sels_prompt, f'{inputs}\n')
|
||||
if reload_quote:
|
||||
t.expect('to continue: ', 'r') # reload swap quote
|
||||
|
|
@ -292,7 +293,7 @@ class CmdTestSwap(
|
|||
('subgroup.signsend', ['init_swap']),
|
||||
('subgroup.signsend_bad', ['init_swap']),
|
||||
('subgroup.autosign', ['signsend']),
|
||||
('swap_server_stop', 'stopping the Thornode server'),
|
||||
('swap_server_stop', 'stopping the Thornode swap server'),
|
||||
('stop', 'stopping regtest daemons'),
|
||||
)
|
||||
cmd_subgroups = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue