Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
)

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions bittensor_cli/src/bittensor/async_substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
format_error_message,
get_explorer_url_for_network,
is_valid_bittensor_address_or_public_key,
print_error,
)


Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion bittensor_cli/src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down