13
13
14
14
from convex_api import Account as ConvexAccount
15
15
from convex_api import ConvexAPI
16
+ from convex_api .utils import is_address
17
+
16
18
17
19
DEFAULT_URL = 'https://convex.world'
18
20
27
29
logger = logging .getLogger ('convex_wallet' )
28
30
29
31
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
-
45
32
46
33
def load_account (args ):
47
34
account = None
@@ -60,7 +47,6 @@ def main():
60
47
)
61
48
62
49
parser .add_argument (
63
- '-a' ,
64
50
'--auto-topup' ,
65
51
action = 'store_true' ,
66
52
help = 'Auto topup account with sufficient funds. This only works for development networks. Default: False' ,
@@ -76,21 +62,31 @@ def main():
76
62
parser .add_argument (
77
63
'-k' ,
78
64
'--keyfile' ,
65
+ nargs = '?' ,
79
66
help = 'account private key encrypted with password saved in a file'
80
67
)
81
68
82
69
parser .add_argument (
83
70
'-p' ,
84
71
'--password' ,
72
+ nargs = '?' ,
85
73
help = 'password to access the private key enrcypted in a keyfile'
86
74
)
87
75
88
76
parser .add_argument (
89
77
'-w' ,
90
78
'--keywords' ,
79
+ nargs = '?' ,
91
80
help = 'account private key as words'
92
81
)
93
82
83
+ parser .add_argument (
84
+ '-n' ,
85
+ '--name' ,
86
+ nargs = '?' ,
87
+ help = 'account name to register'
88
+ )
89
+
94
90
parser .add_argument (
95
91
'-u' ,
96
92
'--url' ,
@@ -109,21 +105,26 @@ def main():
109
105
)
110
106
111
107
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
112
112
113
113
if args .debug :
114
114
logging .basicConfig (level = logging .DEBUG )
115
115
logging .getLogger ('urllib3' ).setLevel (logging .INFO )
116
116
117
117
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 )
123
120
124
121
if args .auto_topup :
125
122
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 )
127
128
128
129
if args .password :
129
130
password = args .password
@@ -132,30 +133,26 @@ def main():
132
133
133
134
values = {
134
135
'password' : password ,
135
- 'address' : account .address_checksum ,
136
+ 'address' : account .address ,
136
137
'keyfile' : account .export_to_text (password ),
137
138
'keywords' : account .export_to_mnemonic ,
138
139
'balance' : convex .get_balance (account )
139
140
}
141
+ if account .name :
142
+ values ['name' ] = account .name
143
+
140
144
print (json .dumps (values , sort_keys = True , indent = 4 ))
141
145
elif args .command == 'info' :
142
146
address = None
143
147
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 )
150
153
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 ' )
152
155
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
-
159
156
values = convex .get_account_info (address )
160
157
print (json .dumps (values , sort_keys = True , indent = 4 ))
161
158
0 commit comments