diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 5008a03c5..24d8e017f 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1168,6 +1168,29 @@ def wallet_ask( :return: created Wallet object """ # Prompt for missing attributes specified in ask_for + + if wallet_path: + if wallet_path == "default": + wallet_path = defaults.wallet.path + + elif self.config.get("wallet_path"): + wallet_path = self.config.get("wallet_path") + console.print( + f"Using the wallet path from config:[bold magenta] {wallet_path}" + ) + + if WO.PATH in ask_for and not wallet_path: + wallet_path = Prompt.ask( + "Enter the [blue]wallet path[/blue]" + + " [dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-path`)[/dark_sea_green3 italic]", + default=defaults.wallet.path, + ) + if wallet_path: + wallet_path = os.path.expanduser(wallet_path) + else: + wallet_path = os.path.expanduser(defaults.wallet.path) + console.print(f"Using default wallet path: ({defaults.wallet.path})") + if WO.NAME in ask_for and not wallet_name: if self.config.get("wallet_name"): wallet_name = self.config.get("wallet_name") @@ -1175,13 +1198,9 @@ def wallet_ask( f"Using the wallet name from config:[bold cyan] {wallet_name}" ) else: - wallet_name = typer.prompt( - typer.style("Enter the wallet name", fg="blue") - + typer.style( - " (Hint: You can set this with `btcli config set --wallet-name`)", - fg="green", - italic=True, - ), + wallet_name = Prompt.ask( + "Enter the [blue]wallet name[/blue]" + + " [dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-name`)[/dark_sea_green3 italic]", default=defaults.wallet.name, ) @@ -1192,38 +1211,13 @@ def wallet_ask( f"Using the wallet hotkey from config:[bold cyan] {wallet_hotkey}" ) else: - wallet_hotkey = typer.prompt( - typer.style("Enter the wallet hotkey", fg="blue") - + typer.style( - " (Hint: You can set this with `btcli config set --wallet-hotkey`)", - fg="green", - italic=True, - ), + wallet_hotkey = Prompt.ask( + "Enter the [blue]wallet hotkey[/blue]" + + " [dark_sea_green3 italic](Hint: You can set this with `btcli config set --wallet-hotkey`)[/dark_sea_green3 italic]", default=defaults.wallet.hotkey, ) - if wallet_path: - if wallet_path == "default": - wallet_path = defaults.wallet.path - elif self.config.get("wallet_path"): - wallet_path = self.config.get("wallet_path") - console.print( - f"Using the wallet path from config:[bold magenta] {wallet_path}" - ) - - if WO.PATH in ask_for and not wallet_path: - wallet_path = typer.prompt( - typer.style("Enter the wallet path", fg="blue") - + typer.style( - " (Hint: You can set this with `btcli config set --wallet-path`)", - fg="green", - italic=True, - ), - default=defaults.wallet.path, - ) # Create the Wallet object - if wallet_path: - wallet_path = os.path.expanduser(wallet_path) wallet = Wallet(name=wallet_name, path=wallet_path, hotkey=wallet_hotkey) # Validate the wallet if required @@ -1379,7 +1373,7 @@ def wallet_overview( "Netuids must be a comma-separated list of ints, e.g., `--netuids 1,2,3,4`.", ) - ask_for = [WO.NAME, WO.PATH] if not all_wallets else [WO.PATH] + ask_for = [WO.NAME] if not all_wallets else [] validate = WV.WALLET if not all_wallets else WV.NONE wallet = self.wallet_ask( wallet_name, wallet_path, wallet_hotkey, ask_for=ask_for, validate=validate @@ -1467,7 +1461,7 @@ def wallet_transfer( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH], + ask_for=[WO.NAME], validate=WV.WALLET, ) subtensor = self.initialize_chain(network) @@ -1524,7 +1518,7 @@ def wallet_swap_hotkey( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) if not destination_hotkey_name: @@ -1536,7 +1530,7 @@ def wallet_swap_hotkey( wallet_name, wallet_path, destination_hotkey_name, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) self.initialize_chain(network) @@ -1602,7 +1596,7 @@ def wallet_inspect( ) # if all-wallets is entered, ask for path - ask_for = [WO.NAME, WO.PATH] if not all_wallets else [WO.PATH] + ask_for = [WO.NAME] if not all_wallets else [] validate = WV.WALLET if not all_wallets else WV.NONE wallet = self.wallet_ask( wallet_name, wallet_path, wallet_hotkey, ask_for=ask_for, validate=validate @@ -1691,7 +1685,7 @@ def wallet_faucet( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH], + ask_for=[WO.NAME], validate=WV.WALLET, ) return self._run_command( @@ -2122,7 +2116,7 @@ def wallet_balance( else: raise typer.Exit() else: - ask_for = [WO.PATH] if all_balances else [WO.NAME, WO.PATH] + ask_for = [] if all_balances else [WO.NAME] validate = WV.NONE if all_balances else WV.WALLET wallet = self.wallet_ask( wallet_name, @@ -2168,7 +2162,7 @@ def wallet_history( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH], + ask_for=[WO.NAME], validate=WV.WALLET, ) return self._run_command(wallets.wallet_history(wallet)) @@ -2269,7 +2263,7 @@ def wallet_set_id( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.HOTKEY, WO.PATH, WO.NAME], + ask_for=[WO.HOTKEY, WO.NAME], validate=WV.WALLET_AND_HOTKEY, ) @@ -2424,7 +2418,7 @@ def wallet_sign( default=False, ) - ask_for = [WO.HOTKEY, WO.PATH, WO.NAME] if use_hotkey else [WO.NAME, WO.PATH] + ask_for = [WO.HOTKEY, WO.NAME] if use_hotkey else [WO.NAME] validate = WV.WALLET_AND_HOTKEY if use_hotkey else WV.WALLET wallet = self.wallet_ask( @@ -2527,7 +2521,7 @@ def root_set_weights( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.HOTKEY, WO.PATH, WO.NAME], + ask_for=[WO.HOTKEY, WO.NAME], validate=WV.WALLET_AND_HOTKEY, ) self._run_command( @@ -2618,7 +2612,7 @@ def root_boost( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -2659,7 +2653,7 @@ def root_slash( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -2709,7 +2703,7 @@ def root_senate_vote( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -2764,7 +2758,7 @@ def root_register( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -2833,7 +2827,7 @@ def root_set_take( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) @@ -2890,10 +2884,10 @@ def root_delegate_stake( if not stake_all and not amount: while True: amount = FloatPrompt.ask( - "[blue bold]Amount to stake (TAO τ)[/blue bold]", console=console + "Amount to [blue]stake (TAO τ)[/blue]", console=console ) confirmation = FloatPrompt.ask( - "[blue bold]Confirm the amount to stake (TAO τ)[/blue bold]", + "Confirm the amount to stake [blue](TAO τ)[/blue]", console=console, ) if amount == confirmation: @@ -2904,7 +2898,7 @@ def root_delegate_stake( ) wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) return self._run_command( root.delegate_stake( @@ -2960,10 +2954,10 @@ def root_undelegate_stake( if not unstake_all and not amount: while True: amount = FloatPrompt.ask( - "[blue bold]Amount to unstake (TAO τ)[/blue bold]", console=console + "Amount to [blue]unstake (TAO τ)[/blue]", console=console ) confirmation = FloatPrompt.ask( - "[blue bold]Confirm the amount to unstake (TAO τ)[/blue bold]", + "Confirm the amount to unstake [blue](TAO τ)[/blue]", console=console, ) if amount == confirmation: @@ -2974,7 +2968,7 @@ def root_undelegate_stake( ) wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) self._run_command( root.delegate_unstake( @@ -3046,7 +3040,7 @@ def root_my_delegates( wallet_name, wallet_path, wallet_hotkey, - ask_for=([WO.NAME, WO.PATH] if not all_wallets else [WO.PATH]), + ask_for=([WO.NAME] if not all_wallets else []), validate=WV.WALLET if not all_wallets else WV.NONE, ) self._run_command( @@ -3160,7 +3154,7 @@ def root_nominate( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -3225,12 +3219,12 @@ def stake_show( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.PATH], + ask_for=[], validate=WV.NONE, ) else: wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) return self._run_command( @@ -3312,7 +3306,7 @@ def stake_add( raise typer.Exit() if not stake_all and not amount and not max_stake: - amount = FloatPrompt.ask("[blue bold]Amount to stake (TAO τ)[/blue bold]") + amount = FloatPrompt.ask("Amount to [blue]stake (TAO τ)[/blue]") if stake_all and not amount: if not Confirm.ask("Stake all the available TAO tokens?", default=False): @@ -3343,7 +3337,7 @@ def stake_add( if is_valid_ss58_address(hotkey_or_ss58): hotkey_ss58_address = hotkey_or_ss58 wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) else: wallet_hotkey = hotkey_or_ss58 @@ -3351,20 +3345,20 @@ def stake_add( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.HOTKEY, WO.PATH], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) elif all_hotkeys or include_hotkeys or exclude_hotkeys or hotkey_ss58_address: wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) else: wallet = self.wallet_ask( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) @@ -3479,7 +3473,7 @@ def stake_remove( raise typer.Exit() if not unstake_all and not amount and not keep_stake: - amount = FloatPrompt.ask("[blue bold]Amount to unstake (TAO τ)[/blue bold]") + amount = FloatPrompt.ask("Amount to [blue]unstake (TAO τ)[/blue]") if unstake_all and not amount and prompt: if not Confirm.ask("Unstake all staked TAO tokens?", default=False): @@ -3497,7 +3491,7 @@ def stake_remove( if is_valid_ss58_address(hotkey_or_ss58): hotkey_ss58_address = hotkey_or_ss58 wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) else: wallet_hotkey = hotkey_or_ss58 @@ -3505,13 +3499,13 @@ def stake_remove( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) elif all_hotkeys or include_hotkeys or exclude_hotkeys or hotkey_ss58_address: wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) else: @@ -3519,7 +3513,7 @@ def stake_remove( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) @@ -3590,7 +3584,7 @@ def stake_get_children( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) @@ -3691,7 +3685,7 @@ def stake_set_children( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -3743,7 +3737,7 @@ def stake_revoke_children( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) if all_netuids and netuid: @@ -3817,7 +3811,7 @@ def stake_childkey_take( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) if all_netuids and netuid: @@ -3895,7 +3889,7 @@ def sudo_set( ) wallet = self.wallet_ask( - wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH] + wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME] ) return self._run_command( sudo.sudo_set_hyperparameter( @@ -3996,7 +3990,6 @@ def subnets_create( self, wallet_name: str = Options.wallet_name, wallet_path: str = Options.wallet_path, - wallet_hotkey: str = Options.wallet_hotkey, network: Optional[list[str]] = Options.network, prompt: bool = Options.prompt, quiet: bool = Options.quiet, @@ -4013,9 +4006,9 @@ def subnets_create( wallet = self.wallet_ask( wallet_name, wallet_path, - wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], - validate=WV.WALLET_AND_HOTKEY, + None, + ask_for=[WO.NAME], + validate=WV.WALLET, ) return self._run_command( subnets.create(wallet, self.initialize_chain(network), prompt) @@ -4093,7 +4086,7 @@ def subnets_pow_register( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ), self.initialize_chain(network), @@ -4135,7 +4128,7 @@ def subnets_register( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command( @@ -4322,7 +4315,7 @@ def weights_reveal( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) @@ -4418,7 +4411,7 @@ def weights_commit( wallet_name, wallet_path, wallet_hotkey, - ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], + ask_for=[WO.NAME, WO.HOTKEY], validate=WV.WALLET_AND_HOTKEY, ) return self._run_command(