Last active
December 4, 2024 15:04
-
-
Save ochaloup/66c1d7c936480a59324ecde1c319dd07 to your computer and use it in GitHub Desktop.
Getting block rewards data from Solana ror an epoch
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
| export RPC_URL=... | |
| # --- Finding the list of blocks that were created in epoch | |
| SLOTS_PER_EPOCH=432000 | |
| START_BLOCK=302400000 | |
| EPOCH=$(($START_BLOCK/$SLOTS_PER_EPOCH)) | |
| echo "Epoch: $EPOCH" | |
| I=0 | |
| is_end=false | |
| while ! $is_end; do | |
| START=$(($START_BLOCK+$I*50000)) | |
| END=$(($START+50000)) | |
| if [[ $(($START_BLOCK+$SLOTS_PER_EPOCH)) -lt $END ]]; then | |
| END=$(($START_BLOCK+$SLOTS_PER_EPOCH-1)) | |
| is_end=true | |
| fi | |
| echo "$START -- $END" | |
| curl $RPC_URL -s -X POST -H "Content-Type: application/json" -d ' | |
| { | |
| "jsonrpc": "2.0", "id": 1, | |
| "method": "getBlocks", | |
| "params": [ | |
| '$START', '$END' | |
| ] | |
| }' | jq '.' | tee ~/tmp/blocks-data/"blocks-$EPOCH-$I.json" | |
| I=$((I+1)) | |
| done |
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
| #!/bin/bash | |
| # Function to create a single block request object | |
| create_block_request() { | |
| local block_num=$1 | |
| cat <<EOF | |
| { | |
| "jsonrpc": "2.0", | |
| "id": 1, | |
| "method": "getBlock", | |
| "params": [ | |
| $block_num, | |
| { | |
| "encoding": "json", | |
| "transactionDetails": "none", | |
| "rewards": true | |
| } | |
| ] | |
| } | |
| EOF | |
| } | |
| # Read numbers into an array | |
| FILE=... | |
| mapfile -t numbers < <(cat "$FILE" | jq '.' | grep -e ' [0-9]' | sed 's/,$//' | sed 's/^[ ]*//') | |
| export RPC_URL=... | |
| GROUP_SIZE=1 | |
| for ((i=0; i<${#numbers[@]}; i+=$GROUP_SIZE)); do | |
| REQUEST="[" | |
| for ((j=i; j<$((i+GROUP_SIZE)) && j<${#numbers[@]}; j++)); do | |
| if [ $j -gt $i ]; then | |
| REQUEST="$REQUEST," | |
| fi | |
| BLOCK_REQUEST=$(create_block_request "${numbers[j]}") | |
| REQUEST="$REQUEST$BLOCK_REQUEST" | |
| done | |
| REQUEST="$REQUEST]" | |
| curl "$RPC_URL" -s -X POST -H "Content-Type: application/json" -d "$REQUEST" | tee -a output-jsons.txt | |
| echo "Processed up to block: ${numbers[j]}" | |
| echo # Add newline between requests | |
| sleep 1 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment