Created
February 17, 2021 19:13
-
-
Save gotjoshua/866d4b46071e80ccca9b8c2a3107f112 to your computer and use it in GitHub Desktop.
loop over a block range and report memo stats
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 | |
START_HEIGHT=${1:-41500} | |
END_HEIGHT=${2:-43200} | |
NODE="--node http://${3:-161.35.51.84}:26657" | |
LOOP_RANGE=$(eval echo {$START_HEIGHT..$END_HEIGHT}) | |
RUNNING_MEMOS=() | |
for BLOCK_HEIGHT in $LOOP_RANGE; do | |
eachPage=1 | |
CMD="regen query txs --events 'tx.height=${BLOCK_HEIGHT}' --limit 100 --page=${eachPage} $NODE" | |
# echo "First Page cmd: $CMD | jq ." # useful to check result | |
RESULT=$(eval $CMD) | |
MEMOS=$(echo $RESULT | jq -r '.txs[].tx.body.memo' | sed 's/Xtra.*//') | |
COUNT=$(echo $RESULT | jq -r '.total_count') | |
PAGES=$(( (COUNT + 100 - 1 ) / 100 )) # works because bash has no floating point https://stackoverflow.com/a/2395027/2919380 | |
echo -en "page 1" | |
if [[ $PAGES -gt 1 ]]; then | |
RANGE=$(eval echo {2..$PAGES}) | |
for eachPage in $RANGE; do | |
echo -en "\b\b..page ${eachPage}" | |
CMD="regen query txs --events 'tx.height=${BLOCK_HEIGHT}' --limit 100 --page=${eachPage} $NODE" | |
RESULT=$(eval $CMD) | |
MEMOS+=$(echo $RESULT | jq -r '.txs[].tx.body.memo' | sed 's/Xtra.*//') | |
done | |
fi | |
echo -e "\n\n Block: $BLOCK_HEIGHT Txs: $COUNT " | |
MEMOS=($(echo $MEMOS)) | |
RUNNING_MEMOS+=( "${MEMOS[@]}" ) | |
(IFS=$'\n'; sort <<< "${MEMOS[*]}") | uniq -c | sort -n | |
echo | |
(IFS=$'\n'; sort <<< "${RUNNING_MEMOS[*]}") | uniq -c | sort -n | |
echo -e "\n\n Total Txs: ${#RUNNING_MEMOS[@]} \n\n" | |
done |
Author
gotjoshua
commented
Feb 17, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment