diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 6b6b17a2..1b42e6ea 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -49,21 +49,45 @@ class Options: Re-usable typer args """ - wallet_name = typer.Option(None, "--wallet-name", "-w", help="Name of wallet") + wallet_name = typer.Option( + None, + "--wallet-name", + "-w", + "--wallet_name", + "--wallet.name", + help="Name of wallet", + ) wallet_name_req = typer.Option( - None, "--wallet-name", "-w", "--wallet_name", help="Name of wallet", prompt=True + None, + "--wallet-name", + "-w", + "--wallet_name", + "--wallet.name", + help="Name of wallet", + prompt=True, ) wallet_path = typer.Option( - None, "--wallet-path", "-p", "--wallet_path", help="Filepath of root of wallets" + None, + "--wallet-path", + "-p", + "--wallet_path", + "--wallet.path", + help="Filepath of root of wallets", ) wallet_hotkey = typer.Option( - None, "--hotkey", "-H", "--wallet_hotkey", help="Hotkey of wallet" + None, + "--hotkey", + "-H", + "--wallet_hotkey", + "--wallet.hotkey", + help="Hotkey of wallet", ) wallet_hk_req = typer.Option( None, "--hotkey", "-H", "--wallet_hotkey", + "--wallet.hotkey", help="Hotkey name of wallet", prompt=True, ) @@ -1028,7 +1052,7 @@ def wallet_overview( "[red]You have specified hotkeys for inclusion and exclusion. Pick only one or neither." ) raise typer.Exit() - # if all-wallets is entered, ask for path + if all_wallets: if not wallet_path: wallet_path = Prompt.ask( @@ -1228,13 +1252,13 @@ def wallet_faucet( # TODO add the following to config processors: Optional[int] = typer.Option( defaults.pow_register.num_processes, - "-processors", + "--processors", "-p", help="Number of processors to use for POW registration.", ), update_interval: Optional[int] = typer.Option( defaults.pow_register.update_interval, - "-update-interval", + "--update-interval", "-u", help="The number of nonces to process before checking for next block during registration", ), @@ -1671,7 +1695,9 @@ def wallet_history( It helps in fetching info on all the transfers so that user can easily tally and cross-check the transactions. """ self.verbosity_handler(quiet, verbose) - wallet = self.wallet_ask(wallet_name, wallet_path, wallet_hotkey) + wallet = self.wallet_ask( + wallet_name, wallet_path, wallet_hotkey, validate=False + ) return self._run_command(wallets.wallet_history(wallet)) def wallet_set_id( diff --git a/bittensor_cli/src/bittensor/extrinsics/transfer.py b/bittensor_cli/src/bittensor/extrinsics/transfer.py index b0c64659..7d5920f6 100644 --- a/bittensor_cli/src/bittensor/extrinsics/transfer.py +++ b/bittensor_cli/src/bittensor/extrinsics/transfer.py @@ -104,7 +104,7 @@ async def do_transfer() -> tuple[bool, str, str]: f":cross_mark: [red]Invalid destination address[/red]:[bold white]\n {destination}[/bold white]" ) return False - + console.print(f"[dark_orange]Initiating transfer on network: {subtensor.network}") # Unlock wallet coldkey. wallet.unlock_coldkey() diff --git a/bittensor_cli/src/bittensor/utils.py b/bittensor_cli/src/bittensor/utils.py index 2edf8781..7368ec8b 100644 --- a/bittensor_cli/src/bittensor/utils.py +++ b/bittensor_cli/src/bittensor/utils.py @@ -28,17 +28,30 @@ verbose_console = Console(quiet=True) +def print_console(message: str, colour: str, title: str, console: Console): + console.print( + f"[bold {colour}][{title}]:[/bold {colour}] [{colour}]{message}[/{colour}]\n" + ) + + def print_verbose(message: str, status=None): """Print verbose messages while temporarily pausing the status spinner.""" if status: - # Pause the spinner to avoid overlapping status.stop() - verbose_console.print( - f"[bold green][Verbose]:[/bold green] [green]{message}[/green]\n" - ) + print_console(message, "green", "Verbose", verbose_console) + status.start() + else: + print_console(message, "green", "Verbose", verbose_console) + + +def print_error(message: str, status=None): + """Print error messages while temporarily pausing the status spinner.""" if status: - # Resume the spinner after the message is printed + status.stop() + print_console(message, "red", "Error", err_console) status.start() + else: + print_console(message, "red", "Error", err_console) RAO_PER_TAO = 1e9 diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 1cfaeae7..e086025a 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -42,6 +42,7 @@ convert_blocks_to_time, decode_scale_bytes, err_console, + print_error, print_verbose, get_all_wallets_for_path, get_delegates_details_from_github, @@ -249,7 +250,7 @@ async def wallet_balance( style="green", no_wrap=True, ), - title="[underline dark_orange]Wallet Coldkey Balances", + title=f"[underline dark_orange]Wallet Coldkey Balance[/underline dark_orange]\n\n[dark_orange]Network: {subtensor.network}", show_footer=True, show_edge=False, border_style="bright_black", @@ -268,7 +269,7 @@ async def wallet_balance( ) table.add_row() table.add_row( - "Total Balance Across All Coldkeys", + "Total Balance", "", str(total_free_balance), str(total_staked_balance), @@ -337,7 +338,7 @@ def create_transfer_history_table(transfers: list[dict]) -> Table: box=box.SIMPLE, pad_edge=False, width=None, - title="[underline dark_orange]Wallet Transfers\n", + title="[underline dark_orange]Wallet Transfers[/underline dark_orange]\n\n[dark_orange]Network: finney", ) table.add_column( @@ -479,9 +480,13 @@ async def _get_total_balance( ) ).values() ) - all_hotkeys = [ - hk for w in cold_wallets for hk in utils.get_hotkey_wallets_for_wallet(w) - ] + all_hotkeys = [] + for w in cold_wallets: + hotkeys_for_wallet = utils.get_hotkey_wallets_for_wallet(w) + if hotkeys_for_wallet: + all_hotkeys.extend(hotkeys_for_wallet) + else: + print_error(f"[red]No hotkeys found for wallet: ({w.name})") else: # We are only printing keys for a single coldkey coldkey_wallet = wallet @@ -500,6 +505,9 @@ async def _get_total_balance( return [], None all_hotkeys = utils.get_hotkey_wallets_for_wallet(coldkey_wallet) + if not all_hotkeys: + print_error(f"No hotkeys found for wallet ({coldkey_wallet.name})") + return all_hotkeys, total_balance @@ -516,17 +524,18 @@ async def overview( """Prints an overview for the wallet's coldkey.""" total_balance = Balance(0) + + # We are printing for every coldkey. + print_verbose("Fetching total balance for coldkey/s") + block_hash = await subtensor.substrate.get_chain_head() + all_hotkeys, total_balance = await _get_total_balance( + total_balance, subtensor, wallet, all_wallets + ) + with console.status( f":satellite: Synchronizing with chain [white]{subtensor.network}[/white]", spinner="aesthetic", ) as status: - # We are printing for every coldkey. - print_verbose("Fetching total balance for hotkeys", status) - block_hash = await subtensor.substrate.get_chain_head() - all_hotkeys, total_balance = await _get_total_balance( - total_balance, subtensor, wallet, all_wallets - ) - # We are printing for a select number of hotkeys from all_hotkeys. if include_hotkeys: print_verbose( @@ -536,7 +545,7 @@ async def overview( # Check we have keys to display. if not all_hotkeys: - err_console.print("[red]No wallets found.[/red]") + print_error("Aborting as no hotkeys found to process", status) return # Pull neuron info for all keys. @@ -669,6 +678,13 @@ async def overview( title = "[underline dark_orange]All Wallets:[/underline dark_orange]" grid.add_row(Align(title, vertical="middle", align="center")) + grid.add_row( + Align( + f"[dark_orange]Network: {subtensor.network}", + vertical="middle", + align="center", + ) + ) # Generate rows per netuid hotkeys_seen = set() total_neurons = 0 @@ -1233,10 +1249,12 @@ def neuron_row_maker( all_hotkeys = get_all_wallets_for_path( wallet.path ) # TODO verify this is correct + else: print_verbose(f"Fetching data for wallet: {wallet.name}") wallets = [wallet] all_hotkeys = get_hotkey_wallets_for_wallet(wallet) + with console.status("Synchronising with chain...", spinner="aesthetic") as status: block_hash = await subtensor.substrate.get_chain_head() await subtensor.substrate.init_runtime(block_hash=block_hash) @@ -1268,7 +1286,7 @@ def neuron_row_maker( Column("[bold white]Hotkey", style="bright_magenta"), Column("[bold white]Stake", style="light_goldenrod2"), Column("[bold white]Emission", style="rgb(42,161,152)"), - title="[underline dark_orange]Wallets\n", + title=f"[underline dark_orange]Wallets[/underline dark_orange]\n\n[dark_orange]Network: {subtensor.network}", show_footer=True, show_edge=False, expand=True,