From 986e1ebf72871d150eea73c7f12bc7a8a546c003 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 3 Mar 2024 09:59:01 +0000 Subject: [PATCH] mmgen-xmrwallet: new `abort` operation --- mmgen/help/xmrwallet.py | 2 ++ mmgen/main_xmrwallet.py | 6 +++--- mmgen/xmrwallet.py | 10 ++++++++++ test/cmdtest_py_d/ct_xmr_autosign.py | 27 +++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/mmgen/help/xmrwallet.py b/mmgen/help/xmrwallet.py index 3efb08a2..63ef7224 100755 --- a/mmgen/help/xmrwallet.py +++ b/mmgen/help/xmrwallet.py @@ -53,6 +53,8 @@ relay - relay a transaction from a transaction file created using ‘sweep submit - submit an autosigned transaction to a wallet and the network resubmit - resubmit most recently submitted autosigned transaction (other actions are required: see Exporting Outputs below) +abort - abort the current transaction created with --autosign. The + transaction may be signed or unsigned txview - display detailed information about a transaction file or files txlist - same as above, but display terse information in tabular format dump - produce JSON dumps of wallet metadata (accounts, addresses and diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index dc15f652..a836d456 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -46,7 +46,7 @@ opts_data = { '[opts] sweep [xmr_keyaddrfile] SWEEP_SPEC', '[opts] submit [TX_file]', '[opts] relay ', - '[opts] resubmit', + '[opts] resubmit | abort (for use with --autosign only)', '[opts] txview | txlist [TX_file] ...', '[opts] export-outputs [wallets]', '[opts] import-key-images [wallets]', @@ -110,7 +110,7 @@ if cmd_args and cfg.autosign and ( MoneroWalletOps.kafile_arg_ops + ('export-outputs','import-key-images','txview','txlist') ) - or len(cmd_args) == 1 and cmd_args[0] in ('submit','resubmit') + or len(cmd_args) == 1 and cmd_args[0] in ('submit', 'resubmit', 'abort') ): cmd_args.insert(1,None) @@ -121,7 +121,7 @@ op = cmd_args.pop(0) infile = cmd_args.pop(0) wallets = spec = None -if op in ('relay','submit','resubmit'): +if op in ('relay', 'submit', 'resubmit', 'abort'): if len(cmd_args) != 0: cfg._opts.usage() elif op in ('txview','txlist'): diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 51a663e9..c0a335e0 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -629,6 +629,7 @@ class MoneroWalletOps: 'sign', 'submit', 'resubmit', + 'abort', 'dump', 'restore', 'export_outputs', @@ -1854,6 +1855,15 @@ class MoneroWalletOps: key = lambda x: getattr(x.data,'submit_time',None) or x.data.create_time )[-1] + class abort(base): + opts = ('watch_only','autosign') + + def __init__(self, cfg, uarg_tuple): + super().__init__(cfg,uarg_tuple) + self.mount_removable_device() + from .autosign import Signable + Signable.xmr_transaction(self.asi).shred_abortable() # prompts user, then raises exception or exits + class dump(wallet): wallet_offline = True diff --git a/test/cmdtest_py_d/ct_xmr_autosign.py b/test/cmdtest_py_d/ct_xmr_autosign.py index 11b33600..619f56bd 100755 --- a/test/cmdtest_py_d/ct_xmr_autosign.py +++ b/test/cmdtest_py_d/ct_xmr_autosign.py @@ -73,7 +73,10 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded): ('export_outputs1', 'exporting outputs from Alice’s watch-only wallet #1'), ('import_key_images1', 'importing signed key images into Alice’s online wallets'), ('sync_chkbal1', 'syncing Alice’s wallet #1'), + ('abort_tx1', 'aborting the current transaction (error)'), ('create_transfer_tx2', 'creating a transfer TX (for relaying via proxy)'), + ('abort_tx2', 'aborting the current transaction (OK, unsigned)'), + ('create_transfer_tx2a', 'creating the transfer TX again'), ('submit_transfer_tx2', 'submitting the transfer TX (relaying via proxy)'), ('sync_chkbal2', 'syncing Alice’s wallets and checking balance'), ('dump_wallets', 'dumping Alice’s wallets'), @@ -248,12 +251,28 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded): return self._create_transfer_tx('0.124') def create_transfer_tx2(self): - self.do_mount_online() - get_file_with_ext(self.asi_online.xmr_tx_dir,'rawtx',delete_all=True) - get_file_with_ext(self.asi_online.xmr_tx_dir,'sigtx',delete_all=True) - self.do_umount_online() return self._create_transfer_tx('0.257') + create_transfer_tx2a = create_transfer_tx2 + + def _abort_tx(self,expect,send=None,exit_val=None): + self.insert_device_online() + t = self.spawn('mmgen-xmrwallet', ['--autosign', 'abort']) + t.expect(expect) + if send: + t.send(send) + t.read() # required! + self.remove_device_online() + if exit_val: + t.req_exit_val = exit_val + return t + + def abort_tx1(self): + return self._abort_tx('No unsent transactions present', exit_val=2) + + def abort_tx2(self): + return self._abort_tx('(y/N): ', 'y') + def _xmr_autosign_op( self, op,