Last active
January 26, 2021 00:02
-
-
Save mutatrum/ad19dbce6c2bec29570176d768a595f1 to your computer and use it in GitHub Desktop.
Get estimated halving date from a bitcoin node
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 | |
CURRENT_BLOCK="$(bitcoin-cli getblockcount)" | |
CURRENT_BLOCK_HASH="$(bitcoin-cli getblockhash $CURRENT_BLOCK)" | |
CURRENT_BLOCK_TIME="$(bitcoin-cli getblock $CURRENT_BLOCK_HASH | jq '.mediantime')" | |
HALVING_BLOCK="$(((($CURRENT_BLOCK/210000)+1)*210000))" | |
BLOCK_DELTA="$(($HALVING_BLOCK-$CURRENT_BLOCK))" | |
PREVIOUS_BLOCK="$(($CURRENT_BLOCK-$BLOCK_DELTA))" | |
PREVIOUS_BLOCK_HASH="$(bitcoin-cli getblockhash $PREVIOUS_BLOCK)" | |
PREVIOUS_BLOCK_TIME="$(bitcoin-cli getblock $PREVIOUS_BLOCK_HASH | jq '.mediantime')" | |
DELTA_TIME="$(($CURRENT_BLOCK_TIME-$PREVIOUS_BLOCK_TIME))" | |
HALVING_TIME="$(($CURRENT_BLOCK_TIME+$DELTA_TIME))" | |
echo "$(date -d @$HALVING_TIME +%F)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change last line to
echo "$(date -d @$HALVING_TIME --iso-8601=seconds)"
to get the time in ISO