-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcheckfork
More file actions
executable file
·143 lines (122 loc) · 4.35 KB
/
checkfork
File metadata and controls
executable file
·143 lines (122 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#
# @author webworker01
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
#how far ahead or behind before being marked as a fork
variance=10
forked=false
remotecheck=$(curl -Ssf https://komodostats.com/api/notary/summary.json)
remotecheck2=$(curl -Ssf https://dexstats.info/api/explorerstatus.php)
format="%-10s %8s %8s %15s %15s %15s\n"
redformat="\033[0;31m$format\033[0m"
printf "$format" "-ASSET-" "-BLOCKS-" "-LONG-" "-komodostats-" "-dexstats-" #"-notarystats-"
parseKomodostats()
{
local coin=$1
local remotedata=$2
remoteblocks=$(jq --arg coinname $coin '.[] | select(.ac_name==$coinname) | .blocks' <<< $remotedata)
}
parseDexstats()
{
local coin=$1
local remotedata=$2
remoteblocks2=$(jq --arg coinname $coin '.status[] | select(.chain==$coinname) | .height | tonumber' <<< $remotedata)
remotehash2=$(jq -r --arg coinname $coin '.status[] | select(.chain==$coinname) | .hash' <<< $remotedata)
}
outputRow()
{
local coinname=$1
local localblocks=$2
local locallongest=$3
local localhash=$4
if (( localblocks > 0 )); then
thisformat=$format
if (( remoteblocks > 0 )); then
diff1=$((localblocks-remoteblocks))
else
diff1=0
fi
if (( remoteblocks2 > 0 )); then
diff2=$((localblocks-remoteblocks2))
else
diff2=0
fi
if ((localblocks < locallongest)); then
forked=true
thisformat=$redformat
fi
if (( diff1 < variance * -1 )) || (( diff1 > variance )); then
forked=true
thisformat=$redformat
fi
if (( diff2 < variance * -1 )) || (( diff2 > variance )); then
forked=true
thisformat=$redformat
fi
hasherror2=""
if [[ ! -z $remotehash2 ]] && [[ -z $hashatheight2 ]]; then
forked=true
hasherror2="!! "
echo "Dexstats Remote Chain Longer! Hash Mismatch 1 Local: $blocks Remote: $remoteblocks2"
elif [[ -z $remotehash2 ]] && [[ "$hashatheight2" != "$remotehash2" ]]; then
forked=true
hasherror2="!! "
echo "Dexstats Hash Mismatch Local: $hashatheight2 Remote: $remotehash2"
fi
printf "$thisformat" "$coinname" "$localblocks" "$locallongest" "${remoteblocks}[$diff1]" "${hasherror2}$remoteblocks2[$diff2]"
else
printf "$format" "$coinname" "$localblocks" "$locallongest" "$remoteblocks" "$remoteblocks2"
fi
}
#KMD
blocks=$($komodocli getinfo | jq .blocks)
longest=$($komodocli getinfo | jq .longestchain)
blockhash=$($komodocli getbestblockhash)
parseKomodostats "KMD" "$remotecheck"
parseDexstats "KMD" "$remotecheck2"
if (( blocks >= remoteblocks2 )); then
hashatheight2=$($komodocli getblockhash $remoteblocks2)
else
hashatheight2=
fi
outputRow "KMD" $blocks $longest $blockhash
if (( thirdpartycoins > 0 )); then
for coins in "${coinsthird[@]}"; do
coin=($coins)
eval $(echo coincli=${coin[1]})
blockchaininfo=$(${coincli} getblockchaininfo)
blocks=$(jq .blocks <<< $blockchaininfo)
longest=$(jq .headers <<< $blockchaininfo)
blockhash=$($coincli getbestblockhash)
parseKomodostats "${coin[0]}" "$remotecheck"
remoteblocks2=""
remotehash2=
hashatheight2=
outputRow "${coin[0]}" $blocks $longest $blockhash
done
else
#Loop through coinlist coins
for coins in "${coinlist[@]}"; do
coin=($coins)
if [[ ! ${ignoreacs[*]} =~ ${coin[0]} ]]; then
blocks=$($komodocli -ac_name=${coin[0]} getinfo | jq .blocks)
longest=$($komodocli -ac_name=${coin[0]} getinfo | jq .longestchain)
blockhash=$($komodocli -ac_name=${coin[0]} getbestblockhash)
parseKomodostats "${coin[0]}" "$remotecheck"
parseDexstats "${coin[0]}" "$remotecheck2"
if [[ ! -z $remoteblocks2 ]] && (( blocks >= remoteblocks2 )); then
hashatheight2=$($komodocli -ac_name=${coin[0]} getblockhash $remoteblocks2)
else
hashatheight2=
fi
outputRow "${coin[0]}" $blocks $longest $blockhash
fi
done
fi
if [ "$forked" == false ]; then
printf "\033[0;32mAll coins are fine\033[0m\n"
else
printf "\033[0;31mPossible fork!\033[0m\n"
fi