Skip to content

Instantly share code, notes, and snippets.

@Reecepbcups
Created October 13, 2023 00:21
Show Gist options
  • Save Reecepbcups/2b8f90139ccbfbe293afaa7d466b2ebf to your computer and use it in GitHub Desktop.
Save Reecepbcups/2b8f90139ccbfbe293afaa7d466b2ebf to your computer and use it in GitHub Desktop.
Easy to paste Cosmos chain information for upgrade coordination
# pip install httpx (or use requests)
from httpx import get
# cosmos.directory
API = "https://juno-api.reece.sh"
ENDPOINT = "cosmos/staking/v1beta1/validators?pagination.limit=1000"
URL = f"{API}/{ENDPOINT}"
get_validators = get(URL).json().get("validators", [])
if len(get_validators) == 0:
print("No validators found")
exit(1)
class Validator:
delegator_shares: int
position: int # in the set
name: str
valoper_address: str
sorted_delegator_shares: list[Validator] = []
for validator in get_validators:
status = validator["status"]
if status != "BOND_STATUS_BONDED":
continue
v = Validator()
v.delegator_shares = int(float(validator["delegator_shares"]))
v.position = -1
v.name = validator["description"]["moniker"]
v.valoper_address = validator["operator_address"]
sorted_delegator_shares.append(v)
sorted_delegator_shares.sort(key=lambda x: x.delegator_shares, reverse=True)
for i, validator in enumerate(sorted_delegator_shares):
validator.position = i + 1
for validator in sorted_delegator_shares:
print(
f"{validator.delegator_shares},{validator.position},{validator.name.strip()},{validator.valoper_address}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment