forked from itzmeanjan/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscribe_10.py
47 lines (35 loc) · 1002 Bytes
/
subscribe_10.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
#!/usr/bin/python3
from python_graphql_client import GraphqlClient
from json import dumps
import asyncio
from sys import argv
def prettyPrint(data):
print(dumps(data, sort_keys=True, indent=2))
try:
if len(argv) != 2:
raise Exception("TxHash not supplied")
hash = argv[1]
if not (hash.startswith("0x") and len(hash) == 66):
raise Exception("Bad txHash")
client = GraphqlClient(endpoint="ws://localhost:7000/v1/graphql")
query = """
subscription watchTx($hash: String!) {
watchTx(hash: $hash) {
from
to
nonce
gas
gasPrice
queuedFor
pendingFor
pool
}
}
"""
print(f'Watching tx : {hash}')
asyncio.run(client.subscribe(
query=query, handle=prettyPrint, variables={"hash": hash}))
except Exception as e:
print(e)
except KeyboardInterrupt:
print('\nStopping')