2017-09-05 15:27:08 +02:00
|
|
|
#!/usr/bin/env python3
|
2012-04-30 11:48:19 +02:00
|
|
|
|
2014-07-29 10:43:04 +02:00
|
|
|
import sys
|
2018-11-02 20:14:59 +01:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
from electrum.network import Network
|
|
|
|
|
from electrum.util import print_msg, create_and_start_event_loop
|
|
|
|
|
from electrum.synchronizer import SynchronizerBase
|
2019-09-10 16:38:10 +02:00
|
|
|
from electrum.simple_config import SimpleConfig
|
2018-11-02 20:14:59 +01:00
|
|
|
|
2012-05-10 14:38:49 +02:00
|
|
|
|
2012-04-30 11:48:19 +02:00
|
|
|
try:
|
|
|
|
|
addr = sys.argv[1]
|
2013-11-10 12:30:57 -08:00
|
|
|
except Exception:
|
2017-09-05 15:27:08 +02:00
|
|
|
print("usage: watch_address <bitcoin_address>")
|
2012-06-14 21:11:37 +02:00
|
|
|
sys.exit(1)
|
2012-04-30 11:48:19 +02:00
|
|
|
|
2019-09-10 16:38:10 +02:00
|
|
|
config = SimpleConfig()
|
|
|
|
|
|
2014-07-29 10:43:04 +02:00
|
|
|
# start network
|
2018-11-02 20:14:59 +01:00
|
|
|
loop = create_and_start_event_loop()[0]
|
2019-09-10 16:38:10 +02:00
|
|
|
network = Network(config)
|
2014-07-29 10:43:04 +02:00
|
|
|
network.start()
|
2012-04-30 11:48:19 +02:00
|
|
|
|
2014-07-29 10:43:04 +02:00
|
|
|
|
2018-11-02 20:14:59 +01:00
|
|
|
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:
|
2022-12-20 13:58:02 +00:00
|
|
|
self.add_address(addr)
|
2018-11-02 20:14:59 +01:00
|
|
|
# main loop
|
|
|
|
|
while True:
|
|
|
|
|
addr = await self.watch_queue.get()
|
|
|
|
|
self.watched_addresses.add(addr)
|
2022-12-20 13:58:02 +00:00
|
|
|
self.add_address(addr)
|
2018-11-02 20:14:59 +01:00
|
|
|
|
|
|
|
|
async def _on_address_status(self, addr, status):
|
|
|
|
|
print_msg(f"addr {addr}, status {status}")
|
2013-10-06 12:28:45 +02:00
|
|
|
|
|
|
|
|
|
2018-11-02 20:14:59 +01:00
|
|
|
notifier = Notifier(network)
|
|
|
|
|
asyncio.run_coroutine_threadsafe(notifier.watch_queue.put(addr), loop)
|