-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_header.py
More file actions
39 lines (30 loc) · 984 Bytes
/
Copy pathfetch_header.py
File metadata and controls
39 lines (30 loc) · 984 Bytes
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
#!/usr/bin/env python3
import asyncio
import ssl
import json
SERVER = 'electrumx.gorillapool.io'
PORT = 50002
CERT_FILE = 'gorillapool.pem'
async def fetch_header(height=0):
ssl_ctx = ssl.create_default_context(cafile=CERT_FILE)
ssl_ctx.check_hostname = False
ssl_ctx.verify_mode = ssl.CERT_REQUIRED
print(f"Connecting to {SERVER}:{PORT} (SSL)...")
reader, writer = await asyncio.open_connection(SERVER, PORT, ssl=ssl_ctx)
try:
request = json.dumps({
'id': 0,
'method': 'blockchain.block.header',
'params': [height]
}) + '\n'
writer.write(request.encode())
await writer.drain()
response = await reader.readline()
data = json.loads(response.decode())
print(f"Header at height {height}:")
print(json.dumps(data, indent=4))
finally:
writer.close()
await writer.wait_closed()
if __name__ == '__main__':
asyncio.run(fetch_header())