Skip to content

Instantly share code, notes, and snippets.

@nicovs
Created May 2, 2018 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicovs/4f5db76f43cc7e250fdc80600e98637f to your computer and use it in GitHub Desktop.
Save nicovs/4f5db76f43cc7e250fdc80600e98637f to your computer and use it in GitHub Desktop.
#!/bin/zsh
EXPLORERAPI=https://explorer.nycoin.community/api
BLOCKHIGHT=$(curl -s "$EXPLORERAPI/getblockcount")
calc(){ awk "BEGIN{ print $* }" ;}
echo "["
for i in {16376..$BLOCKHIGHT..16376}
do
HASH=$(curl -s "$EXPLORERAPI/getblockhash?index=$i")
sleep 1
DATA=$(curl -s "$EXPLORERAPI/getblock?hash=$HASH")
BITS=$(echo $DATA | jq -r ' .bits')
TIME=$(echo $DATA | jq -r ' .time')
EXP="$((16#${BITS:0:2}))"
C=$(echo $BITS | sed 's/^..//')
COEF=$((16#${C}))
echo " ["
echo " \"$HASH\","
echo " $(calc "($COEF*(2^(8*($EXP-3))))"),"
echo " $TIME"
echo " ],"
sleep 1
done
echo "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment