From 5a443c31a0e62b7a060fabbcb85223c1af68288c Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 24 Feb 2025 11:27:48 +0000 Subject: [PATCH] mmgen-txsend --status --verbose: optionally display transaction info --- mmgen/main_txsend.py | 6 ++++-- mmgen/proto/btc/tx/status.py | 15 +++++++++++---- mmgen/proto/eth/tx/status.py | 13 ++++++++++--- test/cmdtest_d/ct_automount.py | 4 +++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index d7fb5cb0..9b0ee4ca 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -105,8 +105,10 @@ async def main(): if cfg.status: if tx.coin_txid: cfg._util.qmsg(f'{tx.proto.coin} txid: {tx.coin_txid.hl()}') - await tx.status.display(usr_req=True) - sys.exit(0) + retval = await tx.status.display(usr_req=True, return_exit_val=True) + if cfg.verbose: + tx.info.view_with_prompt('View transaction details?', pause=False) + sys.exit(retval) if not cfg.yes: tx.info.view_with_prompt('View transaction details?') diff --git a/mmgen/proto/btc/tx/status.py b/mmgen/proto/btc/tx/status.py index 704af5cf..09888ad7 100755 --- a/mmgen/proto/btc/tx/status.py +++ b/mmgen/proto/btc/tx/status.py @@ -20,7 +20,14 @@ from ....util2 import format_elapsed_hr class Status(TxBase.Status): - async def display(self, usr_req=False): + async def display(self, *, usr_req=False, return_exit_val=False): + + def do_exit(retval, message): + if return_exit_val: + msg(message) + return retval + else: + die(retval, message) tx = self.tx @@ -91,9 +98,9 @@ class Status(TxBase.Status): else: msg('Warning: transaction is in mempool!') elif await is_in_wallet(): - die(0, f'Transaction has {r.confs} confirmation{suf(r.confs)}') + return do_exit(0, f'Transaction has {r.confs} confirmation{suf(r.confs)}') elif await is_in_utxos(): - die(4, 'ERROR: transaction is in the blockchain (but not in the tracking wallet)!') + return do_exit(4, 'ERROR: transaction is in the blockchain (but not in the tracking wallet)!') elif await is_replaced(): msg('Transaction has been replaced') msg('Replacement transaction ' + ( @@ -110,4 +117,4 @@ class Status(TxBase.Status): d.append({}) for txid, mp_entry in zip(r.replacing_txs, d): msg(f' {txid}' + (' in mempool' if 'height' in mp_entry else '')) - die(0, '') + return do_exit(0, '') diff --git a/mmgen/proto/eth/tx/status.py b/mmgen/proto/eth/tx/status.py index 0dfdd696..03e77928 100755 --- a/mmgen/proto/eth/tx/status.py +++ b/mmgen/proto/eth/tx/status.py @@ -17,7 +17,14 @@ from ....util import msg, die, suf, capfirst class Status(TxBase.Status): - async def display(self, usr_req=False): + async def display(self, *, usr_req=False, return_exit_val=False): + + def do_exit(retval, message): + if return_exit_val: + msg(message) + return retval + else: + die(retval, message) tx = self.tx @@ -56,8 +63,8 @@ class Status(TxBase.Status): msg(f'{cd} failed to execute!') else: msg(f'{cd} successfully executed with status {ret.exec_status}') - die(0, f'Transaction has {ret.confs} confirmation{suf(ret.confs)}') - die(1, 'Transaction is neither in mempool nor blockchain!') + return do_exit(0, f'Transaction has {ret.confs} confirmation{suf(ret.confs)}') + return do_exit(1, 'Transaction is neither in mempool nor blockchain!') class TokenStatus(Status): pass diff --git a/test/cmdtest_d/ct_automount.py b/test/cmdtest_d/ct_automount.py index 5b6525bf..dc66b69b 100755 --- a/test/cmdtest_d/ct_automount.py +++ b/test/cmdtest_d/ct_automount.py @@ -165,6 +165,8 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtest): ['--alice', '--autosign', '--status', '--verbose'], exit_val = exit_val) t.expect(expect) + if not exit_val: + t.expect('view: ', 'n') t.read() self.remove_device_online() return t @@ -177,7 +179,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtest): return self._alice_txstatus('unsent', 1) def alice_txstatus3(self): - return self._alice_txstatus('in mempool') + return self._alice_txstatus('in mempool', 0) def alice_txstatus4(self): return self._alice_txstatus('1 confirmation', 0)