mmgen-xmrwallet: add --rescan-blockchain option

This commit is contained in:
The MMGen Project 2021-06-27 20:58:02 +00:00
commit 2856c8f39d
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 18 additions and 3 deletions

View file

@ -38,6 +38,7 @@ opts_data = {
-h, --help Print this help message
--, --longhelp Print help message for long options (common
options)
-b, --rescan-blockchain Rescan the blockchain if wallet fails to sync
-d, --outdir=D Output or operate on wallets in directory 'D'
instead of working dir
-D, --daemon=H:P Connect to monerod at {D}
@ -150,6 +151,7 @@ uo = namedtuple('uopts',[
'daemon',
'tx_relay_daemon',
'restore_height',
'rescan_blockchain',
'no_start_wallet_daemon',
'no_stop_wallet_daemon',
])
@ -159,6 +161,7 @@ uopts = uo(
opt.daemon or '',
opt.tx_relay_daemon or '',
opt.restore_height or 0,
opt.rescan_blockchain,
opt.no_start_wallet_daemon,
opt.no_stop_wallet_daemon,
)

View file

@ -391,6 +391,7 @@ class MoneroWalletOps:
name = 'sync'
desc = 'Sync'
past = 'synced'
opts = ('rescan_blockchain',)
def __init__(self,uarg_tuple,uopt_tuple):
@ -432,6 +433,17 @@ class MoneroWalletOps:
if ret['received_money']:
msg(' Wallet has received funds')
while True:
wallet_height = (await self.c.call('get_height'))['height']
if wallet_height >= chain_height:
break
ymsg(f' Wallet failed to sync (wallet height [{wallet_height}] < chain height [{chain_height}])')
if not uopt.rescan_blockchain:
break
msg(' Rescanning blockchain...')
await self.c.call('rescan_blockchain')
await self.c.call('refresh')
t_elapsed = int(time.time() - t_start)
bn = os.path.basename(fn)
@ -445,11 +457,11 @@ class MoneroWalletOps:
self.accts_data[bn] = { 'accts': a, 'addrs': b }
msg(' Wallet height: {}'.format( (await self.c.call('get_height'))['height'] ))
msg(' Wallet height: {}'.format(wallet_height))
msg(' Sync time: {:02}:{:02}'.format( t_elapsed//60, t_elapsed%60 ))
await self.c.call('close_wallet')
return True
return wallet_height >= chain_height
def post_main(self):
d = self.accts_data

View file

@ -325,7 +325,7 @@ class TestSuiteXMRWallet(TestSuiteBase):
return 'ok'
def sync_wallets_selected(self):
return self.sync_wallets(wallets='1-2,4')
return self.sync_wallets(wallets='1-2,4',add_opts=['--rescan-blockchain'])
def sync_wallets(self,wallets=None,add_opts=None):
data = self.users['alice']