1
0

commands: add cmd wait_for_sync

This commit is contained in:
SomberNight
2025-05-13 16:34:06 +00:00
parent 586cf33c05
commit f3551f3c25
3 changed files with 13 additions and 1 deletions

View File

@@ -1412,6 +1412,14 @@ class Commands(Logger):
""" return wallet synchronization status """
return wallet.is_up_to_date()
@command('wn')
async def wait_for_sync(self, wallet: Abstract_Wallet = None):
"""Block until the wallet synchronization finishes."""
while True:
if wallet.is_up_to_date():
return True
await wallet.up_to_date_changed_event.wait()
@command('n')
async def getfeerate(self):
"""

View File

@@ -438,6 +438,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
# true when synchronized. this is stricter than adb.is_up_to_date():
# to-be-generated (HD) addresses are also considered here (gap-limit-roll-forward)
self._up_to_date = False
self.up_to_date_changed_event = asyncio.Event()
self.test_addresses_sanity()
if self.storage and self.has_storage_encryption():
@@ -588,6 +589,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
if status_changed or up_to_date: # suppress False->False transition, as it is spammy
util.trigger_callback('wallet_updated', self)
util.trigger_callback('status')
self.up_to_date_changed_event.set()
self.up_to_date_changed_event.clear()
if status_changed:
self.logger.info(f'set_up_to_date: {up_to_date}')

View File

@@ -114,7 +114,7 @@ if [[ $1 == "start" ]]; then
agent="./run_electrum --regtest -D /tmp/$2"
$agent daemon -d
$agent load_wallet
sleep 1 # give time to synchronize
$agent wait_for_sync
fi
if [[ $1 == "stop" ]]; then
@@ -170,6 +170,7 @@ if [[ $1 == "backup" ]]; then
$alice daemon -d
$alice load_wallet
$alice import_channel_backup $backup
$alice wait_for_sync
echo "request force close $channel1"
$alice request_force_close $channel1
echo "request force close $channel2"