Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save crosschainer/81558930aad9e7a0f41c7210c1175b80 to your computer and use it in GitHub Desktop.
Save crosschainer/81558930aad9e7a0f41c7210c1175b80 to your computer and use it in GitHub Desktop.
import http.client
import json
def get_wallets():
conn = http.client.HTTPConnection("89.163.130.217", 5000)
query = """
query RichList {
allStates(
filter: {and: {key: {startsWith: "currency.balances:", notLike: "%:%:%"}, valueNumeric: {greaterThan: "0"}}}
) {
edges {
node {
key
value
}
}
}
}
"""
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
body = json.dumps({"query": query})
conn.request("POST", "/graphql", body, headers)
response = conn.getresponse()
data = response.read()
conn.close()
data = json.loads(data)
if 'errors' in data:
raise Exception(data['errors'])
if 'data' not in data:
raise Exception("No data found in response")
if 'allStates' not in data['data']:
raise Exception("No allStates found in response data")
return data['data']['allStates']['edges']
def get_total_supply(data):
total_balance = 0.0
for item in data:
balance = item['node']['value']
try:
total_balance += float(balance)
except ValueError:
continue
return total_balance
wallets = get_wallets()
global_balance = get_total_supply(wallets)
print(f"Total supply: {global_balance:.4f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment