forked from SinglePoolAlliance/Registration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology.py
30 lines (25 loc) · 1.23 KB
/
topology.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
import requests
import json
API_URL= "https://graphql-api.mainnet.dandelion.link"
r = requests.get('https://raw.githubusercontent.com/SinglePoolAlliance/Registration/master/registry.json')
pools = json.loads(r.text)
spa_relays = []
for pool in pools:
#(pool['poolId'])
headers = {'Accept-Encoding': 'gzip, deflate, br', 'Content-Type': 'application/json', 'Accept': 'application/json', 'Connection': 'keep-alive', 'DNT': '1', 'Origin': 'http://localhost:3100'}
data = {"query":'''{ stakePools ( where:
{ hash:
{ _eq: "''' + pool['poolId'] +'''"}} ) { relays { ipv4 dnsName port} } }'''}
r = requests.post(API_URL, data=json.dumps(data), headers=headers)
relays = json.loads( r.text)['data']['stakePools'][0]['relays']
for relay in relays:
if relay['ipv4'] == None :
if relay['dnsName'] == None :
print("invalid")
else :
spa_relays.append( {"addr": relay['dnsName'], "port": relay['port'], "valency": 1 } )
break
else:
spa_relays.append( {"addr": relay['ipv4'], "port": relay['port'], "valency": 1 } )
break
print(json.dumps(spa_relays, indent=4, sort_keys=True))