forked from KMDLabs/LabsNotary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkmasks
executable file
·47 lines (38 loc) · 2.59 KB
/
checkmasks
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
#!/bin/bash
#Running with no parameter will give a summary
#./checkmasks all - will output detail for each node
#./checkmasks <maskhex> - will output detail for a specific mask
#which notaryid to use as "seednode" reference starting at 0 to the number of STAKED NOTARIES.
seednode=0
if [[ ! -z $1 ]]
then
if [[ "$1" == "all" ]]
then
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\"}" | jq -c -r .[]
else
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$1\"}" | jq -c -r .
fi
else
stakedchain=$(cat assetchains.json | jq -r .[0].ac_name)
mynotaryid=$(komodo-cli -ac_name=$stakedchain getinfo | jq .notaryid)
bestmaskdata=$(curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\"}")
seedrecvmask=$(echo $bestmaskdata | jq --arg seedid $seednode '.[$seedid|tonumber] | .recvmask' | sed 's/"//g' | awk '{$1=$1};1')
echo "Seed recvmask: $seedrecvmask"
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$seedrecvmask\"}" | jq -c -r '. | del(.maskhex) | del(.tag) | .set'
echo "not:"
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$seedrecvmask\"}" | jq -c -r '. | del(.maskhex) | del(.tag) | .not'
myrecvmask=$(echo $bestmaskdata | jq --arg nodeid $mynotaryid '.[$nodeid|tonumber].recvmask' | sed 's/"//g' | awk '{$1=$1};1')
echo
echo "My recvmask: $myrecvmask"
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$myrecvmask\"}" | jq -c -r '.set'
bestmask=$(echo $bestmaskdata | jq -c 'group_by(.bestmask) | del(.[] | select(.[0].bestmask == " 0" )) | del(.[] | select(.[0].bestmask == " 0" )) | map ({ "total":length, "bestmask":.[0].bestmask }) | sort_by(.total) | reverse')
bestmaskmask=$(echo $bestmask | jq .[0].bestmask | sed 's/"//g' | awk '{$1=$1};1')
bestmaskcount=$(echo $bestmask | jq .[0].total | sed 's/"//g')
echo
echo "Best bestmask: $bestmaskmask [$bestmaskcount agree]"
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$bestmaskmask\"}" | jq -c -r '.set'
mybestmask=$(echo $bestmaskdata | jq --arg nodeid $mynotaryid '.[$nodeid|tonumber].bestmask' | sed 's/"//g' | awk '{$1=$1};1')
echo
echo "My bestmask: $mybestmask"
curl -s --url "http://127.0.0.1:7776" --data "{\"agent\":\"dpow\",\"method\":\"active\",\"maskhex\":\"$mybestmask\"}" | jq -c -r '.set'
fi