-
Notifications
You must be signed in to change notification settings - Fork 0
/
votes_inspector.py
110 lines (92 loc) · 3.91 KB
/
votes_inspector.py
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
import requests
import json
import sys
def print_error(r):
print("Error on req ",r.status_code)
sys.exit(-1)
def get_req(url):
r = requests.get(url=url)
if r.status_code == 200:
data = r.json()
if len(data['aggregate_votes']) > 0:
return data
return get_req(url)
print_error(r)
def write_data(data):
with open('data.json', 'w') as f:
json.dump(data, f)
def get_moniker(validators,valaddr):
for i in range(0,len(validators)):
if validators[i]['operator_address'] == valaddr:
return validators[i]['description']['moniker']
def get_validators(APIURL):
r = requests.get(url=f"https://{APIURL}/cosmos/staking/v1beta1/validators?status=BOND_STATUS_BONDED")
if r.status_code == 200:
data = r.json()
return data['validators']
print_error(r)
def get_accepted_denoms():
r = requests.get(url=f"https://{APIURL}/umee/oracle/v1/params")
if r.status_code == 200:
data = r.json()
return data['params']['accept_list']
print_error(r)
def votes_inspector(APIURL):
votes = f"https://{APIURL}/umee/oracle/v1/validators/aggregate_votes"
denoms_resp=get_accepted_denoms()
acceped_denoms = list()
for i in range(0,len(denoms_resp)):
acceped_denoms.append(denoms_resp[i]['symbol_denom'].upper())
acceped_denoms = list(set(acceped_denoms))
validators = get_validators(APIURL=APIURL)
valaddrs = list()
for i in range(0,len(validators)):
valaddrs.append(validators[i]['operator_address'])
print("Accepted Denoms ",len(acceped_denoms),acceped_denoms)
print("Total Bonded validators ",len(valaddrs))
# Get the total denoms exists in app
votes_resp = get_req(votes)
aggregate_votes = votes_resp['aggregate_votes']
votes_info = list()
voted_validators = list()
print("Total Validators ",len(aggregate_votes))
for i in range(0, len(aggregate_votes)):
a=dict()
a['voter'] = aggregate_votes[i]['voter']
voted_validators.append( a['voter'])
d = aggregate_votes[i]['exchange_rate_tuples']
exchange_rate_tuples = []
for k in range(0,len(d)):
exchange_rate_tuples.append(d[k]['denom'])
if len(exchange_rate_tuples) != len(acceped_denoms):
print("❌" ,a['voter'], ">>", get_moniker(validators,a['voter'])," is missing the votes for denoms")
for j in range(0,len(acceped_denoms)):
if exchange_rate_tuples.count(acceped_denoms[j])==0 :
print("missing votes for denom : ",acceped_denoms[j])
a['missing_votes'] =acceped_denoms[j]
else:
print("✅" ,a['voter'], ">>", get_moniker(validators,a['voter']), "is submit the correct votes ",len(exchange_rate_tuples))
print("*"*100)
print("*"*100)
print("Below validators does not submit the votes at all")
for i in range(0,len(valaddrs)):
if voted_validators.count(valaddrs[i]) == 0 :
print("❌" ,valaddrs[i], ">>", get_moniker(validators,valaddrs[i])," is does not submit the votes for denoms")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--network", type=str,default="mainnet", help="Enter network name : canon or mainnet , by default mainnet")
args = parser.parse_args()
if args.network == "canon":
APIURL = "canon-4.api.network.umee.cc"
else:
APIURL = "api-umee-ia.cosmosia.notional.ventures"
print(f">>>>> network :: {args.network}")
print(f">>>>> API :: {APIURL}")
votes_inspector(APIURL=APIURL)
print("*"*100)
print("Below validators does not submit the votes at all")
for i in range(0,len(valaddrs)):
if voted_validators.count(valaddrs[i]) == 0 :
print("❌" ,valaddrs[i], ">>", get_moniker(validators,valaddrs[i])," is does not submit the votes for denoms")