Created
June 11, 2021 10:19
-
-
Save johnzweng/8bffc3d2d18ea140cd1c2a1c5763e154 to your computer and use it in GitHub Desktop.
Check Taproot Signalling
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 | |
# | |
# 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 "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: