55
66"""
77import logging
8+ import math
89import secrets
910
1011from convex_api import KeyPair
1314
1415logger = logging .getLogger (__name__ )
1516
17+ DEFAULT_FUND_AMOUNT = 100000000
18+
1619
1720class PeerCreateCommand (CommandBase ):
1821
@@ -29,7 +32,8 @@ def create_parser(self, sub_parser):
2932 parser .add_argument (
3033 '--topup' ,
3134 action = 'store_true' ,
32- help = 'Topup account with sufficient funds. This only works for development networks. Default: False' ,
35+ default = True ,
36+ help = 'Topup account with sufficient funds for a peer. This only works for development networks. Default: True' ,
3337 )
3438
3539 parser .add_argument (
@@ -53,7 +57,8 @@ def execute(self, args, output):
5357
5458 if args .topup :
5559 logger .debug ('auto topup of account balance' )
56- convex .topup_account (account )
60+ for counter in range (4 ):
61+ convex .request_funds (DEFAULT_FUND_AMOUNT , account )
5762
5863 if args .name :
5964 logger .debug (f'registering account name { args .name } ' )
@@ -63,12 +68,20 @@ def execute(self, args, output):
6368 password = args .password
6469 else :
6570 password = secrets .token_hex (32 )
71+
72+ balance = convex .get_balance (account )
73+ stake_amount = math .floor (balance * 0.98 )
74+
75+ create_peer_command = f'(create-peer { account .key_pair .public_key } { stake_amount } )'
76+ convex .send (create_peer_command , account )
77+
6678 values = {
6779 'password' : password ,
6880 'address' : account .address ,
6981 'keyfile' : key_pair .export_to_text (password ),
7082 'keywords' : key_pair .export_to_mnemonic ,
71- 'balance' : convex .get_balance (account )
83+ 'balance' : convex .get_balance (account ),
84+ 'stake' : stake_amount ,
7285 }
7386 if account .name :
7487 values ['name' ] = account .name
0 commit comments