Created
March 28, 2025 18:07
-
-
Save crosschainer/81558930aad9e7a0f41c7210c1175b80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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