Skip to content

Instantly share code, notes, and snippets.

@cryptozeny
Last active January 6, 2019 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptozeny/7420cc8107cfb917dd967510b704d1bd to your computer and use it in GitHub Desktop.
Save cryptozeny/7420cc8107cfb917dd967510b704d1bd to your computer and use it in GitHub Desktop.
RPC getBlockInterval +Date

https://youtu.be/E97kpbg1j_o

BLOCK        TIMESTAMP             DIFFICULTY  RATIO  IV  AVERG
0      181101-03:10:00  1.907323166912278e-06  1.216 GENESIS GENESIS 
1      190104-23:20:58  1.907323166912278e-06  1.000 5602258      0 
2      190104-23:24:09  1.907323166912278e-06  1.000 191  95.50 
3      190104-23:24:09  1.907323166912278e-06  1.000   0  63.66 
4      190104-23:24:15  1.907323166912278e-06  1.000   6  49.25 
.
.
.
195    190104-23:47:41  1.907323166912278e-06  1.000   1   8.22 
196    190104-23:47:42  1.907323166912278e-06  1.000   1   8.18 
197    190104-23:47:44  1.907323166912278e-06  1.000   2   8.15 
198    190104-23:47:57  1.907323166912278e-06  1.000  13   8.17 
199    190104-23:47:58  1.907323166912278e-06  1.000   1   8.14 
200    190104-23:47:59  1.907323166912278e-06  1.000   1   8.10 
201    190104-23:48:02  2.353270722537941e-06  1.233   3   8.07 
202    190104-23:48:09   2.66703136533003e-06  1.398   7   8.07 
203    190104-23:48:10  2.659109560205652e-06  1.394   1   8.03 
204    190104-23:48:23  2.672119854984348e-06  1.400  13   8.06 
205    190104-23:48:49  2.668554451913083e-06  1.399  26   8.15
#FULL-Date
#!/bin/bash
difficultyInit=$(echo "1.907323166912278e-06" | sed 's#\([+-]\{0,1\}[0-9]*\.\{0,1\}[0-9]\{1,\}\)[eE]+\{0,1\}\(-\{0,1\}\)\([0-9]\{1,\}\)#(\1*10^\2\3)#g' | bc -l) && \
blockIntervalAVG=0 && \
blockIntervalAVGtotal=-5602258 && \
curBlockNumber=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockcount) && \
printf "\n\n\n\n\n" && \
printf "%-5s %16s %22s %6s %3s %6s\n" BLOCK TIMESTAMP DIFFICULTY RATIO IV AVERG && \
sleep 1 && \
for(( i=0; i<=( $curBlockNumber / 1 ); i++ )); do
curBlockHash=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockhash $i) && \
curBlockTime=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $curBlockHash | jq -r .time) && \
curDate=$(date -d @$curBlockTime '+%y%m%d-%H:%M:%S') && \
curBlockDiff=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $curBlockHash | jq -r .difficulty) && \
if [ $i != 0 ]; then
preBLockNumber=$(($i-1)) && \
preBlockHash=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockhash $preBLockNumber) && \
preBlockTime=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $preBlockHash | jq -r .time) && \
blockInterval=$(($curBlockTime - $preBlockTime)) && \
blockIntervalAVGtotal=$(bc <<< "$blockIntervalAVGtotal + $blockInterval") && \
blockIntervalAVG=$(bc <<< "scale=2; $blockIntervalAVGtotal / $i") && \
difficultyCurrent=$(echo $curBlockDiff | sed 's#\([+-]\{0,1\}[0-9]*\.\{0,1\}[0-9]\{1,\}\)[eE]+\{0,1\}\(-\{0,1\}\)\([0-9]\{1,\}\)#(\1*10^\2\3)#g' | bc -l) && \
difficultyRatio=$(bc <<< "scale=3; $difficultyCurrent / $difficultyInit") && \
printf "%-5s %16s %22s %6s %3s %6s \n" $i $curDate $curBlockDiff $difficultyRatio $blockInterval $blockIntervalAVG;
elif [ $i -eq 0 ]; then
preBLockNumber="GENESIS" && \
printf "%-5s %16s %22s %6s %3s %6s \n" $i $curDate $curBlockDiff $difficultyRatio $preBLockNumber $preBLockNumber;
fi;
done 2>&1 | tee ../dgw-T10-N200-$curBlockNumber.txt
BLOCK        TIMESTAMP             DIFFICULTY  RATIO  IV  AVERG
17211  190106-23:23:39  2.235916843219451e-06  1.172  24  24.00 
17212  190106-23:23:41  2.209544807404159e-06  1.158   2  13.00 
17213  190106-23:23:47  2.211122872228177e-06  1.159   6  10.66 
17214  190106-23:23:54  2.221339268570541e-06  1.164   7   9.75 
17215  190106-23:24:02  2.219411583310076e-06  1.163   8   9.40 
17216  190106-23:24:07  2.218677872368469e-06  1.163   5   8.66 
17217  190106-23:24:10  2.214310289859716e-06  1.160   3   7.85 
17218  190106-23:24:14  2.222119181205335e-06  1.165   4   7.37 
17219  190106-23:24:19  2.225115576961108e-06  1.166   5   7.11 
17220  190106-23:24:27  2.241716152284203e-06  1.175   8   7.20
#RT-Date
#!/bin/bash
difficultyInit=$(echo "1.907323166912278e-06" | sed 's#\([+-]\{0,1\}[0-9]*\.\{0,1\}[0-9]\{1,\}\)[eE]+\{0,1\}\(-\{0,1\}\)\([0-9]\{1,\}\)#(\1*10^\2\3)#g' | bc -l) && \
checkInteger='^[0-9]+$' && \
count=0 && \
blockIntervalAVG=0 && \
blockIntervalAVGtotal=-0 && \
printf "\n\n\n\n\n" && \
printf "%-5s %16s %22s %6s %3s %6s\n" BLOCK TIMESTAMP DIFFICULTY RATIO IV AVERG && \
sleep 1 && \
tail -f ~/.sugarchain/debug.log | while read line; do
curBlockNumber=$(echo $line | grep "height=" | cut -f 6 -d " " | cut -c8-) && \
if [[ $curBlockNumber =~ $checkInteger ]]; then
curBlockHash=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockhash $curBlockNumber) && \
curBlockTime=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $curBlockHash | jq -r .time) && \
curDate=$(date -d @$curBlockTime '+%y%m%d-%H:%M:%S') && \
curBlockDiff=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $curBlockHash | jq -r .difficulty) && \
preBlockHash=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $curBlockHash | jq -r .previousblockhash) && \
preBlockTime=$(./src/sugarchain-cli -rpcuser=username -rpcpassword=password getblockheader $preBlockHash | jq -r .time) && \
blockInterval=$(($curBlockTime - $preBlockTime)) && \
blockIntervalAVGtotal=$(bc <<< "$blockIntervalAVGtotal + $blockInterval") && \
count=$(($count + 1)) && \
blockIntervalAVG=$(bc <<< "scale=2; $blockIntervalAVGtotal / $count") && \
difficultyCurrent=$(echo $curBlockDiff | sed 's#\([+-]\{0,1\}[0-9]*\.\{0,1\}[0-9]\{1,\}\)[eE]+\{0,1\}\(-\{0,1\}\)\([0-9]\{1,\}\)#(\1*10^\2\3)#g' | bc -l) && \
difficultyRatio=$(bc <<< "scale=3; $difficultyCurrent / $difficultyInit") && \
printf "%-5s %16s %22s %6s %3s %6s \n" $curBlockNumber $curDate $curBlockDiff $difficultyRatio $blockInterval $blockIntervalAVG;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment