XMR tracking wallet views: improve data refresh logic

This commit is contained in:
The MMGen Project 2026-11-15 10:56:44 +00:00
commit c3e7bf53c3
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 27 additions and 21 deletions

View file

@ -10,6 +10,7 @@
proto.xmr.tw.view: Monero protocol base class for tracking wallet view classes
"""
import asyncio
from collections import namedtuple
from ....obj import ImmutableAttr
@ -52,10 +53,20 @@ class MoneroTwView:
caps = ()
is_remote = False
async def get_rpc_data(self):
async def get_rpc_data(self, refresh=False):
from mmgen.tw.shared import TwMMGenID, TwLabel
op = xmrwallet_op('dump_data', self.cfg, None, None, compat_call=True)
if refresh:
from ....exception import SocketError
try:
op = xmrwallet_op('dump_data_refresh', self.cfg, None, None, compat_call=True)
except SocketError as e:
ymsg('\nRefresh failed: ' + str(e))
await asyncio.sleep(1.5)
return None
else:
op = xmrwallet_op('dump_data', self.cfg, None, None, compat_call=True)
await op.restart_wallet_daemon()
dump_data = await op.main()
@ -262,16 +273,6 @@ class MoneroTwView:
async def a_sync_wallets(self, parent):
from ....util import msg, ymsg
msg('')
try:
op = xmrwallet_op('sync', parent.cfg, None, None, compat_call=True)
except Exception as e:
if type(e).__name__ == 'SocketError':
import asyncio
ymsg(str(e))
await asyncio.sleep(2)
return False
raise
await op.restart_wallet_daemon()
await op.main()
await parent.get_data()
await parent.get_data(refresh=True)
del parent._rpc
return 'erase'

View file

@ -280,11 +280,13 @@ class TwView(MMGenObject, metaclass=AsyncInit):
if self.data != save:
self.pos = 0
async def get_data(self):
async def get_data(self, refresh=False):
rpc_data = await self.get_rpc_data()
rpc_data = await self.get_rpc_data(**({'refresh': True} if refresh else {}))
if not rpc_data:
if refresh:
return
die(1, fmt(self.no_rpcdata_errmsg).strip())
lbl_id = ('account', 'label')['label_api' in self.rpc.caps]

View file

@ -63,6 +63,7 @@ op_names = {
'resubmit': 'submit',
'abort': 'submit',
'dump_data': 'dump',
'dump_data_refresh': 'dump',
'dump_json': 'dump',
'dump': 'dump',
'restore': 'restore',
@ -84,6 +85,7 @@ kafile_arg_ops = (
'sweep',
'sweep_all',
'dump_data',
'dump_data_refresh',
'dump_json',
'dump',
'restore')

View file

@ -38,7 +38,7 @@ class OpDumpDataCommon(OpWallet):
async def process_wallet(self, d, fn, last):
h = MoneroWalletRPC(self, d)
h.open_wallet('source', refresh=False)
h.open_wallet('source', refresh=not self.wallet_offline)
return {
'seed_id': self.kal.al_id.sid,
'wallet_num': d.idx,
@ -51,6 +51,9 @@ class OpDumpData(OpDumpDataCommon):
start_daemon = False
stem = 'load'
class OpDumpDataRefresh(OpDumpData):
wallet_offline = False
class OpDumpJson(OpDumpDataCommon):
stem = 'dump'

View file

@ -833,10 +833,8 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
t.expect(menu_prompt, ch)
if ch == 'R':
for n in range(len(al)):
t.expect('Syncing')
for n in range(len(al)):
t.expect('Loading')
t.expect('Opening')
for s in ('Loading', 'Opening', 'Refreshing'):
t.expect(s)
if expect_str:
t.expect(expect_str, regex=True)
t.expect(menu_prompt, 'q')