Skip to content

Instantly share code, notes, and snippets.

@johnzweng
Created June 11, 2021 10:19
Show Gist options
  • Save johnzweng/8bffc3d2d18ea140cd1c2a1c5763e154 to your computer and use it in GitHub Desktop.
Save johnzweng/8bffc3d2d18ea140cd1c2a1c5763e154 to your computer and use it in GitHub Desktop.
Check Taproot Signalling
#!/bin/bash
#
# This shell script allows you to check the Taproot signalling on your own
# Bitcoin fullnode (i.e. it does what https://taproot.watch/ does, but
# verified by your own node).
#
# Be a self-sovereign Bitcoiner!
#
# DON'T TRUST, VERIFY! :-)
#
# First check if we have the 'bitcoin-cli' and the 'jq' command available:
if ! command -v bitcoin-cli &> /dev/null
then
echo "command 'bitcoin-cli' could not be found. Are you running this script on a Bitcoin node?"
exit 1
fi
if ! command -v jq &> /dev/null
then
echo "command 'jq' could not be found. It's needed to parse JSON output. Please install it."
exit 1
fi
# Commandline argument "-v" enables verbose mode
if [[ "$1" = "-v" ]] ; then VERBOSE=1 ; else VERBOSE=0; fi
#
# Actual script starts HERE:
#
# Get current blockheight
CURRENT_BLOCKHEIGHT=$(bitcoin-cli getblockchaininfo | jq .headers)
# Difficulty periods always last 2016 blocks, so calculate 'blockheight modulo 2016'
# to find out how many blocks we already have in the current difficulty period
BLOCK_COUNT_IN_CURRENT_PERIOD=$((CURRENT_BLOCKHEIGHT % 2016))
# what is the first block in the current difficulty period
START_BLOCK_OF_CURRENT_PERIOD=$((CURRENT_BLOCKHEIGHT - BLOCK_COUNT_IN_CURRENT_PERIOD))
# initialize our counters
BLOCKS_SIGNALLING_FOR_TAPROOT=0
BLOCKS_NOT_SIGNALLING_FOR_TAPROOT=0
echo ""
echo "**************************************"
echo " Checking Taproot signalling status:"
echo "**************************************"
echo ""
echo "In the current difficulty period $BLOCK_COUNT_IN_CURRENT_PERIOD out of total 2016 blocks"
echo "have already been mined. We will check these $BLOCK_COUNT_IN_CURRENT_PERIOD blocks now,"
echo "if they signal for Taproot or not."
echo ""
# Now loop through all the blocks in the current period:
for (( height=$START_BLOCK_OF_CURRENT_PERIOD; height<=$CURRENT_BLOCKHEIGHT; height++ ))
do
# get blockhash
BLOCK_HASH=$(bitcoin-cli getblockhash $height)
# get block-header and read out the 'version' field (this will be a decimal number)
BLOCK_VERSION=$(bitcoin-cli getblockheader $BLOCK_HASH | jq .version)
# we are interested in the single bits, so let's convert it to binary representation
VERSION_IN_BINARY=$(echo "obase=2;$BLOCK_VERSION" | bc)
# as leading zero's might be omitted, let's check how long the version string in binary is
VERSION_LENGTH=${#VERSION_IN_BINARY}
# Let's find the position of the Taproot bit:
# The taproot bit is bit at index number 2.
# the most-right bit is bit #0, then bit #1, then comes bit #2.
# So the 3rd character from the right is the Taproot signal bit:
INDEX_OF_TAPROOT_BIT=$(($VERSION_LENGTH-3))
# cut out the single taproot bit
TAPROOT_BIT=${VERSION_IN_BINARY:$INDEX_OF_TAPROOT_BIT:1}
#
# Print status per block! :)
#
# In default mode (non-verbose) insert a newline after every 56 blocks (just chosen because 2016 is divisible by 56):
if [[ $VERBOSE -eq 0 && $((height % 56)) -eq 0 ]] ; then echo "" ; fi
# In verbose mode ('-v') print some progress information:
if [[ $VERBOSE -eq 1 ]] ; then echo -n "[$(($CURRENT_BLOCKHEIGHT-height)) blocks left to check]: " ; fi
if [[ $TAPROOT_BIT = "1" ]]
then
# YES, signals taproot :-)
# increase counter
BLOCKS_SIGNALLING_FOR_TAPROOT=$(($BLOCKS_SIGNALLING_FOR_TAPROOT+1))
if [[ $VERBOSE -eq 1 ]] ; then echo "Block number $height: βœ…";
else echo -n "βœ…"; fi
else
# No.. does not signal for Taproot.. :-(
# increase counter
BLOCKS_NOT_SIGNALLING_FOR_TAPROOT=$((BLOCKS_NOT_SIGNALLING_FOR_TAPROOT+1))
if [[ $VERBOSE -eq 1 ]] ; then echo "Block number $height: πŸ›‘ Oh Noooo... the block does NOT signal Taproot support. 😒";
else echo -n "πŸ›‘"; fi
fi
done
#
# Display some nice summary:
#
echo ""
echo ""
echo "*********************************************************************"
echo " SUMMARY:"
echo ""
echo " In the current difficulty period $BLOCK_COUNT_IN_CURRENT_PERIOD out of 2016 total blocks have been mined."
echo " From these $BLOCK_COUNT_IN_CURRENT_PERIOD blocks $BLOCKS_SIGNALLING_FOR_TAPROOT are signalling Taproot support."
echo ""
# Less than 1815 signalling blocks:
if [[ $BLOCKS_SIGNALLING_FOR_TAPROOT -lt 1815 ]]
then
echo " Taproot is not locked in yet. 😒 1815 blocks need to signal, "
echo " so $((1815-$BLOCKS_SIGNALLING_FOR_TAPROOT)) signalling blocks are still missing. 😒"
else
# 1815 or more signalling blocks!
echo ""
echo " πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰"
echo ""
echo " 🀩 🀩 🀩 🀩 Y A Y ! ! ! 🀩 🀩 🀩 🀩"
echo " 😍 😍 😍 Taproot has LOCKED IN! 😍 😍 😍"
echo ""
echo " ❀️ ️Taproot will be finally enabled in block number 709632!! ❀️"
echo ""
echo " πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰"
echo ""
fi
echo ""
echo "*********************************************************************"
echo ""
@johnzweng
Copy link
Author

The sha256sum of this file is expected to be b936271a924d4374a25f43638ae236f7cc87fd4d24497ce953d7edc639b743f9.

If you trust this file, you can directly execute it on your Raspiblitz, Umbrel, or any other Bitcoin fullnode with this single command:

[[ $(curl -s https://gist.githubusercontent.com/johnzweng/8bffc3d2d18ea140cd1c2a1c5763e154/raw/ | sha256sum) = "b936271a924d4374a25f43638ae236f7cc87fd4d24497ce953d7edc639b743f9  -" ]] && curl -s https://gist.githubusercontent.com/johnzweng/8bffc3d2d18ea140cd1c2a1c5763e154/raw/ | bash

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