@@ -26,9 +26,9 @@ async def transfer_extrinsic(
2626 amount : Balance ,
2727 era : int = 3 ,
2828 transfer_all : bool = False ,
29+ allow_death : bool = False ,
2930 wait_for_inclusion : bool = True ,
3031 wait_for_finalization : bool = False ,
31- keep_alive : bool = True ,
3232 prompt : bool = False ,
3333) -> bool :
3434 """Transfers funds from this wallet to the destination public key address.
@@ -39,11 +39,11 @@ async def transfer_extrinsic(
3939 :param amount: Amount to stake as Bittensor balance.
4040 :param era: Length (in blocks) for which the transaction should be valid.
4141 :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.
4243 :param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`,
4344 or returns `False` if the extrinsic fails to enter the block within the timeout.
4445 :param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning
4546 `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.
4747 :param prompt: If `True`, the call waits for confirmation from the user before proceeding.
4848 :return: success: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
4949 finalization / inclusion, the response is `True`, regardless of its inclusion.
@@ -57,8 +57,8 @@ async def get_transfer_fee() -> Balance:
5757 """
5858 call = await subtensor .substrate .compose_call (
5959 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 ,
6262 )
6363
6464 try :
@@ -82,8 +82,8 @@ async def do_transfer() -> tuple[bool, str, str]:
8282 """
8383 call = await subtensor .substrate .compose_call (
8484 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 ,
8787 )
8888 extrinsic = await subtensor .substrate .create_signed_extrinsic (
8989 call = call , keypair = wallet .coldkey , era = {"period" : era }
@@ -115,6 +115,20 @@ async def do_transfer() -> tuple[bool, str, str]:
115115 if not unlock_key (wallet ).success :
116116 return False
117117
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+
118132 # Check balance.
119133 with console .status (
120134 f":satellite: Checking balance and fees on chain [white]{ subtensor .network } [/white]" ,
@@ -131,23 +145,26 @@ async def do_transfer() -> tuple[bool, str, str]:
131145 )
132146 fee = await get_transfer_fee ()
133147
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
136150 existential_deposit = Balance (0 )
137151
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 :
146153 err_console .print (
147154 ":cross_mark: [bold red]Not enough balance[/bold red]:\n \n "
148155 f" balance: [bright_cyan]{ account_balance } [/bright_cyan]\n "
149156 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]"
151168 )
152169 return False
153170
0 commit comments