@@ -26,9 +26,9 @@ async def transfer_extrinsic(
26
26
amount : Balance ,
27
27
era : int = 3 ,
28
28
transfer_all : bool = False ,
29
+ allow_death : bool = False ,
29
30
wait_for_inclusion : bool = True ,
30
31
wait_for_finalization : bool = False ,
31
- keep_alive : bool = True ,
32
32
prompt : bool = False ,
33
33
) -> bool :
34
34
"""Transfers funds from this wallet to the destination public key address.
@@ -39,11 +39,11 @@ async def transfer_extrinsic(
39
39
:param amount: Amount to stake as Bittensor balance.
40
40
:param era: Length (in blocks) for which the transaction should be valid.
41
41
:param transfer_all: Whether to transfer all funds from this wallet to the destination address.
42
+ :param allow_death: Whether to allow for falling below the existential deposit when performing this transfer.
42
43
:param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`,
43
44
or returns `False` if the extrinsic fails to enter the block within the timeout.
44
45
:param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning
45
46
`True`, or returns `False` if the extrinsic fails to be finalized within the timeout.
46
- :param keep_alive: If set, keeps the account alive by keeping the balance above the existential deposit.
47
47
:param prompt: If `True`, the call waits for confirmation from the user before proceeding.
48
48
:return: success: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
49
49
finalization / inclusion, the response is `True`, regardless of its inclusion.
@@ -57,8 +57,8 @@ async def get_transfer_fee() -> Balance:
57
57
"""
58
58
call = await subtensor .substrate .compose_call (
59
59
call_module = "Balances" ,
60
- call_function = "transfer_keep_alive" ,
61
- call_params = { "dest" : destination , "value" : amount . rao } ,
60
+ call_function = call_function ,
61
+ call_params = call_params ,
62
62
)
63
63
64
64
try :
@@ -82,8 +82,8 @@ async def do_transfer() -> tuple[bool, str, str]:
82
82
"""
83
83
call = await subtensor .substrate .compose_call (
84
84
call_module = "Balances" ,
85
- call_function = "transfer_keep_alive" ,
86
- call_params = { "dest" : destination , "value" : amount . rao } ,
85
+ call_function = call_function ,
86
+ call_params = call_params ,
87
87
)
88
88
extrinsic = await subtensor .substrate .create_signed_extrinsic (
89
89
call = call , keypair = wallet .coldkey , era = {"period" : era }
@@ -115,6 +115,20 @@ async def do_transfer() -> tuple[bool, str, str]:
115
115
if not unlock_key (wallet ).success :
116
116
return False
117
117
118
+ call_params = {"dest" : destination }
119
+ if transfer_all :
120
+ call_function = "transfer_all"
121
+ if allow_death :
122
+ call_params ["keep_alive" ] = False
123
+ else :
124
+ call_params ["keep_alive" ] = True
125
+ else :
126
+ call_params ["value" ] = amount .rao
127
+ if allow_death :
128
+ call_function = "transfer_allow_death"
129
+ else :
130
+ call_function = "transfer_keep_alive"
131
+
118
132
# Check balance.
119
133
with console .status (
120
134
f":satellite: Checking balance and fees on chain [white]{ subtensor .network } [/white]" ,
@@ -131,23 +145,26 @@ async def do_transfer() -> tuple[bool, str, str]:
131
145
)
132
146
fee = await get_transfer_fee ()
133
147
134
- if not keep_alive :
135
- # Check if the transfer should keep_alive the account
148
+ if allow_death :
149
+ # Check if the transfer should keep alive the account
136
150
existential_deposit = Balance (0 )
137
151
138
- # Check if we have enough balance.
139
- if transfer_all is True :
140
- amount = account_balance - fee - existential_deposit
141
- if amount < Balance (0 ):
142
- print_error ("Not enough balance to transfer" )
143
- return False
144
-
145
- if account_balance < (amount + fee + existential_deposit ):
152
+ if account_balance < (amount + fee + existential_deposit ) and not allow_death :
146
153
err_console .print (
147
154
":cross_mark: [bold red]Not enough balance[/bold red]:\n \n "
148
155
f" balance: [bright_cyan]{ account_balance } [/bright_cyan]\n "
149
156
f" amount: [bright_cyan]{ amount } [/bright_cyan]\n "
150
- f" for fee: [bright_cyan]{ fee } [/bright_cyan]"
157
+ f" for fee: [bright_cyan]{ fee } [/bright_cyan]\n "
158
+ f" would bring you under the existential deposit: [bright_cyan]{ existential_deposit } [/bright_cyan].\n "
159
+ f"You can try again with `--allow-death`."
160
+ )
161
+ return False
162
+ elif account_balance < (amount + fee ) and allow_death :
163
+ print_error (
164
+ ":cross_mark: [bold red]Not enough balance[/bold red]:\n \n "
165
+ f" balance: [bright_red]{ account_balance } [/bright_red]\n "
166
+ f" amount: [bright_red]{ amount } [/bright_red]\n "
167
+ f" for fee: [bright_red]{ fee } [/bright_red]"
151
168
)
152
169
return False
153
170
0 commit comments