From 0db428d29a511dc44cb366df8af7e3b51c5567e9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 1 Nov 2026 12:51:06 +0000 Subject: [PATCH] xmrwallet.ops sign, import_outputs: reimplement as proper OpWallet subclasses --- mmgen/autosign/signable.py | 19 ++++++++++++------- mmgen/xmrwallet/file/outputs.py | 4 ++-- mmgen/xmrwallet/ops/export.py | 1 + mmgen/xmrwallet/ops/import.py | 23 +++++++++++------------ mmgen/xmrwallet/ops/sign.py | 18 +++++++++--------- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/mmgen/autosign/signable.py b/mmgen/autosign/signable.py index 29045fc9..67f38ae1 100644 --- a/mmgen/autosign/signable.py +++ b/mmgen/autosign/signable.py @@ -12,6 +12,7 @@ autosign.signable: Signable class for MMGen Wallet autosigning import sys +from ..cfg import Config from ..tx import UnsignedTX, SignedTX from ..util import msg, msg_r, gmsg, bmsg, die, suf, fmt_list from ..color import yellow, red, orange @@ -238,10 +239,12 @@ class Signable: automount = True summary_footer = '' - def need_daemon_restart(self, m, new_idx): + def get_cfg(self, new_idx): old_idx = self.parent.xmr_cur_wallet_idx self.parent.xmr_cur_wallet_idx = new_idx - return old_idx != new_idx or m.wd.state != 'ready' + return Config({ + '_clone': self.parent.xmrwallet_cfg, + 'no_restart_wallet_daemon': old_idx == new_idx}) def print_summary(self, signables): bmsg('\nAutosign summary:') @@ -267,11 +270,12 @@ class Signable: tx = MoneroMMGenTX.Completed(self.parent.xmrwallet_cfg, f, silent_load=silent_load) m = xmrwallet.op( 'sign', - self.parent.xmrwallet_cfg, + self.get_cfg(tx.src_wallet_idx), # sets wallet idx infile = str(self.parent.wallet_files[0]), # MMGen wallet file wallets = str(tx.src_wallet_idx), + spec = f, # tx file compat_call = compat_call) - return await m.main(f, restart_daemon=self.need_daemon_restart(m, tx.src_wallet_idx)) + return (await m.main())[0] class xmr_compat_transaction(xmr_transaction): desc = 'Monero compat transaction' @@ -307,10 +311,11 @@ class Signable: wallet_idx = xmrwallet.op_cls('wallet').get_idx_from_fn(f) m = xmrwallet.op( 'import_outputs', - self.parent.xmrwallet_cfg, + self.get_cfg(wallet_idx), # sets wallet idx infile = str(self.parent.wallet_files[0]), # MMGen wallet file - wallets = str(wallet_idx)) - obj = await m.main(f, wallet_idx, restart_daemon=self.need_daemon_restart(m, wallet_idx)) + wallets = str(wallet_idx), + spec = f) + obj = (await m.main())[0] obj.write(quiet=not obj.data.sign) self.action_desc = 'imported and signed' if obj.data.sign else 'imported' return obj diff --git a/mmgen/xmrwallet/file/outputs.py b/mmgen/xmrwallet/file/outputs.py index 634ccf54..490f9193 100644 --- a/mmgen/xmrwallet/file/outputs.py +++ b/mmgen/xmrwallet/file/outputs.py @@ -108,8 +108,8 @@ class MoneroWalletOutputsFile: self.check_checksums(d_wrap) @classmethod - def find_fn_from_wallet_fn(cls, cfg, wallet_fn, *, ret_on_no_match=False): - path = get_autosign_obj(cfg).xmr_outputs_dir or Path() + def find_fn_from_wallet_fn(cls, cfg, wallet_fn, *, ret_on_no_match=False, wallet_dir=None): + path = wallet_dir or get_autosign_obj(cfg).xmr_outputs_dir or Path() pat = cls.fn_fs.format( a = wallet_fn.name, b = f'[0-9a-f]{{{cls.chksum_nchars}}}\\', diff --git a/mmgen/xmrwallet/ops/export.py b/mmgen/xmrwallet/ops/export.py index cbac791e..f27f73f9 100644 --- a/mmgen/xmrwallet/ops/export.py +++ b/mmgen/xmrwallet/ops/export.py @@ -41,6 +41,7 @@ class OpExportOutputs(OpWallet): old_fn = getattr(MoneroWalletOutputsFile, ftype).find_fn_from_wallet_fn( cfg = self.cfg, wallet_fn = fn, + wallet_dir = None if self.cfg.autosign else self.wd.wallet_dir, ret_on_no_match = True) if old_fn: old_fn.unlink() diff --git a/mmgen/xmrwallet/ops/import.py b/mmgen/xmrwallet/ops/import.py index ea0a6ff2..f6754dfc 100644 --- a/mmgen/xmrwallet/ops/import.py +++ b/mmgen/xmrwallet/ops/import.py @@ -9,6 +9,7 @@ """ xmrwallet.ops.import: Monero wallet ops for the MMGen Suite """ +from pathlib import Path from ...util import msg, bmsg, die, suf @@ -19,19 +20,16 @@ from .wallet import OpWallet class OpImportOutputs(OpWallet): action = 'importing wallet outputs into' - start_daemon = False + stem = 'process' + return_data = True + main_starts_daemon = True - async def main(self, fn, wallet_idx, *, restart_daemon=True): - outputs_file = fn - if restart_daemon: - await self.restart_wallet_daemon() - h = MoneroWalletRPC(self, self.addr_data[0]) - self.head_msg(wallet_idx, fn) - if restart_daemon: - h.open_wallet(refresh=False) - m = MoneroWalletOutputsFile.Unsigned( - parent = self, - fn = fn) + async def process_wallet(self, d, fn, last): + h = MoneroWalletRPC(self, d) + h.open_wallet(refresh=False) + self.head_msg(d.idx, h.fn) + outputs_file = Path(self.uargs.spec) + m = MoneroWalletOutputsFile.Unsigned(parent=self, fn=outputs_file) res = self.c.call( 'import_outputs', outputs_data_hex = m.data.outputs_data_hex) @@ -63,6 +61,7 @@ class OpImportKeyImages(OpWallet): keyimage_fn = MoneroWalletOutputsFile.Signed.find_fn_from_wallet_fn( self.cfg, fn, + wallet_dir = None if self.cfg.autosign else self.wd.wallet_dir, ret_on_no_match = True) if not keyimage_fn: msg(f'No signed key image file found for wallet #{d.idx}') diff --git a/mmgen/xmrwallet/ops/sign.py b/mmgen/xmrwallet/ops/sign.py index 7b7e9145..31fc3af6 100644 --- a/mmgen/xmrwallet/ops/sign.py +++ b/mmgen/xmrwallet/ops/sign.py @@ -10,22 +10,22 @@ xmrwallet.ops.sign: Monero wallet ops for the MMGen Suite """ +from pathlib import Path from ..rpc import MoneroWalletRPC from .wallet import OpWallet class OpSign(OpWallet): action = 'signing transaction with' - start_daemon = False + stem = 'process' + return_data = True + main_starts_daemon = True - async def main(self, fn, *, restart_daemon=True): - if restart_daemon: - await self.restart_wallet_daemon() - tx = self.get_tx_cls('Unsigned')(self.cfg, fn) - h = MoneroWalletRPC(self, self.addr_data[0]) - self.head_msg(tx.src_wallet_idx, h.fn) - if restart_daemon: - h.open_wallet(refresh=False) + async def process_wallet(self, d, fn, last): + h = MoneroWalletRPC(self, d) + h.open_wallet(refresh=False) + self.head_msg(d.idx, h.fn) + tx = self.get_tx_cls('Unsigned')(self.cfg, Path(self.uargs.spec)) res = self.c.call( 'sign_transfer', unsigned_txset = tx.data.unsigned_txset,