Last active
September 14, 2022 20:52
Revisions
-
mutatrum revised this gist
Jun 10, 2022 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,10 +10,12 @@ function binarySearch { L=$1 R=$2 if ((R >= L)); then BLOCK=$((L + (R - L) / 2)) BLOCKTIME=$(getBlockTime $BLOCK) if ((BLOCKTIME == TIME)); then echo $BLOCK @@ -30,11 +32,15 @@ function binarySearch { BLOCKS=$(bitcoin-cli getblockchaininfo | jq -r .blocks) BLOCK=$(binarySearch 0 $BLOCKS) if ((BLOCK >= 0)); then BLOCKTIME=$(getBlockTime $BLOCK) echo "Block $BLOCK: $(date -d @$BLOCKTIME -Iseconds) $((BLOCKTIME - TIME)) seconds" fi if ((BLOCKTIME != TIME)) && ((BLOCK < BLOCKS)); then NEXTBLOCK=$((BLOCK + 1)) NEXTBLOCKTIME=$(getBlockTime $NEXTBLOCK) echo "Block $NEXTBLOCK: $(date -d @$NEXTBLOCKTIME -Iseconds) $((NEXTBLOCKTIME - TIME)) seconds" -
mutatrum revised this gist
Jun 10, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ BLOCK=$(binarySearch 0 $BLOCKS) BLOCKTIME=$(getBlockTime $BLOCK) echo "Block $BLOCK: $(date -d @$BLOCKTIME -Iseconds) $((BLOCKTIME - TIME)) seconds" if (( BLOCKTIME != TIME )) && ((BLOCK > 0)) && ((BLOCK < BLOCKS)); then NEXTBLOCK=$((BLOCK + 1)) NEXTBLOCKTIME=$(getBlockTime $NEXTBLOCK) -
mutatrum created this gist
Jun 10, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #!/bin/bash TIME=$(date -d "$1" +"%s") function getBlockTime { echo $(bitcoin-cli getblockheader $(bitcoin-cli getblockhash $1) | jq -r .time) } function binarySearch { L=$1 R=$2 if ((R > L)); then BLOCK=$((L + (R - L) / 2)) BLOCKTIME=$(getBlockTime $BLOCK) if ((BLOCKTIME == TIME)); then echo $BLOCK elif ((BLOCKTIME > TIME)); then echo $(binarySearch $L $((BLOCK - 1))) else echo $(binarySearch $((BLOCK + 1)) $R) fi else echo $R fi } BLOCKS=$(bitcoin-cli getblockchaininfo | jq -r .blocks) BLOCK=$(binarySearch 0 $BLOCKS) BLOCKTIME=$(getBlockTime $BLOCK) echo "Block $BLOCK: $(date -d @$BLOCKTIME -Iseconds) $((BLOCKTIME - TIME)) seconds" if ((BLOCKTIME < TIME)) && ((BLOCK < BLOCKS)); then NEXTBLOCK=$((BLOCK + 1)) NEXTBLOCKTIME=$(getBlockTime $NEXTBLOCK) echo "Block $NEXTBLOCK: $(date -d @$NEXTBLOCKTIME -Iseconds) $((NEXTBLOCKTIME - TIME)) seconds" fi