1515from convex_api import ConvexAPI
1616
1717DEFAULT_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+ '''
1824
1925logger = logging .getLogger ('convex_wallet' )
2026
@@ -35,9 +41,20 @@ def auto_topup_account(convex, account, min_balance=None):
3541 retry_counter -= 1
3642
3743
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+
3852def main ():
3953
40- parser = argparse .ArgumentParser (description = 'Convex Wallet' )
54+ parser = argparse .ArgumentParser (
55+ description = 'Convex Wallet' ,
56+ formatter_class = argparse .RawTextHelpFormatter
57+ )
4158
4259 parser .add_argument (
4360 '-a' ,
@@ -56,13 +73,13 @@ def main():
5673 parser .add_argument (
5774 '-k' ,
5875 '--keyfile' ,
59- help = 'account key file'
76+ help = 'account private key encrypted with password saved in a file'
6077 )
6178
6279 parser .add_argument (
6380 '-p' ,
6481 '--password' ,
65- help = 'password to access the account '
82+ help = 'password to access the private key enrcypted in a keyfile '
6683 )
6784
6885 parser .add_argument (
@@ -80,7 +97,12 @@ def main():
8097
8198 parser .add_argument (
8299 '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 = '*' ,
84106 )
85107
86108 args = parser .parse_args ()
@@ -100,7 +122,6 @@ def main():
100122 logger .debug ('auto topup of account balance' )
101123 auto_topup_account (convex , account )
102124
103- values = {}
104125 if args .password :
105126 password = args .password
106127 else :
@@ -114,7 +135,26 @@ def main():
114135 'balance' : convex .get_balance (account )
115136 }
116137 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 ]
117142
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 ))
118158
119159if __name__ == "__main__" :
120160 main ()
0 commit comments