Skip to content

Instantly share code, notes, and snippets.

@clemensgg
Created January 10, 2024 12:04
Show Gist options
  • Save clemensgg/311ec6f9883e766b3e02748cee2bb300 to your computer and use it in GitHub Desktop.
Save clemensgg/311ec6f9883e766b3e02748cee2bb300 to your computer and use it in GitHub Desktop.
fetch valset info
#!/bin/bash
daemon=$1
node=$2
limit=500
page=1
temp_file=$(mktemp)
{
echo "operator_address,voting_power,moniker"
while true; do
# Fetch validator set information
validators_json=$($daemon query staking validators --limit $limit --page $page --output json --node $node)
# Break the loop if there are no validators in the response
if [ -z "$validators_json" ] || [ "$(echo "$validators_json" | jq '.validators | length')" -eq 0 ]; then
break
fi
# Parse JSON and append to temp file for BONDED validators
echo "$validators_json" | jq -r '.validators[] | select(.status == "BOND_STATUS_BONDED") | [.operator_address, .tokens, .description.moniker] | @csv' >> "$temp_file"
((page++))
done
# Sort by voting power in descending order and output to final CSV file
sort -t, -k2,2nr "$temp_file"
} > valset_info.csv
# Clean up
rm "$temp_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment