diff --git a/convex_api/tool/command/peer_create_command.py b/convex_api/tool/command/peer_create_command.py index 3e43d3f..f780726 100644 --- a/convex_api/tool/command/peer_create_command.py +++ b/convex_api/tool/command/peer_create_command.py @@ -5,6 +5,7 @@ """ import logging +import math import secrets from convex_api import KeyPair @@ -13,6 +14,8 @@ logger = logging.getLogger(__name__) +DEFAULT_FUND_AMOUNT = 100000000 + class PeerCreateCommand(CommandBase): @@ -29,7 +32,8 @@ def create_parser(self, sub_parser): parser.add_argument( '--topup', action='store_true', - help='Topup account with sufficient funds. This only works for development networks. Default: False', + default=True, + help='Topup account with sufficient funds for a peer. This only works for development networks. Default: True', ) parser.add_argument( @@ -53,7 +57,8 @@ def execute(self, args, output): if args.topup: logger.debug('auto topup of account balance') - convex.topup_account(account) + for counter in range(4): + convex.request_funds(DEFAULT_FUND_AMOUNT, account) if args.name: logger.debug(f'registering account name {args.name}') @@ -63,12 +68,20 @@ def execute(self, args, output): password = args.password else: password = secrets.token_hex(32) + + balance = convex.get_balance(account) + stake_amount = math.floor(balance * 0.98) + + create_peer_command = f'(create-peer {account.key_pair.public_key} {stake_amount} )' + convex.send(create_peer_command, account) + values = { 'password': password, 'address': account.address, 'keyfile': key_pair.export_to_text(password), 'keywords': key_pair.export_to_mnemonic, - 'balance': convex.get_balance(account) + 'balance': convex.get_balance(account), + 'stake': stake_amount, } if account.name: values['name'] = account.name