-
Notifications
You must be signed in to change notification settings - Fork 56
/
cli.py
executable file
·41 lines (37 loc) · 1.4 KB
/
cli.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
#!./venv/bin/python
from dotenv import load_dotenv
load_dotenv()
import argparse
import asyncio
import os
from models.constants import Constants
from db.tortoise_config import DBConfig
from db.models.account import Account
from rpc.client import RPCClient
parser = argparse.ArgumentParser(description="Utilities for Graham")
parser.add_argument('-r', '--representative-fix', action='store_true', help='Set representative for all bot accounts')
options, unknown = parser.parse_known_args()
async def rep_fix():
print("Starting rep set routine")
await DBConfig().init_db()
accounts = await Account.all()
for a in accounts:
# Get account info
acct_info = await RPCClient.instance().account_info(a.address)
if acct_info is not None and 'representative' in acct_info and acct_info['representative'] != Constants.REPRESENTATIVE:
print(f"Setting rep for {a.address}")
hash = await RPCClient.instance().account_representative_set(a.address, Constants.REPRESENTATIVE)
if hash is not None:
print(f"Set rep {hash}")
else:
print("Failed to set rep")
print("Done")
if __name__ == '__main__':
if options.representative_fix:
print("Running rep fix")
loop = asyncio.new_event_loop()
loop.run_until_complete(rep_fix())
loop.close()
else:
parser.print_help()
exit(0)