Jailcounter Script

Recording this script here for posterity, since there is currently no GitHub repository.

Do you want to see how long you were in jail for a given time period? Well you’re in luck, because @BenVan is a bash wizard.

Assuming you have Pocket already installed, install this script and run the following command ./jailcounter.sh <address> <starting block> <ending block>.

#!/bin/bash
# jailcounter.sh

function error_exit {
	if [ "$isNode" == "yes" ]
	then
		echo "$CurVAL is not a validator at block # $cBlock"
	fi
	isNode="no"
	CurNOD="                                 ";
}
function set_up {
	isNode="yes"
	CurNOD=$(pocket query node $CurVAL $cBlock | grep "jailed") || error_exit
	CurNOD=${CurNOD:14:5}
	if [ "$isNode" == "yes" ]
        then
	  if [ "${CurNOD:0:4}" == "true" ]
	  then
	     echo "starting pass for: $CurVAL at block $cBlock status = Jail Bird!!!"
	  else
             echo "starting pass for: $CurVAL at block $cBlock status = Free Man"
	  fi
        else
	  echo "starting pass for: $CurVAL at block $cBlock status = Not a Validator!!"
        fi
}
function readNode {
	while (( cBlock < eBlock));
  do
	isNode="yes"
        CurNOD=$(pocket query node $CurVAL $cBlock | grep "jailed") || error_exit
        CurNOD=${CurNOD:14:5}
#	echo "$CurNOD"
	if [ "$isNode" == "yes" ]
	then
        	if [ "${CurNOD:0:4}" == "true" ]
	        then
		  if [ "$isJail" == "no" ]
		  then
		    isJail="yes"
		    inCount=1
		    echo "into jail on block: $cBlock"
		    echo "was out for: $outCount Blocks"
		    echo "================================"
	          else
		    inCount=$((inCount+1));
                  fi
	        else
                  if [ "$isJail" == "yes" ]
                  then
                    isJail="no"
                    outCount=1
                    echo "free from jail on block: $cBlock"
                    echo "was in for: $inCount Blocks"
		    echo "================================"
                  else
                    outCount=$((outCount+1));
		    if [ $outCount -gt $gOutCount ] 
		    then
			    gOutCount=$outCount
		    fi
                  fi
	        fi
	fi
	cBlock=$((cBlock+1));
  done
  echo "finished processing at block # $cBlock"
  echo "Is validator = $isNode"
  echo "Is in jail = $isJail"
  echo "longest stretch of freedom = $gOutCount"
}
# CurVAL="d0d0090b30fcafd54c0f08dedbf099d9eb6828d9"
# sBlock="10700"
# eBlock="10770"
  CurVAL=$1
  sBlock=$2
  eBlock=$3
cBlock=$sBlock
isNode="no"
isJail="no"
outCount=0
gOutCount=0
inCount=0
gInCount=0
set_up
readNode