@@ -18,7 +18,8 @@ def _do_transfer(
18
18
subtensor : "Subtensor" ,
19
19
wallet : "Wallet" ,
20
20
destination : str ,
21
- amount : Balance ,
21
+ amount : Optional [Balance ],
22
+ keep_alive : bool = True ,
22
23
wait_for_inclusion : bool = True ,
23
24
wait_for_finalization : bool = False ,
24
25
period : Optional [int ] = None ,
@@ -30,7 +31,8 @@ def _do_transfer(
30
31
subtensor (bittensor.core.subtensor.Subtensor): the Subtensor object used for transfer
31
32
wallet (bittensor_wallet.Wallet): Bittensor wallet object to make transfer from.
32
33
destination (str): Destination public key address (ss58_address or ed25519) of recipient.
33
- amount (bittensor.utils.balance.Balance): Amount to stake as Bittensor balance.
34
+ amount (bittensor.utils.balance.Balance): Amount to stake as Bittensor balance. `None` if transferring all.
35
+ keep_alive (bool): If `True`, will keep the existential deposit in the account.
34
36
wait_for_inclusion (bool): If set, waits for the extrinsic to enter a block before returning `True`, or returns
35
37
`False` if the extrinsic fails to enter the block within the timeout.
36
38
wait_for_finalization (bool): If set, waits for the extrinsic to be finalized on the chain before returning
@@ -42,10 +44,24 @@ def _do_transfer(
42
44
Returns:
43
45
success, block hash, formatted error message
44
46
"""
47
+ call_params = {"dest" : destination }
48
+ if amount is None :
49
+ call_function = "transfer_all"
50
+ if keep_alive :
51
+ call_params ["keep_alive" ] = True
52
+ else :
53
+ call_params ["keep_alive" ] = False
54
+ else :
55
+ call_params ["amount" ] = amount .rao
56
+ if keep_alive :
57
+ call_function = "transfer_keep_alive"
58
+ else :
59
+ call_function = "transfer_allow_death"
60
+
45
61
call = subtensor .substrate .compose_call (
46
62
call_module = "Balances" ,
47
- call_function = "transfer_keep_alive" ,
48
- call_params = { "dest" : destination , "value" : amount . rao } ,
63
+ call_function = call_function ,
64
+ call_params = call_params ,
49
65
)
50
66
51
67
success , message = subtensor .sign_and_send_extrinsic (
@@ -72,7 +88,7 @@ def transfer_extrinsic(
72
88
subtensor : "Subtensor" ,
73
89
wallet : "Wallet" ,
74
90
dest : str ,
75
- amount : Balance ,
91
+ amount : Optional [ Balance ] ,
76
92
transfer_all : bool = False ,
77
93
wait_for_inclusion : bool = True ,
78
94
wait_for_finalization : bool = False ,
@@ -85,7 +101,7 @@ def transfer_extrinsic(
85
101
subtensor (bittensor.core.subtensor.Subtensor): the Subtensor object used for transfer
86
102
wallet (bittensor_wallet.Wallet): Bittensor wallet object to make transfer from.
87
103
dest (str): Destination public key address (ss58_address or ed25519) of recipient.
88
- amount (bittensor.utils.balance.Balance): Amount to stake as Bittensor balance.
104
+ amount (bittensor.utils.balance.Balance): Amount to stake as Bittensor balance. `None` if transferring all.
89
105
transfer_all (bool): Whether to transfer all funds from this wallet to the destination address.
90
106
wait_for_inclusion (bool): If set, waits for the extrinsic to enter a block before returning `True`, or returns
91
107
`False` if the extrinsic fails to enter the block within the timeout.
@@ -100,6 +116,10 @@ def transfer_extrinsic(
100
116
success (bool): Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
101
117
finalization / inclusion, the response is `True`, regardless of its inclusion.
102
118
"""
119
+ if amount is None and not transfer_all :
120
+ logging .error ("If not transferring all, `amount` must be specified." )
121
+ return False
122
+
103
123
# Validate destination address.
104
124
if not is_valid_bittensor_address_or_public_key (dest ):
105
125
logging .error (
@@ -131,12 +151,10 @@ def transfer_extrinsic(
131
151
132
152
# Check if we have enough balance.
133
153
if transfer_all is True :
134
- amount = account_balance - fee - existential_deposit
135
- if amount < Balance (0 ):
154
+ if (account_balance - fee ) < existential_deposit :
136
155
logging .error ("Not enough balance to transfer" )
137
156
return False
138
-
139
- if account_balance < (amount + fee + existential_deposit ):
157
+ elif account_balance < (amount + fee + existential_deposit ):
140
158
logging .error (":cross_mark: [red]Not enough balance[/red]" )
141
159
logging .error (f"\t \t Balance:\t [blue]{ account_balance } [/blue]" )
142
160
logging .error (f"\t \t Amount:\t [blue]{ amount } [/blue]" )
0 commit comments