58
58
validate_uri ,
59
59
prompt_for_subnet_identity ,
60
60
validate_rate_tolerance ,
61
+ get_hotkey_pub_ss58 ,
61
62
)
62
63
from bittensor_cli .src .commands import sudo , wallets , view
63
64
from bittensor_cli .src .commands import weights as weights_cmds
@@ -791,6 +792,9 @@ def __init__(self):
791
792
self .wallet_app .command (
792
793
"regen-hotkey" , rich_help_panel = HELP_PANELS ["WALLET" ]["SECURITY" ]
793
794
)(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 )
794
798
self .wallet_app .command (
795
799
"new-hotkey" , rich_help_panel = HELP_PANELS ["WALLET" ]["MANAGEMENT" ]
796
800
)(self .wallet_new_hotkey )
@@ -973,6 +977,10 @@ def __init__(self):
973
977
"regen_hotkey" ,
974
978
hidden = True ,
975
979
)(self .wallet_regen_hotkey )
980
+ self .wallet_app .command (
981
+ "regen_hotkeypub" ,
982
+ hidden = True ,
983
+ )(self .wallet_regen_hotkey_pub )
976
984
self .wallet_app .command (
977
985
"new_hotkey" ,
978
986
hidden = True ,
@@ -1143,7 +1151,8 @@ async def _run():
1143
1151
exit_early is True
1144
1152
): # temporarily to handle multiple run commands in one session
1145
1153
try :
1146
- await self .subtensor .substrate .close ()
1154
+ if self .subtensor :
1155
+ await self .subtensor .substrate .close ()
1147
1156
raise typer .Exit ()
1148
1157
except Exception as e : # ensures we always exit cleanly
1149
1158
if not isinstance (e , (typer .Exit , RuntimeError )):
@@ -1726,7 +1735,7 @@ def wallet_ask(
1726
1735
if return_wallet_and_hotkey :
1727
1736
valid = utils .is_valid_wallet (wallet )
1728
1737
if valid [1 ]:
1729
- return wallet , wallet . hotkey . ss58_address
1738
+ return wallet , get_hotkey_pub_ss58 ( wallet )
1730
1739
else :
1731
1740
if wallet_hotkey and is_valid_ss58_address (wallet_hotkey ):
1732
1741
return wallet , wallet_hotkey
@@ -2285,7 +2294,7 @@ def wallet_regen_coldkey_pub(
2285
2294
2286
2295
EXAMPLE
2287
2296
2288
- [green]$[/green] btcli wallet regen_coldkeypub --ss58_address 5DkQ4...
2297
+ [green]$[/green] btcli wallet regen-coldkeypub --ss58_address 5DkQ4...
2289
2298
2290
2299
[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.
2291
2300
"""
@@ -2300,7 +2309,7 @@ def wallet_regen_coldkey_pub(
2300
2309
2301
2310
if not wallet_name :
2302
2311
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 " ,
2304
2313
default = defaults .wallet .name ,
2305
2314
)
2306
2315
wallet = Wallet (wallet_name , wallet_hotkey , wallet_path )
@@ -2317,7 +2326,7 @@ def wallet_regen_coldkey_pub(
2317
2326
address = ss58_address if ss58_address else public_key_hex
2318
2327
):
2319
2328
rich .print ("[red]Error: Invalid SS58 address or public key![/red]" )
2320
- raise typer . Exit ()
2329
+ return
2321
2330
return self ._run_command (
2322
2331
wallets .regen_coldkey_pub (
2323
2332
wallet , ss58_address , public_key_hex , overwrite , json_output
@@ -2383,6 +2392,68 @@ def wallet_regen_hotkey(
2383
2392
)
2384
2393
)
2385
2394
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
+
2386
2457
def wallet_new_hotkey (
2387
2458
self ,
2388
2459
wallet_name : Optional [str ] = Options .wallet_name ,
@@ -2502,7 +2573,7 @@ def wallet_associate_hotkey(
2502
2573
ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
2503
2574
validate = WV .WALLET_AND_HOTKEY ,
2504
2575
)
2505
- hotkey_ss58 = wallet . hotkey . ss58_address
2576
+ hotkey_ss58 = get_hotkey_pub_ss58 ( wallet )
2506
2577
hotkey_display = (
2507
2578
f"hotkey [blue]{ wallet_hotkey } [/blue] "
2508
2579
f"[{ COLORS .GENERAL .HK } ]({ hotkey_ss58 } )[/{ COLORS .GENERAL .HK } ]"
@@ -3518,7 +3589,7 @@ def stake_add(
3518
3589
ask_for = [WO .NAME , WO .HOTKEY , WO .PATH ],
3519
3590
validate = WV .WALLET_AND_HOTKEY ,
3520
3591
)
3521
- include_hotkeys = wallet . hotkey . ss58_address
3592
+ include_hotkeys = get_hotkey_pub_ss58 ( wallet )
3522
3593
3523
3594
elif all_hotkeys or include_hotkeys or exclude_hotkeys :
3524
3595
wallet = self .wallet_ask (
@@ -3982,7 +4053,7 @@ def stake_move(
3982
4053
ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
3983
4054
validate = WV .WALLET_AND_HOTKEY ,
3984
4055
)
3985
- destination_hotkey = destination_wallet . hotkey . ss58_address
4056
+ destination_hotkey = get_hotkey_pub_ss58 ( destination_wallet )
3986
4057
else :
3987
4058
if is_valid_ss58_address (destination_hotkey ):
3988
4059
destination_hotkey = destination_hotkey
@@ -4021,7 +4092,7 @@ def stake_move(
4021
4092
ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
4022
4093
validate = WV .WALLET_AND_HOTKEY ,
4023
4094
)
4024
- origin_hotkey = wallet . hotkey . ss58_address
4095
+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
4025
4096
else :
4026
4097
if is_valid_ss58_address (wallet_hotkey ):
4027
4098
origin_hotkey = wallet_hotkey
@@ -4033,7 +4104,7 @@ def stake_move(
4033
4104
ask_for = [],
4034
4105
validate = WV .WALLET_AND_HOTKEY ,
4035
4106
)
4036
- origin_hotkey = wallet . hotkey . ss58_address
4107
+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
4037
4108
4038
4109
if not interactive_selection :
4039
4110
if origin_netuid is None :
@@ -4186,7 +4257,7 @@ def stake_transfer(
4186
4257
ask_for = [WO .NAME , WO .PATH , WO .HOTKEY ],
4187
4258
validate = WV .WALLET_AND_HOTKEY ,
4188
4259
)
4189
- origin_hotkey = wallet . hotkey . ss58_address
4260
+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
4190
4261
else :
4191
4262
if is_valid_ss58_address (wallet_hotkey ):
4192
4263
origin_hotkey = wallet_hotkey
@@ -4198,7 +4269,7 @@ def stake_transfer(
4198
4269
ask_for = [],
4199
4270
validate = WV .WALLET_AND_HOTKEY ,
4200
4271
)
4201
- origin_hotkey = wallet . hotkey . ss58_address
4272
+ origin_hotkey = get_hotkey_pub_ss58 ( wallet )
4202
4273
4203
4274
if not interactive_selection :
4204
4275
if origin_netuid is None :
0 commit comments