5
5
6
6
"""
7
7
import logging
8
+ import math
8
9
import secrets
9
10
10
11
from convex_api import KeyPair
13
14
14
15
logger = logging .getLogger (__name__ )
15
16
17
+ DEFAULT_FUND_AMOUNT = 100000000
18
+
16
19
17
20
class PeerCreateCommand (CommandBase ):
18
21
@@ -29,7 +32,8 @@ def create_parser(self, sub_parser):
29
32
parser .add_argument (
30
33
'--topup' ,
31
34
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' ,
33
37
)
34
38
35
39
parser .add_argument (
@@ -53,7 +57,8 @@ def execute(self, args, output):
53
57
54
58
if args .topup :
55
59
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 )
57
62
58
63
if args .name :
59
64
logger .debug (f'registering account name { args .name } ' )
@@ -63,12 +68,20 @@ def execute(self, args, output):
63
68
password = args .password
64
69
else :
65
70
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
+
66
78
values = {
67
79
'password' : password ,
68
80
'address' : account .address ,
69
81
'keyfile' : key_pair .export_to_text (password ),
70
82
'keywords' : key_pair .export_to_mnemonic ,
71
- 'balance' : convex .get_balance (account )
83
+ 'balance' : convex .get_balance (account ),
84
+ 'stake' : stake_amount ,
72
85
}
73
86
if account .name :
74
87
values ['name' ] = account .name
0 commit comments