ttxradar.py - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
ttxradar.py (1110B)
---
1 #!/usr/bin/env python3
2 import sys
3 import asyncio
4
5 from electrum.network import filter_protocol, Network
6 from electrum.util import create_and_start_event_loop, log_exceptions
7 from electrum.simple_config import SimpleConfig
8
9
10 try:
11 txid = sys.argv[1]
12 except:
13 print("usage: txradar txid")
14 sys.exit(1)
15
16 config = SimpleConfig()
17
18 loop, stopping_fut, loop_thread = create_and_start_event_loop()
19 network = Network(config)
20 network.start()
21
22 @log_exceptions
23 async def f():
24 try:
25 peers = await network.get_peers()
26 peers = filter_protocol(peers)
27 results = await network.send_multiple_requests(peers, 'blockchain.transaction.get', [txid])
28 r1, r2 = [], []
29 for k, v in results.items():
30 (r1 if not isinstance(v, Exception) else r2).append(k)
31 print(f"Received {len(results)} answers")
32 try: propagation = len(r1) * 100. / (len(r1) + len(r2))
33 except ZeroDivisionError: propagation = 0
34 print(f"Propagation rate: {propagation:.1f} percent")
35 finally:
36 stopping_fut.set_result(1)
37
38 asyncio.run_coroutine_threadsafe(f(), loop)