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
19 changes: 9 additions & 10 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
confirm_action,
console,
print_error,
print_success,
format_error_message,
millify,
get_human_readable,
Expand Down Expand Up @@ -587,8 +588,8 @@ async def get_neuron_for_pubkey_and_subnet():
subtensor, netuid=netuid, hotkey_ss58=get_hotkey_pub_ss58(wallet)
)
if is_registered:
print_error(
f":white_heavy_check_mark: [dark_sea_green3]Already registered on netuid:{netuid}[/dark_sea_green3]"
print_success(
f"[dark_sea_green3]Already registered on netuid:{netuid}[/dark_sea_green3]"
)
return True

Expand Down Expand Up @@ -630,8 +631,8 @@ async def get_neuron_for_pubkey_and_subnet():
# https://github.com/opentensor/subtensor/blob/development/pallets/subtensor/src/errors.rs

if "HotKeyAlreadyRegisteredInSubNet" in err_msg:
console.print(
f":white_heavy_check_mark: [dark_sea_green3]Already Registered on "
print_success(
f"[dark_sea_green3]Already Registered on "
f"[bold]subnet:{netuid}[/bold][/dark_sea_green3]"
)
return True
Expand All @@ -647,8 +648,8 @@ async def get_neuron_for_pubkey_and_subnet():
hotkey_ss58=get_hotkey_pub_ss58(wallet),
)
if is_registered:
console.print(
":white_heavy_check_mark: [dark_sea_green3]Registered[/dark_sea_green3]"
print_success(
"[dark_sea_green3]Registered[/dark_sea_green3]"
)
return True
else:
Expand Down Expand Up @@ -738,8 +739,8 @@ async def burned_register_extrinsic(
era_ = {"period": era}

if not neuron.is_null:
print_success("[dark_sea_green3]Already Registered[/dark_sea_green3]:")
console.print(
":white_heavy_check_mark: [dark_sea_green3]Already Registered[/dark_sea_green3]:\n"
f"uid: [{COLOR_PALETTE.G.NETUID_EXTRA}]{neuron.uid}[/{COLOR_PALETTE.G.NETUID_EXTRA}]\n"
f"netuid: [{COLOR_PALETTE.G.NETUID}]{neuron.netuid}[/{COLOR_PALETTE.G.NETUID}]\n"
f"hotkey: [{COLOR_PALETTE.G.HK}]{neuron.hotkey}[/{COLOR_PALETTE.G.HK}]\n"
Expand Down Expand Up @@ -798,9 +799,7 @@ async def burned_register_extrinsic(
)

if len(netuids_for_hotkey) > 0:
console.print(
f":white_heavy_check_mark: [green]Registered on netuid {netuid} with UID {my_uid}[/green]"
)
print_success(f"Registered on netuid {netuid} with UID {my_uid}")
return True, f"Registered on {netuid} with UID {my_uid}", ext_id
else:
# neuron not found, try again
Expand Down
11 changes: 4 additions & 7 deletions bittensor_cli/src/bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
confirm_action,
console,
print_error,
print_success,
u16_normalized_float,
print_verbose,
format_error_message,
Expand Down Expand Up @@ -343,9 +344,7 @@ async def root_register_extrinsic(
subtensor, netuid=0, hotkey_ss58=get_hotkey_pub_ss58(wallet)
)
if is_registered:
console.print(
":white_heavy_check_mark: [green]Already registered on root network.[/green]"
)
print_success("Already registered on root network.")
return True, "Already registered on root network", None

with console.status(":satellite: Registering to root network...", spinner="earth"):
Expand Down Expand Up @@ -377,9 +376,7 @@ async def root_register_extrinsic(
params=[0, get_hotkey_pub_ss58(wallet)],
)
if uid is not None:
console.print(
f":white_heavy_check_mark: [green]Registered with UID {uid}[/green]"
)
print_success(f"Registered with UID {uid}")
return True, f"Registered with UID {uid}", ext_id
else:
# neuron not found, try again
Expand Down Expand Up @@ -540,7 +537,7 @@ async def _do_set_weights():
return True

if success is True:
console.print(":white_heavy_check_mark: [green]Finalized[/green]")
print_success("Finalized")
return True
else:
fmt_err = format_error_message(error_message)
Expand Down
17 changes: 9 additions & 8 deletions bittensor_cli/src/bittensor/extrinsics/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
confirm_action,
console,
print_error,
print_success,
format_error_message,
unlock_key,
print_extrinsic_id,
Expand Down Expand Up @@ -112,8 +113,8 @@ async def reset_axon_extrinsic(

# We only wait here if we expect finalization.
if not wait_for_finalization and not wait_for_inclusion:
console.print(
":white_heavy_check_mark: [dark_sea_green3]Axon reset successfully[/dark_sea_green3]"
print_success(
"[dark_sea_green3]Axon reset successfully[/dark_sea_green3]"
)
return True, "Not waiting for finalization or inclusion.", None

Expand All @@ -125,8 +126,8 @@ async def reset_axon_extrinsic(
else:
ext_id = await response.get_extrinsic_identifier()
await print_extrinsic_id(response)
console.print(
":white_heavy_check_mark: [dark_sea_green3]Axon reset successfully[/dark_sea_green3]"
print_success(
"[dark_sea_green3]Axon reset successfully[/dark_sea_green3]"
)
return True, "Axon reset successfully", ext_id

Expand Down Expand Up @@ -230,8 +231,8 @@ async def set_axon_extrinsic(

# We only wait here if we expect finalization.
if not wait_for_finalization and not wait_for_inclusion:
console.print(
f":white_heavy_check_mark: [dark_sea_green3]Axon set successfully to {ip}:{port}[/dark_sea_green3]"
print_success(
f"[dark_sea_green3]Axon set successfully to {ip}:{port}[/dark_sea_green3]"
)
return True, "Not waiting for finalization or inclusion.", None

Expand All @@ -243,8 +244,8 @@ async def set_axon_extrinsic(
else:
ext_id = await response.get_extrinsic_identifier()
await print_extrinsic_id(response)
console.print(
f":white_heavy_check_mark: [dark_sea_green3]Axon set successfully to {ip}:{port}[/dark_sea_green3]"
print_success(
f"[dark_sea_green3]Axon set successfully to {ip}:{port}[/dark_sea_green3]"
)
return True, f"Axon set successfully to {ip}:{port}", ext_id

Expand Down
6 changes: 3 additions & 3 deletions bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
confirm_action,
console,
print_error,
print_success,
print_verbose,
is_valid_bittensor_address_or_public_key,
print_error,
Expand Down Expand Up @@ -219,11 +220,10 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt]
success, block_hash, err_msg, ext_receipt = await do_transfer()

if success:
console.print(":white_heavy_check_mark: [green]Finalized[/green]")
console.print(f"[green]Block Hash: {block_hash}[/green]")
print_success(f"Finalized. Block Hash: {block_hash}")

else:
console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
print_error(f"Failed: {err_msg}")

if success:
with console.status(":satellite: Checking Balance...", spinner="aesthetic"):
Expand Down
11 changes: 11 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def print_error(message: str, status=None):
print_console(error_message, "red", err_console)


def print_success(message: str, status=None):
"""Print success messages while temporarily pausing the status spinner."""
success_message = f":white_heavy_check_mark: {message}"
if status:
status.stop()
print_console(success_message, "green", console)
status.start()
else:
print_console(success_message, "green", console)


RAO_PER_TAO = 1e9
U16_MAX = 65535
U64_MAX = 18446744073709551615
Expand Down
31 changes: 14 additions & 17 deletions bittensor_cli/src/commands/crowd/contribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
json_console,
print_error,
print_extrinsic_id,
print_success,
unlock_key,
)
from bittensor_cli.src.commands.crowd.view import show_crowdloan_details
Expand Down Expand Up @@ -89,7 +90,7 @@ async def contribute_to_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, error_msg

is_valid, error_message = validate_for_contribution(
Expand All @@ -99,7 +100,7 @@ async def contribute_to_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_message}))
else:
print_error(f"[red]{error_message}[/red]")
print_error(error_message)
return False, error_message

contributor_address = proxy or wallet.coldkeypub.ss58_address
Expand Down Expand Up @@ -136,15 +137,15 @@ async def contribute_to_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, "Contribution below minimum requirement."

if contribution_amount > user_balance:
error_msg = f"Insufficient balance. You have {user_balance} but trying to contribute {contribution_amount}."
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, "Insufficient balance."

# Auto-adjustment
Expand Down Expand Up @@ -245,7 +246,7 @@ async def contribute_to_crowdloan(
json.dumps({"success": False, "error": unlock_status.message})
)
else:
print_error(f"[red]{unlock_status.message}[/red]")
print_error(unlock_status.message)
return False, unlock_status.message

with console.status(f"\n:satellite: Contributing to crowdloan #{crowdloan_id}..."):
Expand All @@ -272,7 +273,7 @@ async def contribute_to_crowdloan(
)
)
else:
print_error(f"[red]Failed to contribute: {error_message}[/red]")
print_error(f"Failed to contribute: {error_message}")
return False, error_message or "Failed to contribute."

new_balance, new_contribution, updated_crowdloan = await asyncio.gather(
Expand Down Expand Up @@ -398,15 +399,15 @@ async def withdraw_from_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, error_msg

if crowdloan.finalized:
error_msg = f"Crowdloan #{crowdloan_id} is already finalized. Withdrawals are not allowed."
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, "Cannot withdraw from finalized crowdloan."

contributor_address = proxy or wallet.coldkeypub.ss58_address
Expand All @@ -424,7 +425,7 @@ async def withdraw_from_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, "No contribution to withdraw."

is_creator = wallet.coldkeypub.ss58_address == crowdloan.creator
Expand All @@ -435,7 +436,7 @@ async def withdraw_from_crowdloan(
if json_output:
json_console.print(json.dumps({"success": False, "error": error_msg}))
else:
print_error(f"[red]{error_msg}[/red]")
print_error(error_msg)
return False, "Creator cannot withdraw deposit amount."
remaining_contribution = crowdloan.deposit
else:
Expand Down Expand Up @@ -534,7 +535,7 @@ async def withdraw_from_crowdloan(
json.dumps({"success": False, "error": unlock_status.message})
)
else:
print_error(f"[red]{unlock_status.message}[/red]")
print_error(unlock_status.message)
return False, unlock_status.message

with console.status(f"\n:satellite: Withdrawing from crowdloan #{crowdloan_id}..."):
Expand All @@ -561,9 +562,7 @@ async def withdraw_from_crowdloan(
)
)
else:
print_error(
f"[red]Failed to withdraw: {error_message or 'Unknown error'}[/red]"
)
print_error(f"Failed to withdraw: {error_message or 'Unknown error'}")
return False, error_message or "Failed to withdraw from crowdloan."

new_balance, updated_contribution, updated_crowdloan = await asyncio.gather(
Expand Down Expand Up @@ -602,9 +601,7 @@ async def withdraw_from_crowdloan(
}
json_console.print(json.dumps(output_dict))
else:
console.print(
f"\n✅ [green]Successfully withdrew from crowdloan #{crowdloan_id}![/green]\n"
)
print_success(f"Successfully withdrew from crowdloan #{crowdloan_id}!\n")

console.print(
f"Amount Withdrawn: [{COLORS.S.AMOUNT}]{withdrawable}[/{COLORS.S.AMOUNT}]\n"
Expand Down
Loading