5858 validate_uri ,
5959 prompt_for_subnet_identity ,
6060 validate_rate_tolerance ,
61+ get_hotkey_pub_ss58 ,
6162)
6263from bittensor_cli .src .commands import sudo , wallets , view
6364from bittensor_cli .src .commands import weights as weights_cmds
@@ -791,6 +792,9 @@ def __init__(self):
791792 self .wallet_app .command (
792793 "regen-hotkey" , rich_help_panel = HELP_PANELS ["WALLET" ]["SECURITY" ]
793794 )(self .wallet_regen_hotkey )
795+ self .wallet_app .command (
796+ "regen-hotkeypub" , rich_help_panel = HELP_PANELS ["WALLET" ]["SECURITY" ]
797+ )(self .wallet_regen_hotkey_pub )
794798 self .wallet_app .command (
795799 "new-hotkey" , rich_help_panel = HELP_PANELS ["WALLET" ]["MANAGEMENT" ]
796800 )(self .wallet_new_hotkey )
@@ -973,6 +977,10 @@ def __init__(self):
973977 "regen_hotkey" ,
974978 hidden = True ,
975979 )(self .wallet_regen_hotkey )
980+ self .wallet_app .command (
981+ "regen_hotkeypub" ,
982+ hidden = True ,
983+ )(self .wallet_regen_hotkey_pub )
976984 self .wallet_app .command (
977985 "new_hotkey" ,
978986 hidden = True ,
@@ -1143,7 +1151,8 @@ async def _run():
11431151 exit_early is True
11441152 ): # temporarily to handle multiple run commands in one session
11451153 try :
1146- await self .subtensor .substrate .close ()
1154+ if self .subtensor :
1155+ await self .subtensor .substrate .close ()
11471156 raise typer .Exit ()
11481157 except Exception as e : # ensures we always exit cleanly
11491158 if not isinstance (e , (typer .Exit , RuntimeError )):
@@ -1726,7 +1735,7 @@ def wallet_ask(
17261735 if return_wallet_and_hotkey :
17271736 valid = utils .is_valid_wallet (wallet )
17281737 if valid [1 ]:
1729- return wallet , wallet . hotkey . ss58_address
1738+ return wallet , get_hotkey_pub_ss58 ( wallet )
17301739 else :
17311740 if wallet_hotkey and is_valid_ss58_address (wallet_hotkey ):
17321741 return wallet , wallet_hotkey
@@ -2285,7 +2294,7 @@ def wallet_regen_coldkey_pub(
22852294
22862295 EXAMPLE
22872296
2288- [green]$[/green] btcli wallet regen_coldkeypub --ss58_address 5DkQ4...
2297+ [green]$[/green] btcli wallet regen-coldkeypub --ss58_address 5DkQ4...
22892298
22902299 [bold]Note[/bold]: This command is particularly useful for users who need to regenerate their coldkeypub, perhaps due to file corruption or loss. You will need either ss58 address or public hex key from your old coldkeypub.txt for the wallet. It is a recovery-focused utility that ensures continued access to your wallet functionalities.
22912300 """
@@ -2300,7 +2309,7 @@ def wallet_regen_coldkey_pub(
23002309
23012310 if not wallet_name :
23022311 wallet_name = Prompt .ask (
2303- f"Enter the name of the [{ COLORS .G .CK } ]new wallet (coldkey) " ,
2312+ f"Enter the name of the [{ COLORS .G .CK } ]wallet for the new coldkeypub " ,
23042313 default = defaults .wallet .name ,
23052314 )
23062315 wallet = Wallet (wallet_name , wallet_hotkey , wallet_path )
@@ -2317,7 +2326,7 @@ def wallet_regen_coldkey_pub(
23172326 address = ss58_address if ss58_address else public_key_hex
23182327 ):
23192328 rich .print ("[red]Error: Invalid SS58 address or public key![/red]" )
2320- raise typer . Exit ()
2329+ return
23212330 return self ._run_command (
23222331 wallets .regen_coldkey_pub (
23232332 wallet , ss58_address , public_key_hex , overwrite , json_output
@@ -2383,6 +2392,68 @@ def wallet_regen_hotkey(
23832392 )
23842393 )
23852394
2395+ def wallet_regen_hotkey_pub (
2396+ self ,
2397+ wallet_name : Optional [str ] = Options .wallet_name ,
2398+ wallet_path : Optional [str ] = Options .wallet_path ,
2399+ wallet_hotkey : Optional [str ] = Options .wallet_hotkey ,
2400+ public_key_hex : Optional [str ] = Options .public_hex_key ,
2401+ ss58_address : Optional [str ] = Options .ss58_address ,
2402+ overwrite : bool = Options .overwrite ,
2403+ quiet : bool = Options .quiet ,
2404+ verbose : bool = Options .verbose ,
2405+ json_output : bool = Options .json_output ,
2406+ ):
2407+ """
2408+ Regenerates the public part of a hotkey (hotkeypub.txt) for a wallet.
2409+
2410+ Use this command when you need to move machine for subnet mining. Use the public key or SS58 address from your hotkeypub.txt that you have on another machine to regenerate the hotkeypub.txt on this new machine.
2411+
2412+ USAGE
2413+
2414+ The command requires either a public key in hexadecimal format or an ``SS58`` address from the existing hotkeypub.txt from old machine to regenerate the coldkeypub on the new machine.
2415+
2416+ EXAMPLE
2417+
2418+ [green]$[/green] btcli wallet regen-hotkeypub --ss58_address 5DkQ4...
2419+
2420+ [bold]Note[/bold]: This command is particularly useful for users who need to regenerate their hotkeypub, perhaps due to file corruption or loss. You will need either ss58 address or public hex key from your old hotkeypub.txt for the wallet. It is a recovery-focused utility that ensures continued access to your wallet functionalities.
2421+ """
2422+ self .verbosity_handler (quiet , verbose , json_output )
2423+
2424+ if not wallet_path :
2425+ wallet_path = Prompt .ask (
2426+ "Enter the path to the wallets directory" ,
2427+ default = self .config .get ("wallet_path" ) or defaults .wallet .path ,
2428+ )
2429+ wallet_path = os .path .expanduser (wallet_path )
2430+
2431+ if not wallet_name :
2432+ wallet_name = Prompt .ask (
2433+ f"Enter the name of the [{ COLORS .G .CK } ]wallet for the new hotkeypub" ,
2434+ default = defaults .wallet .name ,
2435+ )
2436+ wallet = Wallet (wallet_name , wallet_hotkey , wallet_path )
2437+
2438+ if not ss58_address and not public_key_hex :
2439+ prompt_answer = typer .prompt (
2440+ "Enter the ss58_address or the public key in hex"
2441+ )
2442+ if prompt_answer .startswith ("0x" ):
2443+ public_key_hex = prompt_answer
2444+ else :
2445+ ss58_address = prompt_answer
2446+ if not utils .is_valid_bittensor_address_or_public_key (
2447+ address = ss58_address if ss58_address else public_key_hex
2448+ ):
2449+ rich .print ("[red]Error: Invalid SS58 address or public key![/red]" )
2450+ return False
2451+ return self ._run_command (
2452+ wallets .regen_hotkey_pub (
2453+ wallet , ss58_address , public_key_hex , overwrite , json_output
2454+ )
2455+ )
2456+
23862457 def wallet_new_hotkey (
23872458 self ,
23882459 wallet_name : Optional [str ] = Options .wallet_name ,
@@ -2502,7 +2573,7 @@ def wallet_associate_hotkey(
25022573 ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
25032574 validate = WV .WALLET_AND_HOTKEY ,
25042575 )
2505- hotkey_ss58 = wallet . hotkey . ss58_address
2576+ hotkey_ss58 = get_hotkey_pub_ss58 ( wallet )
25062577 hotkey_display = (
25072578 f"hotkey [blue]{ wallet_hotkey } [/blue] "
25082579 f"[{ COLORS .GENERAL .HK } ]({ hotkey_ss58 } )[/{ COLORS .GENERAL .HK } ]"
@@ -3518,7 +3589,7 @@ def stake_add(
35183589 ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
35193590 validate = WV .WALLET_AND_HOTKEY ,
35203591 )
3521- include_hotkeys = wallet . hotkey . ss58_address
3592+ include_hotkeys = get_hotkey_pub_ss58 ( wallet )
35223593
35233594 elif all_hotkeys or include_hotkeys or exclude_hotkeys :
35243595 wallet = self .wallet_ask (
@@ -3982,7 +4053,7 @@ def stake_move(
39824053 ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
39834054 validate = WV .WALLET_AND_HOTKEY ,
39844055 )
3985- destination_hotkey = destination_wallet . hotkey . ss58_address
4056+ destination_hotkey = get_hotkey_pub_ss58 ( destination_wallet )
39864057 else :
39874058 if is_valid_ss58_address (destination_hotkey ):
39884059 destination_hotkey = destination_hotkey
@@ -4021,7 +4092,7 @@ def stake_move(
40214092 ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
40224093 validate = WV .WALLET_AND_HOTKEY ,
40234094 )
4024- origin_hotkey = wallet . hotkey . ss58_address
4095+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
40254096 else :
40264097 if is_valid_ss58_address (wallet_hotkey ):
40274098 origin_hotkey = wallet_hotkey
@@ -4033,7 +4104,7 @@ def stake_move(
40334104 ask_for = [],
40344105 validate = WV .WALLET_AND_HOTKEY ,
40354106 )
4036- origin_hotkey = wallet . hotkey . ss58_address
4107+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
40374108
40384109 if not interactive_selection :
40394110 if origin_netuid is None :
@@ -4186,7 +4257,7 @@ def stake_transfer(
41864257 ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
41874258 validate = WV .WALLET_AND_HOTKEY ,
41884259 )
4189- origin_hotkey = wallet . hotkey . ss58_address
4260+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
41904261 else :
41914262 if is_valid_ss58_address (wallet_hotkey ):
41924263 origin_hotkey = wallet_hotkey
@@ -4198,7 +4269,7 @@ def stake_transfer(
41984269 ask_for = [],
41994270 validate = WV .WALLET_AND_HOTKEY ,
42004271 )
4201- origin_hotkey = wallet . hotkey . ss58_address
4272+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
42024273
42034274 if not interactive_selection :
42044275 if origin_netuid is None :
0 commit comments