Skip to content
102 changes: 50 additions & 52 deletions bittensor_cli/cli.py

Large diffs are not rendered by default.

53 changes: 23 additions & 30 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from bittensor_cli.src.bittensor.utils import (
confirm_action,
console,
err_console,
print_error,
format_error_message,
millify,
get_human_readable,
Expand Down Expand Up @@ -94,7 +94,7 @@ def _get_real_torch():


def log_no_torch_error():
err_console.print(
print_error(
"This command requires torch. You can install torch"
" with `pip install torch` and run the command again."
)
Expand Down Expand Up @@ -509,8 +509,8 @@ async def get_neuron_for_pubkey_and_subnet():

print_verbose("Checking subnet status")
if not await subtensor.subnet_exists(netuid):
err_console.print(
f":cross_mark: [red]Failed[/red]: error: [bold white]subnet:{netuid}[/bold white] does not exist."
print_error(
f"Failed: error: [bold white]subnet:{netuid}[/bold white] does not exist."
)
return False

Expand Down Expand Up @@ -587,7 +587,7 @@ async def get_neuron_for_pubkey_and_subnet():
subtensor, netuid=netuid, hotkey_ss58=get_hotkey_pub_ss58(wallet)
)
if is_registered:
err_console.print(
print_error(
f":white_heavy_check_mark: [dark_sea_green3]Already registered on netuid:{netuid}[/dark_sea_green3]"
)
return True
Expand Down Expand Up @@ -635,9 +635,7 @@ async def get_neuron_for_pubkey_and_subnet():
f"[bold]subnet:{netuid}[/bold][/dark_sea_green3]"
)
return True
err_console.print(
f":cross_mark: [red]Failed[/red]: {err_msg}"
)
print_error(f"Failed: {err_msg}")
await asyncio.sleep(0.5)

# Successful registration, final check for neuron and pubkey
Expand All @@ -655,25 +653,23 @@ async def get_neuron_for_pubkey_and_subnet():
return True
else:
# neuron not found, try again
err_console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
print_error("Unknown error. Neuron not found.")
continue
else:
# Exited loop because pow is no longer valid.
err_console.print("[red]POW is stale.[/red]")
print_error("POW is stale.")
# Try again.
continue

if attempts < max_allowed_attempts:
# Failed registration, retry pow
attempts += 1
err_console.print(
print_error(
":satellite: Failed registration, retrying pow ...({attempts}/{max_allowed_attempts})"
)
else:
# Failed to register after max attempts.
err_console.print("[red]No more attempts.[/red]")
print_error("No more attempts.")
return False


Expand Down Expand Up @@ -772,7 +768,7 @@ async def burned_register_extrinsic(
)

if not success:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
print_error(f"Failed: {err_msg}")
await asyncio.sleep(0.5)
return False, err_msg, None
# Successful registration, final check for neuron and pubkey
Expand Down Expand Up @@ -808,9 +804,7 @@ async def burned_register_extrinsic(
return True, f"Registered on {netuid} with UID {my_uid}", ext_id
else:
# neuron not found, try again
err_console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
print_error("Unknown error. Neuron not found.")
return False, "Unknown error. Neuron not found.", ext_id


Expand Down Expand Up @@ -891,7 +885,7 @@ async def run_faucet_extrinsic(
if cuda:
if not torch.cuda.is_available():
if prompt:
err_console.print("CUDA is not available.")
print_error("CUDA is not available.")
return False, "CUDA is not available."
pow_result = await create_pow(
subtensor,
Expand Down Expand Up @@ -936,9 +930,8 @@ async def run_faucet_extrinsic(

# process if registration successful, try again if pow is still valid
if not await response.is_success:
err_console.print(
f":cross_mark: [red]Failed[/red]: "
f"{format_error_message(await response.error_message)}"
print_error(
f"Failed: {format_error_message(await response.error_message)}"
)
if attempts == max_allowed_attempts:
raise MaxAttemptsException
Expand Down Expand Up @@ -1788,29 +1781,29 @@ async def swap_hotkey_extrinsic(
)

if netuid is not None and netuid not in netuids_registered:
err_console.print(
f":cross_mark: [red]Failed[/red]: Original hotkey {hk_ss58} is not registered on subnet {netuid}"
print_error(
f"Failed: Original hotkey {hk_ss58} is not registered on subnet {netuid}"
)
return False, None

elif not len(netuids_registered) > 0:
err_console.print(
print_error(
f"Original hotkey [dark_orange]{hk_ss58}[/dark_orange] is not registered on any subnet. "
f"Please register and try again"
)
return False, None

if netuid is not None:
if netuid in netuids_registered_new_hotkey:
err_console.print(
f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} "
print_error(
f"Failed: New hotkey {new_hk_ss58} "
f"is already registered on subnet {netuid}"
)
return False, None
else:
if len(netuids_registered_new_hotkey) > 0:
err_console.print(
f":cross_mark: [red]Failed[/red]: New hotkey {new_hk_ss58} "
print_error(
f"Failed: New hotkey {new_hk_ss58} "
f"is already registered on subnet(s) {netuids_registered_new_hotkey}"
)
return False, None
Expand Down Expand Up @@ -1864,6 +1857,6 @@ async def swap_hotkey_extrinsic(
)
return True, ext_receipt
else:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
print_error(f"Failed: {err_msg}")
time.sleep(0.5)
return False, ext_receipt
14 changes: 6 additions & 8 deletions bittensor_cli/src/bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from bittensor_cli.src.bittensor.utils import (
confirm_action,
console,
err_console,
print_error,
u16_normalized_float,
print_verbose,
format_error_message,
Expand Down Expand Up @@ -363,7 +363,7 @@ async def root_register_extrinsic(
)

if not success:
err_console.print(f":cross_mark: [red]Failed[/red]: {err_msg}")
print_error(f"Failed: {err_msg}")
await asyncio.sleep(0.5)
return False, err_msg, None

Expand All @@ -383,9 +383,7 @@ async def root_register_extrinsic(
return True, f"Registered with UID {uid}", ext_id
else:
# neuron not found, try again
err_console.print(
":cross_mark: [red]Unknown error. Neuron not found.[/red]"
)
print_error("Unknown error. Neuron not found.")
return False, "Unknown error. Neuron not found.", ext_id


Expand Down Expand Up @@ -454,7 +452,7 @@ async def _do_set_weights():
)

if my_uid is None:
err_console.print("Your hotkey is not registered to the root network")
print_error("Your hotkey is not registered to the root network")
return False

if not unlock_key(wallet).success:
Expand Down Expand Up @@ -546,10 +544,10 @@ async def _do_set_weights():
return True
else:
fmt_err = format_error_message(error_message)
err_console.print(f":cross_mark: [red]Failed[/red]: {fmt_err}")
print_error(f"Failed: {fmt_err}")
return False

except SubstrateRequestException as e:
fmt_err = format_error_message(e)
err_console.print(":cross_mark: [red]Failed[/red]: error:{}".format(fmt_err))
print_error("Failed: error:{}".format(fmt_err))
return False
14 changes: 5 additions & 9 deletions bittensor_cli/src/bittensor/extrinsics/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bittensor_cli.src.bittensor.utils import (
confirm_action,
console,
err_console,
print_error,
format_error_message,
unlock_key,
print_extrinsic_id,
Expand Down Expand Up @@ -120,7 +120,7 @@ async def reset_axon_extrinsic(
success = await response.is_success
if not success:
error_msg = format_error_message(await response.error_message)
err_console.print(f":cross_mark: [red]Failed[/red]: {error_msg}")
print_error(f"Failed: {error_msg}")
return False, error_msg, None
else:
ext_id = await response.get_extrinsic_identifier()
Expand All @@ -132,9 +132,7 @@ async def reset_axon_extrinsic(

except Exception as e:
error_message = format_error_message(e)
err_console.print(
f":cross_mark: [red]Failed to reset axon: {error_message}[/red]"
)
print_error(f"Failed to reset axon: {error_message}")
return False, error_message, None


Expand Down Expand Up @@ -240,7 +238,7 @@ async def set_axon_extrinsic(
success = await response.is_success
if not success:
error_msg = format_error_message(await response.error_message)
err_console.print(f":cross_mark: [red]Failed[/red]: {error_msg}")
print_error(f"Failed: {error_msg}")
return False, error_msg, None
else:
ext_id = await response.get_extrinsic_identifier()
Expand All @@ -252,7 +250,5 @@ async def set_axon_extrinsic(

except Exception as e:
error_message = format_error_message(e)
err_console.print(
f":cross_mark: [red]Failed to set axon: {error_message}[/red]"
)
print_error(f"Failed to set axon: {error_message}")
return False, error_message, None
22 changes: 11 additions & 11 deletions bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bittensor_cli.src.bittensor.utils import (
confirm_action,
console,
err_console,
print_error,
print_verbose,
is_valid_bittensor_address_or_public_key,
print_error,
Expand Down Expand Up @@ -95,8 +95,8 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt]

# Validate destination address.
if not is_valid_bittensor_address_or_public_key(destination):
err_console.print(
f":cross_mark: [red]Invalid destination SS58 address[/red]:[bold white]\n {destination}[/bold white]"
print_error(
f"Invalid destination SS58 address:[bold white]\n {destination}[/bold white]"
)
return False, None
console.print(f"[dark_orange]Initiating transfer on network: {subtensor.network}")
Expand Down Expand Up @@ -139,33 +139,33 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt]

if proxy:
if proxy_balance < (amount + existential_deposit) and not allow_death:
err_console.print(
":cross_mark: [bold red]Not enough balance[/bold red]:\n\n"
print_error(
"[bold red]Not enough balance[/bold red]:\n\n"
f" balance: [bright_cyan]{proxy_balance}[/bright_cyan]\n"
f" amount: [bright_cyan]{amount}[/bright_cyan]\n"
f" would bring you under the existential deposit: [bright_cyan]{existential_deposit}[/bright_cyan].\n"
f"You can try again with `--allow-death`."
)
return False, None
if account_balance < fee:
err_console.print(
":cross_mark: [bold red]Not enough balance[/bold red]:\n\n"
print_error(
"[bold red]Not enough balance[/bold red]:\n\n"
f" balance: [bright_cyan]{account_balance}[/bright_cyan]\n"
f" fee: [bright_cyan]{fee}[/bright_cyan]\n"
f" would bring you under the existential deposit: [bright_cyan]{existential_deposit}[/bright_cyan].\n"
)
return False, None
if account_balance < amount and allow_death:
print_error(
":cross_mark: [bold red]Not enough balance[/bold red]:\n\n"
"[bold red]Not enough balance[/bold red]:\n\n"
f" balance: [bright_red]{account_balance}[/bright_red]\n"
f" amount: [bright_red]{amount}[/bright_red]\n"
)
return False, None
else:
if account_balance < (amount + fee + existential_deposit) and not allow_death:
err_console.print(
":cross_mark: [bold red]Not enough balance[/bold red]:\n\n"
print_error(
"[bold red]Not enough balance[/bold red]:\n\n"
f" balance: [bright_cyan]{account_balance}[/bright_cyan]\n"
f" amount: [bright_cyan]{amount}[/bright_cyan]\n"
f" for fee: [bright_cyan]{fee}[/bright_cyan]\n"
Expand All @@ -175,7 +175,7 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt]
return False, None
elif account_balance < (amount + fee) and allow_death:
print_error(
":cross_mark: [bold red]Not enough balance[/bold red]:\n\n"
"[bold red]Not enough balance[/bold red]:\n\n"
f" balance: [bright_red]{account_balance}[/bright_red]\n"
f" amount: [bright_red]{amount}[/bright_red]\n"
f" for fee: [bright_red]{fee}[/bright_red]"
Expand Down
8 changes: 4 additions & 4 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from bittensor_cli.src.bittensor.utils import (
format_error_message,
console,
err_console,
print_error,
decode_hex_identity_dict,
validate_chain_endpoint,
u16_normalized_float,
Expand Down Expand Up @@ -136,8 +136,8 @@ async def __aenter__(self):
await self.substrate.initialize()
return self
except TimeoutError: # TODO verify
err_console.print(
"\n[red]Error[/red]: Timeout occurred connecting to substrate. "
print_error(
"\nError: Timeout occurred connecting to substrate. "
f"Verify your chain and network settings: {self}"
)
raise typer.Exit(code=1)
Expand Down Expand Up @@ -2527,5 +2527,5 @@ async def best_connection(networks: list[str]):
t2 = time.monotonic()
results[network] = [t2 - t1, latency, t2 - pt1]
except Exception as e:
err_console.print(f"Error attempting network {network}: {e}")
print_error(f"Error attempting network {network}: {e}")
return results
Loading