Skip to content

Commit 31ef8e8

Browse files
committed
cleanup tools
1 parent 1dd0da9 commit 31ef8e8

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

tools/convex_wallet.py

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
from convex_api import Account as ConvexAccount
1515
from convex_api import ConvexAPI
16+
from convex_api.utils import is_address
17+
1618

1719
DEFAULT_URL = 'https://convex.world'
1820

@@ -27,21 +29,6 @@
2729
logger = logging.getLogger('convex_wallet')
2830

2931

30-
def auto_topup_account(convex, account, min_balance=None):
31-
if isinstance(account, (list, tuple)):
32-
for account_item in account:
33-
auto_topup_account(convex, account_item, min_balance)
34-
return
35-
amount = 10000000
36-
retry_counter = 100
37-
if min_balance is None:
38-
min_balance = amount
39-
balance = convex.get_balance(account)
40-
while balance < min_balance and retry_counter > 0:
41-
convex.request_funds(amount, account)
42-
balance = convex.get_balance(account)
43-
retry_counter -= 1
44-
4532

4633
def load_account(args):
4734
account = None
@@ -60,7 +47,6 @@ def main():
6047
)
6148

6249
parser.add_argument(
63-
'-a',
6450
'--auto-topup',
6551
action='store_true',
6652
help='Auto topup account with sufficient funds. This only works for development networks. Default: False',
@@ -76,21 +62,31 @@ def main():
7662
parser.add_argument(
7763
'-k',
7864
'--keyfile',
65+
nargs='?',
7966
help='account private key encrypted with password saved in a file'
8067
)
8168

8269
parser.add_argument(
8370
'-p',
8471
'--password',
72+
nargs='?',
8573
help='password to access the private key enrcypted in a keyfile'
8674
)
8775

8876
parser.add_argument(
8977
'-w',
9078
'--keywords',
79+
nargs='?',
9180
help='account private key as words'
9281
)
9382

83+
parser.add_argument(
84+
'-n',
85+
'--name',
86+
nargs='?',
87+
help='account name to register'
88+
)
89+
9490
parser.add_argument(
9591
'-u',
9692
'--url',
@@ -109,21 +105,26 @@ def main():
109105
)
110106

111107
args = parser.parse_args()
108+
convex = ConvexAPI(args.url)
109+
if not convex:
110+
print(f'Cannot connect to the convex network at {args.url}')
111+
return
112112

113113
if args.debug:
114114
logging.basicConfig(level=logging.DEBUG)
115115
logging.getLogger('urllib3').setLevel(logging.INFO)
116116

117117
if args.command == 'create' or args.command == 'new':
118-
account = ConvexAccount.create_new()
119-
convex = ConvexAPI(args.url)
120-
if not convex:
121-
print(f'Cannot connect to the convex network at {args.url}')
122-
return
118+
import_account = load_account(args)
119+
account = convex.create_account(account=import_account)
123120

124121
if args.auto_topup:
125122
logger.debug('auto topup of account balance')
126-
auto_topup_account(convex, account)
123+
convex.topup_account(account)
124+
125+
if args.name:
126+
convex.topup_account(account)
127+
account = convex.register_account_name(args.name, account)
127128

128129
if args.password:
129130
password = args.password
@@ -132,30 +133,26 @@ def main():
132133

133134
values = {
134135
'password': password,
135-
'address': account.address_checksum,
136+
'address': account.address,
136137
'keyfile': account.export_to_text(password),
137138
'keywords': account.export_to_mnemonic,
138139
'balance': convex.get_balance(account)
139140
}
141+
if account.name:
142+
values['name'] = account.name
143+
140144
print(json.dumps(values, sort_keys=True, indent=4))
141145
elif args.command == 'info':
142146
address = None
143147
if len(args.command_args) > 0:
144-
address = args.command_args[0]
145-
146-
account = load_account(args)
147-
if account:
148-
address = account.address_checksum
149-
148+
if is_address(args.command_args[0]):
149+
address = args.command_args[0]
150+
else:
151+
name = args.command_args[0]
152+
address = convex.resolve_account_name(name)
150153
if not address:
151-
print('you must provide account keywords/keyfile or an account address')
154+
print('cannot find account address using name or address provided')
152155
return
153-
154-
convex = ConvexAPI(args.url)
155-
if not convex:
156-
print(f'Cannot connect to the convex network at {args.url}')
157-
return
158-
159156
values = convex.get_account_info(address)
160157
print(json.dumps(values, sort_keys=True, indent=4))
161158

0 commit comments

Comments
 (0)