OpWallet: open wallet in main() where feasible

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

View file

@ -20,6 +20,7 @@ from .wallet import OpWallet
class OpCreate(OpWallet):
stem = 'creat'
opts = ('restore_height',)
main_opens_wallet = False
def check_uopts(self):
if self.cfg.restore_height != 'current' and int(self.cfg.restore_height or 0) < 0:

View file

@ -18,9 +18,9 @@ from .wallet import OpWallet
class OpDump(OpWallet):
wallet_offline = True
wallet_desc = 'source'
async def process_wallet(self, d, h, last):
h.open_wallet('source')
wallet_data = h.get_wallet_data(print=False)
msg('')
MoneroWalletDumpFile.New(
@ -33,11 +33,10 @@ class OpDump(OpWallet):
class OpDumpDataCommon(OpWallet):
wallet_offline = True
return_data = True
wallet_desc = 'source'
async def process_wallet(self, d, h, last):
h.open_wallet('source', refresh=not self.wallet_offline)
if (height := self.c.call('get_height')['height']) > 1:
from requests.exceptions import ConnectionError
blockcount = height - 1

View file

@ -19,10 +19,10 @@ from .wallet import OpWallet
class OpExportOutputs(OpWallet):
action = 'exporting outputs from'
stem = 'process'
wallet_desc = 'source'
sign = False
async def process_wallet(self, d, h, last):
h.open_wallet('source')
if self.cfg.rescan_blockchain:
gmsg_r('\n Rescanning blockchain...')

View file

@ -24,8 +24,6 @@ class OpImportOutputs(OpWallet):
main_starts_daemon = True
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)
outputs_file = Path(self.uargs.spec)
m = MoneroWalletOutputsFile.Unsigned(parent=self, fn=outputs_file)
@ -65,7 +63,6 @@ class OpImportKeyImages(OpWallet):
if not keyimage_fn:
msg(f'No signed key image file found for wallet #{d.idx}')
return False
h.open_wallet()
self.head_msg(d.idx, h.fn)
m = MoneroWalletOutputsFile.Signed(parent=self, fn=keyimage_fn)
data = m.data.signed_key_images or []

View file

@ -24,10 +24,11 @@ class OpNew(OpMixinSpec, OpWallet):
spec_id = 'newaddr_spec'
spec_key = ((1, 'source'),)
wallet_offline = True
wallet_desc = 'Monero'
async def main(self, add_timestr=True):
h = MoneroWalletRPC(self, self.source)
h.open_wallet('Monero', refresh=False)
h.open_wallet(self.wallet_desc, refresh=False)
desc = 'account' if self.account is None else 'address'
label = TwComment(
@ -65,7 +66,7 @@ class OpNew(OpMixinSpec, OpWallet):
# wallet must be left open: otherwise the 'stop_wallet' RPC call used to stop the daemon will fail
if self.cfg.no_stop_wallet_daemon:
h.close_wallet('Monero')
h.close_wallet(self.wallet_desc)
msg('')
return ret

View file

@ -18,6 +18,7 @@ from .create import OpCreate
class OpRestore(OpCreate):
wallet_offline = True
wallet_desc = 'newly created'
def check_uopts(self):
if self.cfg.restore_height is not None:
@ -86,7 +87,7 @@ class OpRestore(OpCreate):
await super().process_wallet(d, h, last)
h.open_wallet('newly created')
h.open_wallet(self.wallet_desc)
msg('')
data = get_dump_data()

View file

@ -130,8 +130,6 @@ class OpSign(OpWallet):
do_err(f'sum of outputs ({osum}) does not match sum of inputs ({res["amount_in"]})')
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)
tx = self.get_tx_cls('Unsigned')(self.cfg, Path(self.uargs.spec))
self.check_integrity(

View file

@ -20,6 +20,7 @@ from .wallet import OpWallet
class OpSync(OpWallet):
opts = ('rescan_blockchain', 'skip_empty_accounts', 'skip_empty_addresses')
main_opens_wallet = False
def check_uopts(self):
if self.cfg.rescan_blockchain and self.cfg.watch_only:

View file

@ -40,13 +40,13 @@ class OpList(OpSync):
class OpView(OpSync):
stem = 'open'
opts = ()
main_opens_wallet = True
wallet_offline = True
def pre_init_action(self):
ymsg('Running in offline mode. Balances may be out of date!')
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}')

View file

@ -33,11 +33,13 @@ class OpWallet(OpBase):
'no_stop_wallet_daemon',
'autosign',
'watch_only')
wallet_desc = None
wallet_offline = False
start_daemon = True
skip_wallet_check = False # for debugging
disable_authentication = False
main_starts_daemon = False
main_opens_wallet = True
def __init__(self, cfg, uarg_tuple):
@ -210,10 +212,11 @@ class OpWallet(OpBase):
b = n + 1,
c = len(self.addr_data),
d = fn.name))
data.append(await self.process_wallet(
d,
MoneroWalletRPC(self, d),
last = n == len(self.addr_data) - 1))
h = MoneroWalletRPC(self, d)
if self.main_opens_wallet:
h.open_wallet(self.wallet_desc, refresh=not self.wallet_offline)
data.append(await self.process_wallet(d, h, 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))