Files
pallectrum/electrum/scripts/watch_address.py
SomberNight dc6c481406 wallet.is_up_to_date: fix flickering during sync due to race
AddressSynchronizer.add_address called synchronizer.add, which would only
schedule adding the addr to the Synchronizer in the next event loop iter.
If during that time, the synchronizer called adb.set_up_to_date(True),
the wallet would falsely believe and advertise itself as up_to_date
(as the wallet would see wallet.synchronize not creating new addresses,
and adb (via synchronizer) telling it is up_to_date).
Moments later, the synchronizer._add_address is finally executed and
up_to_date=False propagates out synchronizer->adb->wallet.
2022-12-20 13:58:02 +00:00

48 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import asyncio
from electrum.network import Network
from electrum.util import print_msg, create_and_start_event_loop
from electrum.synchronizer import SynchronizerBase
from electrum.simple_config import SimpleConfig
try:
addr = sys.argv[1]
except Exception:
print("usage: watch_address <bitcoin_address>")
sys.exit(1)
config = SimpleConfig()
# start network
loop = create_and_start_event_loop()[0]
network = Network(config)
network.start()
class Notifier(SynchronizerBase):
def __init__(self, network):
SynchronizerBase.__init__(self, network)
self.watched_addresses = set()
self.watch_queue = asyncio.Queue()
async def main(self):
# resend existing subscriptions if we were restarted
for addr in self.watched_addresses:
self.add_address(addr)
# main loop
while True:
addr = await self.watch_queue.get()
self.watched_addresses.add(addr)
self.add_address(addr)
async def _on_address_status(self, addr, status):
print_msg(f"addr {addr}, status {status}")
notifier = Notifier(network)
asyncio.run_coroutine_threadsafe(notifier.watch_queue.put(addr), loop)