Files
pallectrum/electrum/scripts/peers.py

30 lines
945 B
Python
Raw Normal View History

2017-09-05 15:27:08 +02:00
#!/usr/bin/env python3
2018-11-02 20:14:59 +01:00
import asyncio
2012-03-31 12:08:11 +02:00
2018-11-02 20:14:59 +01:00
from electrum.network import filter_protocol, Network
from electrum.util import create_and_start_event_loop, log_exceptions
from electrum.blockchain import hash_raw_header
from electrum.simple_config import SimpleConfig
config = SimpleConfig()
2013-10-06 12:28:45 +02:00
2018-11-02 20:14:59 +01:00
loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
2018-11-02 20:14:59 +01:00
network.start()
2014-03-04 22:31:12 +01: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.headers.subscribe', [])
2018-11-02 20:14:59 +01:00
for server, header in sorted(results.items(), key=lambda x: x[1].get('height')):
height = header.get('height')
blockhash = hash_raw_header(header.get('hex'))
2019-02-05 20:33:50 +01:00
print(server, height, blockhash)
2018-11-02 20:14:59 +01:00
finally:
stopping_fut.set_result(1)
asyncio.run_coroutine_threadsafe(f(), loop)