xmrwallet.ops sign, import_outputs: reimplement as proper OpWallet subclasses

This commit is contained in:
The MMGen Project 2026-11-01 12:51:06 +00:00
commit 0db428d29a
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 35 additions and 30 deletions

View file

@ -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

View file

@ -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}}}\\',

View file

@ -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()

View file

@ -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}')

View file

@ -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,