Browse Source

mmgen-txsend --status --verbose: optionally display transaction info

The MMGen Project 2 weeks ago
parent
commit
5a443c31a0
4 changed files with 28 additions and 10 deletions
  1. 4 2
      mmgen/main_txsend.py
  2. 11 4
      mmgen/proto/btc/tx/status.py
  3. 10 3
      mmgen/proto/eth/tx/status.py
  4. 3 1
      test/cmdtest_d/ct_automount.py

+ 4 - 2
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?')

+ 11 - 4
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, '')

+ 10 - 3
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

+ 3 - 1
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)