forked from dsiganos/nano-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelegators.py
executable file
·35 lines (27 loc) · 873 Bytes
/
delegators.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
#!/usr/bin/env python3
import requests
import json
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--count', action='store_true', default=False,
help='Count delegators only')
parser.add_argument("account")
return parser.parse_args()
def post(session, params, timeout=60):
resp = session.post('http://[::1]:7076', json=params, timeout=timeout)
return resp.json()
args = parse_args()
action = 'delegators'
if args.count:
action = 'delegators_count'
params = {
"action": action,
"account": args.account
}
session = requests.Session()
result = post(session, params)
print(json.dumps(result, indent=4))
for delegator, weight in result['delegators'].items():
weight_in_nano = int(weight) / (10**30)
print('%s %s' % (delegator, '{:,}'.format(weight_in_nano)))