From 90c1796485a49a9cdbf9dfb1c538955a25570ada Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Mon, 12 May 2025 16:16:13 +0200 Subject: [PATCH 1/2] Fixes name-shadowing bug. --- bittensor_cli/cli.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 80ddc4a0d..e2c55a41d 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -436,14 +436,14 @@ def parse_mnemonic(mnemonic: str) -> str: def get_creation_data( mnemonic: Optional[str], seed: Optional[str], - json: Optional[str], + json_path: Optional[str], json_password: Optional[str], ) -> tuple[str, str, str, str]: """ Determines which of the key creation elements have been supplied, if any. If None have been supplied, prompts to user, and determines what they've supplied. Returns all elements in a tuple. """ - if not mnemonic and not seed and not json: + if not mnemonic and not seed and not json_path: prompt_answer = Prompt.ask( "Enter the mnemonic, or the seed hex string, or the location of the JSON file." ) @@ -452,20 +452,20 @@ def get_creation_data( elif len(prompt_answer.split(" ")) > 1: mnemonic = parse_mnemonic(prompt_answer) else: - json = prompt_answer + json_path = prompt_answer elif mnemonic: mnemonic = parse_mnemonic(mnemonic) - if json: - if not os.path.exists(json): - print_error(f"The JSON file '{json}' does not exist.") + if json_path: + if not os.path.exists(json_path): + print_error(f"The JSON file '{json_path}' does not exist.") raise typer.Exit() - if json and not json_password: + if json_path and not json_password: json_password = Prompt.ask( "Enter the backup password for JSON file.", password=True ) - return mnemonic, seed, json, json_password + return mnemonic, seed, json_path, json_password def config_selector(conf: dict, title: str): @@ -2090,7 +2090,7 @@ def wallet_regen_coldkey( wallet_hotkey: Optional[str] = Options.wallet_hotkey, mnemonic: Optional[str] = Options.mnemonic, seed: Optional[str] = Options.seed, - json: Optional[str] = Options.json, + json_path: Optional[str] = Options.json, json_password: Optional[str] = Options.json_password, use_password: Optional[bool] = Options.use_password, overwrite: bool = Options.overwrite, @@ -2130,15 +2130,15 @@ def wallet_regen_coldkey( wallet = Wallet(wallet_name, wallet_hotkey, wallet_path) - mnemonic, seed, json, json_password = get_creation_data( - mnemonic, seed, json, json_password + mnemonic, seed, json_path, json_password = get_creation_data( + mnemonic, seed, json_path, json_password ) return self._run_command( wallets.regen_coldkey( wallet, mnemonic, seed, - json, + json_path, json_password, use_password, overwrite, @@ -2214,7 +2214,7 @@ def wallet_regen_hotkey( wallet_hotkey: Optional[str] = Options.wallet_hotkey, mnemonic: Optional[str] = Options.mnemonic, seed: Optional[str] = Options.seed, - json: Optional[str] = Options.json, + json_path: Optional[str] = Options.json, json_password: Optional[str] = Options.json_password, use_password: bool = typer.Option( False, # Overriden to False @@ -2250,15 +2250,15 @@ def wallet_regen_hotkey( ask_for=[WO.NAME, WO.PATH, WO.HOTKEY], validate=WV.WALLET, ) - mnemonic, seed, json, json_password = get_creation_data( - mnemonic, seed, json, json_password + mnemonic, seed, json_path, json_password = get_creation_data( + mnemonic, seed, json_path, json_password ) return self._run_command( wallets.regen_hotkey( wallet, mnemonic, seed, - json, + json_path, json_password, use_password, overwrite, From 56f193294d233f512bbced52cf444e91be76af5e Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Mon, 12 May 2025 16:48:05 +0200 Subject: [PATCH 2/2] Adds explicit choosing rather than parsing so as to ensure we do not incorrectly assume the entry the user wishes to make. Also correctly snips the leading '0x' from seed hex. --- bittensor_cli/cli.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index e2c55a41d..8a6ddac3a 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -444,14 +444,27 @@ def get_creation_data( prompts to user, and determines what they've supplied. Returns all elements in a tuple. """ if not mnemonic and not seed and not json_path: - prompt_answer = Prompt.ask( - "Enter the mnemonic, or the seed hex string, or the location of the JSON file." + choices = { + 1: "mnemonic", + 2: "seed hex string", + 3: "path to JSON File", + } + type_answer = IntPrompt.ask( + "Select one of the following to enter\n" + f"[{COLORS.G.HINT}][1][/{COLORS.G.HINT}] Mnemonic\n" + f"[{COLORS.G.HINT}][2][/{COLORS.G.HINT}] Seed hex string\n" + f"[{COLORS.G.HINT}][3][/{COLORS.G.HINT}] Path to JSON File\n", + choices=["1", "2", "3"], + show_choices=False, ) - if prompt_answer.startswith("0x"): + prompt_answer = Prompt.ask(f"Please enter your {choices[type_answer]}") + if type_answer == 1: + mnemonic = prompt_answer + elif type_answer == 2: seed = prompt_answer - elif len(prompt_answer.split(" ")) > 1: - mnemonic = parse_mnemonic(prompt_answer) - else: + if seed.startswith("0x"): + seed = seed[2:] + elif type_answer == 3: json_path = prompt_answer elif mnemonic: mnemonic = parse_mnemonic(mnemonic)