OpWallet: pass RPC instance to process_wallet()

This commit is contained in:
The MMGen Project 2026-11-16 10:45:27 +00:00
commit 37db58491c
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
10 changed files with 32 additions and 52 deletions

View file

@ -25,7 +25,7 @@ class OpCreate(OpWallet):
if self.cfg.restore_height != 'current' and int(self.cfg.restore_height or 0) < 0:
die(1, f'{self.cfg.restore_height}: invalid value for --restore-height (less than zero)')
async def process_wallet(self, d, fn, last):
async def process_wallet(self, d, h, last):
msg_r('') # for pexpect
if self.cfg.restore_height == 'current':
@ -36,7 +36,7 @@ class OpCreate(OpWallet):
if self.cfg.watch_only:
ret = self.c.call(
'generate_from_keys',
filename = fn.name,
filename = h.fn.name,
password = d.wallet_passwd,
address = d.addr,
viewkey = d.viewkey,
@ -45,7 +45,7 @@ class OpCreate(OpWallet):
from ...xmrseed import xmrseed
ret = self.c.call(
'restore_deterministic_wallet',
filename = fn.name,
filename = h.fn.name,
password = d.wallet_passwd,
seed = xmrseed().fromhex(d.sec.wif, tostr=True),
restore_height = restore_height,

View file

@ -13,21 +13,19 @@ xmrwallet.ops.dump: Monero wallet ops for the MMGen Suite
from ...util import msg, Msg
from ..file.outputs import MoneroWalletDumpFile
from ..rpc import MoneroWalletRPC
from .wallet import OpWallet
class OpDump(OpWallet):
wallet_offline = True
async def process_wallet(self, d, fn, last):
h = MoneroWalletRPC(self, d)
async def process_wallet(self, d, h, last):
h.open_wallet('source')
wallet_data = h.get_wallet_data(print=False)
msg('')
MoneroWalletDumpFile.New(
parent = self,
wallet_fn = fn,
wallet_fn = h.fn,
data = {'wallet_metadata': wallet_data.addrs_data}
).write()
return True
@ -36,9 +34,8 @@ class OpDumpDataCommon(OpWallet):
wallet_offline = True
return_data = True
async def process_wallet(self, d, fn, last):
async def process_wallet(self, d, h, last):
h = MoneroWalletRPC(self, d)
h.open_wallet('source', refresh=not self.wallet_offline)
if (height := self.c.call('get_height')['height']) > 1:

View file

@ -13,7 +13,6 @@ xmrwallet.ops.export: Monero wallet ops for the MMGen Suite
from ...util import gmsg, gmsg_r
from ..file.outputs import MoneroWalletOutputsFile
from ..rpc import MoneroWalletRPC
from .wallet import OpWallet
@ -22,8 +21,7 @@ class OpExportOutputs(OpWallet):
stem = 'process'
sign = False
async def process_wallet(self, d, fn, last):
h = MoneroWalletRPC(self, d)
async def process_wallet(self, d, h, last):
h.open_wallet('source')
if self.cfg.rescan_blockchain:
@ -40,14 +38,14 @@ class OpExportOutputs(OpWallet):
for ftype in ('Unsigned', 'Signed'):
old_fn = getattr(MoneroWalletOutputsFile, ftype).find_fn_from_wallet_fn(
cfg = self.cfg,
wallet_fn = fn,
wallet_fn = h.fn,
wallet_dir = None if self.cfg.autosign else self.wd.wallet_dir,
ret_on_no_match = True)
if old_fn:
old_fn.unlink()
m = MoneroWalletOutputsFile.New(
parent = self,
wallet_fn = fn,
wallet_fn = h.fn,
data = self.c.call('export_outputs', all=True),
sign = self.sign)
m.write()

View file

@ -14,7 +14,6 @@ from pathlib import Path
from ...util import msg, bmsg, die, suf
from ..file.outputs import MoneroWalletOutputsFile
from ..rpc import MoneroWalletRPC
from .wallet import OpWallet
@ -24,8 +23,7 @@ class OpImportOutputs(OpWallet):
return_data = True
main_starts_daemon = True
async def process_wallet(self, d, fn, last):
h = MoneroWalletRPC(self, d)
async def process_wallet(self, d, h, last):
if self.need_daemon_start or len(self.kal.data) != 1:
h.open_wallet(refresh=False)
self.head_msg(d.idx, h.fn)
@ -58,16 +56,15 @@ class OpImportKeyImages(OpWallet):
rw_msg = ' for requested wallets' if self.uargs.wallets else ''
die(2, f'No signed key image files found{rw_msg}!')
async def process_wallet(self, d, fn, last):
async def process_wallet(self, d, h, last):
keyimage_fn = MoneroWalletOutputsFile.Signed.find_fn_from_wallet_fn(
self.cfg,
fn,
h.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}')
return False
h = MoneroWalletRPC(self, d)
h.open_wallet()
self.head_msg(d.idx, h.fn)
m = MoneroWalletOutputsFile.Signed(parent=self, fn=keyimage_fn)

View file

@ -13,7 +13,6 @@ xmrwallet.ops.restore: Monero wallet ops for the MMGen Suite
from ...util import msg, gmsg, bmsg, ymsg, rmsg, die
from ..file.outputs import MoneroWalletDumpFile
from ..rpc import MoneroWalletRPC
from .create import OpCreate
@ -24,7 +23,7 @@ class OpRestore(OpCreate):
if self.cfg.restore_height is not None:
die(1, '--restore-height must be unset when running the ‘restore’ command')
async def process_wallet(self, d, fn, last):
async def process_wallet(self, d, h, last):
def get_dump_data():
@ -37,9 +36,9 @@ class OpRestore(OpCreate):
match tuple(gen()):
case [dump_fn, *rest]:
if rest:
ymsg(f'Warning: more than one dump file found for ‘{fn}’ - using the first!')
ymsg(f'Warning: more than one dump file found for ‘{h.fn}’ - using the first!')
case _:
die(1, f'No suitable dump file found for ‘{fn}’')
die(1, f'No suitable dump file found for ‘{h.fn}’')
return MoneroWalletDumpFile.Completed(
parent = self,
@ -80,14 +79,13 @@ class OpRestore(OpCreate):
rmsg('Restored data does not match original dump! Dumping bad data.')
MoneroWalletDumpFile.New(
parent = self,
wallet_fn = fn,
wallet_fn = h.fn,
data = {'wallet_metadata': restored_data}
).write(add_suf='.bad')
die(3, 'Fatal error')
await super().process_wallet(d, fn, last)
await super().process_wallet(d, h, last)
h = MoneroWalletRPC(self, d)
h.open_wallet('newly created')
msg('')

View file

@ -14,8 +14,6 @@ from pathlib import Path
from ...util import ymsg, die
from ..rpc import MoneroWalletRPC
from .wallet import OpWallet
class OpSign(OpWallet):
@ -131,8 +129,7 @@ class OpSign(OpWallet):
if (osum := odata[0]['amount'] + res['change_amount'] + res['fee']) != res['amount_in']:
do_err(f'sum of outputs ({osum}) does not match sum of inputs ({res["amount_in"]})')
async def process_wallet(self, d, fn, last):
h = MoneroWalletRPC(self, d)
async def process_wallet(self, d, h, last):
if self.need_daemon_start or len(self.kal.data) != 1:
h.open_wallet(refresh=False)
self.head_msg(d.idx, h.fn)

View file

@ -35,19 +35,13 @@ class OpSync(OpWallet):
self.wallets_data = {}
async def process_wallet(self, d, fn, last):
async def process_wallet(self, d, h, last):
chain_height = self.dc.call_raw('get_height')['height']
msg(f' Chain height: {chain_height}')
t_start = time.time()
msg_r(' Opening wallet...')
self.c.call(
'open_wallet',
filename = fn.name,
password = d.wallet_passwd)
msg('done')
h.open_wallet(refresh=False)
msg_r(' Getting wallet height (be patient, this could take a long time)...')
wallet_height = self.c.call('get_height')['height']
@ -88,7 +82,7 @@ class OpSync(OpWallet):
hl_amt(wd.accts_data['total_balance']),
hl_amt(wd.accts_data['total_unlocked_balance'])))
self.wallets_data[fn.name] = wd
self.wallets_data[h.fn.name] = wd
msg(f' Wallet height: {wallet_height}')
msg(f' Sync time: {t_elapsed//60:02}:{t_elapsed%60:02}')

View file

@ -14,7 +14,6 @@ from ...color import green
from ...util import msg, ymsg
from ..include import gen_acct_addr_info
from ..rpc import MoneroWalletRPC
from .sync import OpSync
@ -46,19 +45,13 @@ class OpView(OpSync):
def pre_init_action(self):
ymsg('Running in offline mode. Balances may be out of date!')
async def process_wallet(self, d, fn, last):
self.c.call(
'open_wallet',
filename = fn.name,
password = d.wallet_passwd)
async def process_wallet(self, d, h, last):
h.open_wallet(refresh=False)
wallet_height = self.c.call('get_height')['height']
msg(f' Wallet height: {wallet_height}')
self.wallets_data[fn.name] = MoneroWalletRPC(self, d).get_wallet_data(
print = False,
skip_empty_ok = True)
self.wallets_data[h.fn.name] = h.get_wallet_data(print=False, skip_empty_ok=True)
if not last:
self.c.call('close_wallet')

View file

@ -19,6 +19,8 @@ from ...addrlist import KeyAddrList, ViewKeyAddrList, AddrIdxList
from ...proto.xmr.rpc import MoneroWalletRPCClient
from ...proto.xmr.daemon import MoneroWalletDaemon
from ..rpc import MoneroWalletRPC
from . import OpBase
class OpWallet(OpBase):
@ -208,7 +210,10 @@ class OpWallet(OpBase):
b = n + 1,
c = len(self.addr_data),
d = fn.name))
data.append(await self.process_wallet(d, fn, last=n == len(self.addr_data) - 1))
data.append(await self.process_wallet(
d,
MoneroWalletRPC(self, d),
last = n == len(self.addr_data) - 1))
if not self.compat_call:
gmsg(f'\n{len(data)} wallet{suf(len(data))} {self.stem}ed\n')
return data if self.return_data else sum(map(bool, data))

View file

@ -1007,12 +1007,13 @@ class CmdTestXMRCompatDev(CmdTestXMRCompat):
user_data = (
# user sid autosign kal_range add_coind_args
udata('miner', '98831F3A', False, '1', []),
udata('alice', 'FE3C6545', True, '1', []))
udata('alice', 'FE3C6545', True, '1-2', []))
cmd_group = (
('autosign_setup', 'autosign setup with user’s seed'),
('autosign_xmr_setup', 'autosign setup (creation of Monero signing wallet)'),
('addrimport_user', 'creating (importing) user’s watch-only wallet from key-address file'),
('gen_vkafile_user', 'generating viewkey-address file for user'),
('user_listaddresses_refresh', 'refreshing wallet'),
('gen_kafile_miner', 'generating key-address file for Miner'),
('create_wallet_miner', 'creating Monero wallet for Miner'),
('mine_initial_coins', 'mining initial coins'),