-
Notifications
You must be signed in to change notification settings - Fork 11
/
fetch_last_height.py
53 lines (41 loc) · 1.26 KB
/
fetch_last_height.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import zmq.asyncio
import asyncio
loop = zmq.asyncio.ZMQEventLoop()
asyncio.set_event_loop(loop)
import libbitcoin.server
context = libbitcoin.server.Context()
tor_enabled = True
async def main():
if tor_enabled:
url = "tcp://iqqy3y6bdjpdij3i.onion:9091"
else:
url = "tcp://gateway.unsystem.net:9091"
# Testnet URL
url = "tcp://163.172.84.141:9091"
client_settings = libbitcoin.server.ClientSettings()
client_settings.query_expire_time = 10.0
if tor_enabled:
client_settings.socks5 = "127.0.0.1:9150"
print("Connecting:", url)
client = context.Client(url, settings=client_settings)
ec, height = await client.last_height()
if ec:
print("Couldn't fetch last_height:", ec, file=sys.stderr)
context.stop()
return
print("Last height:", height)
ec, total_connections = await client.total_connections()
if ec:
print("Couldn't fetch total_connections:", ec, file=sys.stderr)
context.stop()
return
print("Total server connections:", total_connections)
context.stop()
if __name__ == '__main__':
tasks = [
main(),
]
tasks.extend(context.tasks())
loop.run_until_complete(asyncio.wait(tasks))
loop.close()