citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

btc-next-difficulty (819B)


      1 #!/usr/bin/env bash
      2 fmt="--rfc-3339=seconds"
      3 past=${1:-50}
      4 times=$(btc-blocktimes $past)
      5 blocks=$(bcli getblockcount)
      6 prev=$(bc <<<"$blocks % 2016")
      7 prevblock=$((blocks - prev))
      8 prevdate=$(bcli getblockhash $prevblock | xargs bcli getblock | jq .time | xargs -I{} date $fmt -d@{})
      9 next=$((2016 - prev))
     10 timesnext=$(bc <<<"$times * $next")
     11 timesnext=${timesnext%.*}
     12 nextdate="$(date -d "now + $timesnext seconds" $fmt)"
     13 now="$(date --rfc-3339=seconds)"
     14 nexttime=$(datediff -f '%dd %Hh' "$now" "$nextdate")
     15 prevtime=$(datediff -f '%dd %Hh' "$now" "$prevdate")
     16 times=$(qalc -t "$times seconds")
     17 printf "prev\t%s\t%s\t%s\nnext\t%s\t %s\t%s\nblocktimes($past)\t%s\n" \
     18        "$prev" \
     19        "$prevtime" \
     20        "$prevdate" \
     21        "$next" \
     22        "$nexttime" \
     23        "$nextdate" \
     24        "$times" | column -t -s $'\t'