-
Notifications
You must be signed in to change notification settings - Fork 5
/
fork.py
34 lines (20 loc) · 1.14 KB
/
fork.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
import subprocess
import json
def export(fn, csv):
f = open(fn, "w")
f.write(csv)
f.close()
call = lambda c: subprocess.run(c, capture_output=True)
node = "--node=tcp://127.0.0.1:26657"
output = "--output=json"
query = ["osmosisd","query"]
depositors = lambda pid: [x["depositor"] for x in json.loads(call(query+["gov","deposits", pid, node, output]).stdout)["deposits"]]
addr_to_oper = lambda addr: call(["osmosisd","debug","bech32-convert","--prefix=osmovaloper", addr]).stderr.strip().decode("utf-8")
dep_vals = list(set([addr_to_oper(x) for x in depositors("103")]))
is_active = lambda x: x["jailed"]==False and x["status"]=="BOND_STATUS_BONDED"
all_vals = lambda: json.loads(call(query+["staking","validators", node, output, "--limit=200"]).stdout)["validators"]
active_vals = lambda: sorted([x for x in all_vals() if is_active(x)], key=lambda v: int(v["tokens"]), reverse=True)
did_deposit = lambda v: v["operator_address"] in dep_vals
data = lambda: [", ".join([x["description"]["moniker"], x["tokens"], x["tokens"] if did_deposit(x) else "0"]) for x in active_vals()]
if __name__ == "__main__":
export("fork_ready_v6.csv", "\n".join(data()))