-
-
Save vindard/7437da89b6df58a1bebd78a279c5354e to your computer and use it in GitHub Desktop.
Print a taproot signalling block diagram
This file contains 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 | |
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo) | |
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks) | |
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9) | |
SINCE=$(echo "$TAPROOT" | jq .since) | |
PERIOD=$(echo "$TAPROOT" | jq .statistics.period) | |
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks) | |
PERIOD_COUNT=$(((BLOCKS - SINCE) / PERIOD)) | |
SINCE=$((SINCE + (PERIOD * PERIOD_COUNT))) | |
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed) | |
echo && echo "Printing graph for $ELAPSED of $PERIOD blocks in this period:" && echo | |
for BLOCK in $(seq "$SINCE" $((SINCE + ELAPSED - 1))); do | |
HASH=$(bitcoin-cli getblockhash "$BLOCK") | |
HEADER=$(bitcoin-cli getblockheader "$HASH") | |
VERSION=$(echo "$HEADER" | jq .version) | |
SIGNAL=$(((VERSION & 3758096388) == 536870916)) | |
if [[ "$1" == "watch" ]]; then | |
case $SIGNAL in | |
(0) echo -e -n "\033[1;31m▅\033[0m";; | |
(1) echo -e -n "\033[1;32m▅\033[0m";; | |
esac | |
else | |
case $SIGNAL in | |
(0) echo -n "🟥";; | |
(1) echo -n "🟩";; | |
esac | |
fi | |
if ((($BLOCK + 1) % 48 == 0)); then echo; fi | |
done | |
echo | |
PERCENTAGE=`echo $BLOCKCHAININFO | jq '.softforks.taproot.bip9.statistics | .count / .elapsed * 100'` | |
export PERIOD=$PERIOD | |
export SIGNAL=`echo $BLOCKCHAININFO | jq '.softforks.taproot.bip9.statistics.count'` | |
SIGNAL_OVERALL=$(python3 -c "import os; percent = int(os.environ['SIGNAL']) / int(os.environ['PERIOD']); print(round(percent*100, 2))") | |
export NON_SIGNAL=`echo $BLOCKCHAININFO | jq '.softforks.taproot.bip9.statistics | .elapsed - .count'` | |
NON_SIGNAL_OVERALL=$(python3 -c "import os; print( round(int(os.environ['NON_SIGNAL']) / int(os.environ['PERIOD']), 4) * 100 )") | |
echo && echo "---" && echo | |
echo "> $SIGNAL signaling blocks (${SIGNAL_OVERALL}%) | $NON_SIGNAL non-signaling blocks (${NON_SIGNAL_OVERALL}%)" | |
WILL_LOCK="will lock in" | |
if (( $(echo "$PERCENTAGE 90" | awk '{print ($1 < $2)}') )); then WILL_LOCK="will not lock in"; fi | |
printf "> Taproot \033[1m${WILL_LOCK}\033[0m with current signaling ratio: %.2f%% (90%% required)\n" $PERCENTAGE | |
echo | |
if (( $(echo "$NON_SIGNAL_OVERALL 10" | awk '{print ($1 > $2)}') )); then | |
echo -e "\033[1mTaproot WILL NOT lock in for this period.\033[0m" | |
elif (( $(echo "$SIGNAL_OVERALL 90" | awk '{print ($1 > $2)}') )); then | |
echo -e "\033[1mTaproot WILL lock in for this period.\033[0m" | |
else | |
echo -e "\033[1mTaproot MAY STILL lock in for this period.\033[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment