Skip to content

Commit

Permalink
add create-peer command
Browse files Browse the repository at this point in the history
  • Loading branch information
billbsing committed Jul 23, 2021
1 parent 26d562f commit 75020d1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions convex_api/tool/command/peer_create_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import logging
import math
import secrets

from convex_api import KeyPair
Expand All @@ -13,6 +14,8 @@

logger = logging.getLogger(__name__)

DEFAULT_FUND_AMOUNT = 100000000


class PeerCreateCommand(CommandBase):

Expand All @@ -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(
Expand All @@ -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}')
Expand All @@ -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
Expand Down

0 comments on commit 75020d1

Please sign in to comment.