-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (60 loc) · 2.13 KB
/
main.py
File metadata and controls
75 lines (60 loc) · 2.13 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import http.client
import json
import ssl
import sys
from google.protobuf.struct_pb2 import Struct
import grpc
from dfuse.graphql.v1 import graphql_pb2_grpc
from dfuse.graphql.v1.graphql_pb2 import Request
ssl._create_default_https_context = ssl._create_unverified_context
def token_for_api_key(apiKey):
connection = http.client.HTTPSConnection("auth.eosnation.io")
connection.request('POST', '/v1/auth/issue',
json.dumps({"api_key": apiKey}), {'Content-type': 'application/json'})
response = connection.getresponse()
if response.status != 200:
raise Exception(
f" Status: {response.status} reason: {response.reason}")
token = json.loads(response.read().decode())['token']
connection.close()
return token
def graphql_stream():
credentials = grpc.access_token_call_credentials(
token_for_api_key(sys.argv[1]))
channel = grpc.secure_channel('eos.dfuse.eosnation.io:9000',
credentials=grpc.composite_channel_credentials(grpc.ssl_channel_credentials(),
credentials))
return graphql_pb2_grpc.GraphQLStub(channel)
document = '''
subscription($query: String!, $cursor: String) {
searchTransactionsForward(query: $query, liveMarkerInterval: 12, limit: 10, cursor: $cursor) {
block {
num
}
trace {
id
matchingActions{
account
receiver
name
json
}
}
}
}
'''
variables = Struct()
variables["query"] = "account:eosio.token receiver:eosio.token action:transfer"
stream = graphql_stream()
stream = stream.Execute(Request(query=document, variables=variables))
for rawResult in stream:
if rawResult.errors:
print(rawResult.errors)
else:
result = json.loads(rawResult.data)
if result['searchTransactionsForward']['trace'] == None:
print("Live progress at block {}".format(
result['searchTransactionsForward']['block']['num']))
else:
print(result['searchTransactionsForward']
['trace']['matchingActions'])