Files
pallectrum/electrum/scripts/txradar.py

37 lines
1.0 KiB
Python
Raw Normal View History

2017-09-05 15:27:08 +02:00
#!/usr/bin/env python3
import sys
2018-11-02 20:14:59 +01:00
import asyncio
from electrum.network import filter_protocol, Network
from electrum.util import create_and_start_event_loop, log_exceptions
2014-05-21 21:15:42 +02:00
try:
2018-11-02 20:14:59 +01:00
txid = sys.argv[1]
2014-05-21 21:15:42 +02:00
except:
2017-09-05 15:27:08 +02:00
print("usage: txradar txid")
2014-05-21 21:15:42 +02:00
sys.exit(1)
2018-11-02 20:14:59 +01:00
loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network()
network.start()
2014-05-21 21:15:42 +02:00
2018-11-02 20:14:59 +01:00
@log_exceptions
async def f():
try:
2019-02-05 20:33:50 +01:00
peers = await network.get_peers()
2018-11-02 20:14:59 +01:00
peers = filter_protocol(peers, 's')
2019-02-05 20:33:50 +01:00
results = await network.send_multiple_requests(peers, 'blockchain.transaction.get', [txid])
2018-11-02 20:14:59 +01:00
r1, r2 = [], []
for k, v in results.items():
(r1 if not isinstance(v, Exception) else r2).append(k)
print(f"Received {len(results)} answers")
try: propagation = len(r1) * 100. / (len(r1) + len(r2))
except ZeroDivisionError: propagation = 0
print(f"Propagation rate: {propagation:.1f} percent")
finally:
stopping_fut.set_result(1)
2014-05-21 21:15:42 +02:00
2018-11-02 20:14:59 +01:00
asyncio.run_coroutine_threadsafe(f(), loop)