btc-submitblocks (614B)
1 #!/usr/bin/env bash 2 3 set -eou pipefail 4 5 mkdir -p /tmp/blocks 6 7 nncp-toss 8 9 blocks=$(bitcoin-cli getblockcount) 10 results=$(mktemp) 11 12 cd /tmp/blocks 13 blocklist=$(ls -1 | sort -n) 14 to_submit=$(wc -l <<<"$blocklist") 15 printf "%d blocks to submit...\n" "$to_submit" >&2 16 17 for block in $blocklist 18 do 19 res=$(<$block bitcoin-cli -stdin submitblock) 20 21 echo "$res" >> $results 22 23 if [ "$res" = "prev-blk-not-found" ]; then 24 exit 42 25 fi 26 done 27 28 echo "$(sortur < $results)" 29 rm $results 30 31 blocks2=$(bcli getblockcount) 32 33 printf "%d to height %d, processed %d blocks\n" $blocks $blocks2 $(bc <<<"$blocks2 - $blocks") 34 35 rm -rf /tmp/blocks/*