diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index b012c989e..b3cc16ff7 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1404,9 +1404,12 @@ def wallet_transfer( None, "--amount", "-a", - prompt=True, + prompt=False, help="Amount (in TAO) to transfer.", ), + transfer_all: bool = typer.Option( + False, "--all", prompt=False, help="Transfer all available balance." + ), wallet_name: str = Options.wallet_name, wallet_path: str = Options.wallet_path, wallet_hotkey: str = Options.wallet_hotkey, @@ -1446,9 +1449,21 @@ def wallet_transfer( validate=WV.WALLET, ) subtensor = self.initialize_chain(network) + if transfer_all and amount: + print_error("Cannot specify an amount and '--all' flag.") + raise typer.Exit() + elif transfer_all: + amount = 0 + elif not amount: + amount = FloatPrompt.ask("Enter amount (in TAO) to transfer.") return self._run_command( wallets.transfer( - wallet, subtensor, destination_ss58_address, amount, prompt + wallet, + subtensor, + destination_ss58_address, + amount, + transfer_all, + prompt, ) ) @@ -3269,7 +3284,7 @@ def stake_add( self.verbosity_handler(quiet, verbose) if stake_all and amount: - err_console.print( + print_error( "Cannot specify an amount and 'stake-all'. Choose one or the other." ) raise typer.Exit() diff --git a/bittensor_cli/src/bittensor/async_substrate_interface.py b/bittensor_cli/src/bittensor/async_substrate_interface.py index 0f4dd0d43..eb289bfd4 100644 --- a/bittensor_cli/src/bittensor/async_substrate_interface.py +++ b/bittensor_cli/src/bittensor/async_substrate_interface.py @@ -1707,9 +1707,7 @@ async def rpc_request( ) result = await self._make_rpc_request(payloads, runtime=runtime) if "error" in result[payload_id][0]: - raise SubstrateRequestException( - result[payload_id][0]["error"]["message"] - ) + raise SubstrateRequestException(result[payload_id][0]["error"]["message"]) if "result" in result[payload_id][0]: return result[payload_id][0] else: diff --git a/bittensor_cli/src/bittensor/extrinsics/transfer.py b/bittensor_cli/src/bittensor/extrinsics/transfer.py index 8ae37e9b6..588c8684e 100644 --- a/bittensor_cli/src/bittensor/extrinsics/transfer.py +++ b/bittensor_cli/src/bittensor/extrinsics/transfer.py @@ -15,6 +15,7 @@ format_error_message, get_explorer_url_for_network, is_valid_bittensor_address_or_public_key, + print_error, ) @@ -23,6 +24,7 @@ async def transfer_extrinsic( wallet: Wallet, destination: str, amount: Balance, + transfer_all: bool = False, wait_for_inclusion: bool = True, wait_for_finalization: bool = False, keep_alive: bool = True, @@ -34,6 +36,7 @@ async def transfer_extrinsic( :param wallet: Bittensor wallet object to make transfer from. :param destination: Destination public key address (ss58_address or ed25519) of recipient. :param amount: Amount to stake as Bittensor balance. + :param transfer_all: Whether to transfer all funds from this wallet to the destination address. :param wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`, or returns `False` if the extrinsic fails to enter the block within the timeout. :param wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning @@ -135,6 +138,12 @@ async def do_transfer() -> tuple[bool, str, str]: existential_deposit = Balance(0) # Check if we have enough balance. + if transfer_all is True: + amount = account_balance - fee - existential_deposit + if amount < Balance(0): + print_error("Not enough balance to transfer") + return False + if account_balance < (amount + fee + existential_deposit): err_console.print( ":cross_mark: [bold red]Not enough balance[/bold red]:\n\n" diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index a1dd22623..162c2184e 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -1256,11 +1256,17 @@ async def transfer( subtensor: SubtensorInterface, destination: str, amount: float, + transfer_all: bool, prompt: bool, ): """Transfer token of amount to destination.""" await transfer_extrinsic( - subtensor, wallet, destination, Balance.from_tao(amount), prompt=prompt + subtensor, + wallet, + destination, + Balance.from_tao(amount), + transfer_all, + prompt=prompt, )