Skip to content

Instantly share code, notes, and snippets.

@gotjoshua
Last active February 16, 2021 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotjoshua/9dd958d45bdcfd1ac4ae5f11a873653b to your computer and use it in GitHub Desktop.
Save gotjoshua/9dd958d45bdcfd1ac4ae5f11a873653b to your computer and use it in GitHub Desktop.
txMemoCountForBlock.sh
#!/bin/bash
BLOCK_HEIGHT=${1:-42672} # the block with most txs during the stress test
eachPage=1
# escaping syntax from https://pkg.go.dev/github.com/qredo/tendermint/rpc/core#TxSearch
CMD="regen query txs --events 'tx.height=${BLOCK_HEIGHT}' --limit 100 --page=${eachPage}"
echo 'First Page:'
echo "$CMD | jq ."
RESULT=$(eval $CMD)
MEMOS=$(echo $RESULT | jq -r '.txs[].tx.body.memo')
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}"
RESULT=$(eval $CMD)
MEMOS+=$(echo $RESULT | jq -r '.txs[].tx.body.memo')
done
fi
echo -e "\n\n Block: $BLOCK_HEIGHT Total Txs: $COUNT "
MEMOS=($(echo $MEMOS))
(IFS=$'\n'; sort <<< "${MEMOS[*]}") | uniq -c | grep -v '1 '
@gotjoshua
Copy link
Author

hopefully the sdk will make this easier soon:
cosmos/cosmos-sdk#8579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment