15
15
from convex_api import ConvexAPI
16
16
17
17
DEFAULT_URL = 'https://convex.world'
18
+ COMMAND_HELP_TEXT = '''
19
+
20
+ create Create a new account using the provided --password. If no password auto generate one.
21
+ new Same as 'create' command.
22
+ info [address] Get information about an account, you can pass the account address, or the keywords or keyfile/password of the account.
23
+ '''
18
24
19
25
logger = logging .getLogger ('convex_wallet' )
20
26
@@ -35,9 +41,20 @@ def auto_topup_account(convex, account, min_balance=None):
35
41
retry_counter -= 1
36
42
37
43
44
+ def load_account (args ):
45
+ account = None
46
+ if args .keyfile and args .password :
47
+ account = ConvexAccount .import_from_file (args .keyfile , args .password )
48
+ elif args .keywords :
49
+ account = ConvexAccount .import_from_mnemonic (args .keywords )
50
+ return account
51
+
38
52
def main ():
39
53
40
- parser = argparse .ArgumentParser (description = 'Convex Wallet' )
54
+ parser = argparse .ArgumentParser (
55
+ description = 'Convex Wallet' ,
56
+ formatter_class = argparse .RawTextHelpFormatter
57
+ )
41
58
42
59
parser .add_argument (
43
60
'-a' ,
@@ -56,13 +73,13 @@ def main():
56
73
parser .add_argument (
57
74
'-k' ,
58
75
'--keyfile' ,
59
- help = 'account key file'
76
+ help = 'account private key encrypted with password saved in a file'
60
77
)
61
78
62
79
parser .add_argument (
63
80
'-p' ,
64
81
'--password' ,
65
- help = 'password to access the account '
82
+ help = 'password to access the private key enrcypted in a keyfile '
66
83
)
67
84
68
85
parser .add_argument (
@@ -80,7 +97,12 @@ def main():
80
97
81
98
parser .add_argument (
82
99
'command' ,
83
- help = 'Wallet command'
100
+ help = f'Wallet commands are as follows: \r \n { COMMAND_HELP_TEXT } '
101
+ )
102
+
103
+ parser .add_argument (
104
+ 'command_args' ,
105
+ nargs = '*' ,
84
106
)
85
107
86
108
args = parser .parse_args ()
@@ -100,7 +122,6 @@ def main():
100
122
logger .debug ('auto topup of account balance' )
101
123
auto_topup_account (convex , account )
102
124
103
- values = {}
104
125
if args .password :
105
126
password = args .password
106
127
else :
@@ -114,7 +135,26 @@ def main():
114
135
'balance' : convex .get_balance (account )
115
136
}
116
137
print (json .dumps (values , sort_keys = True , indent = 4 ))
138
+ elif args .command == 'info' :
139
+ address = None
140
+ if len (args .command_args ) > 0 :
141
+ address = args .command_args [0 ]
117
142
143
+ account = load_account (args )
144
+ if account :
145
+ address = account .address_checksum
146
+
147
+ if not address :
148
+ print ('you must provide account keywords/keyfile or an account address' )
149
+ return
150
+
151
+ convex = ConvexAPI (args .url )
152
+ if not convex :
153
+ print (f'Cannot connect to the convex network at { args .url } ' )
154
+ return
155
+
156
+ values = convex .get_account_info (address )
157
+ print (json .dumps (values , sort_keys = True , indent = 4 ))
118
158
119
159
if __name__ == "__main__" :
120
160
main ()
0 commit comments