3
3
import json
4
4
import os
5
5
from collections import defaultdict
6
- from typing import Generator , Optional
6
+ from typing import Generator , Optional , Union
7
7
8
8
import aiohttp
9
9
from bittensor_wallet import Wallet , Keypair
48
48
WalletLike ,
49
49
blocks_to_duration ,
50
50
decode_account_id ,
51
+ get_hotkey_pub_ss58 ,
51
52
)
52
53
53
54
@@ -159,7 +160,7 @@ async def regen_coldkey(
159
160
"name" : new_wallet .name ,
160
161
"path" : new_wallet .path ,
161
162
"hotkey" : new_wallet .hotkey_str ,
162
- "hotkey_ss58" : new_wallet . hotkey . ss58_address ,
163
+ "hotkey_ss58" : get_hotkey_pub_ss58 ( new_wallet ) ,
163
164
"coldkey_ss58" : new_wallet .coldkeypub .ss58_address ,
164
165
},
165
166
"error" : "" ,
@@ -209,7 +210,7 @@ async def regen_coldkey_pub(
209
210
"name" : new_coldkeypub .name ,
210
211
"path" : new_coldkeypub .path ,
211
212
"hotkey" : new_coldkeypub .hotkey_str ,
212
- "hotkey_ss58" : new_coldkeypub . hotkey . ss58_address ,
213
+ "hotkey_ss58" : get_hotkey_pub_ss58 ( new_coldkeypub ) ,
213
214
"coldkey_ss58" : new_coldkeypub .coldkeypub .ss58_address ,
214
215
},
215
216
"error" : "" ,
@@ -255,7 +256,7 @@ async def regen_hotkey(
255
256
console .print (
256
257
"\n ✅ [dark_sea_green]Regenerated hotkey successfully!\n " ,
257
258
f"[dark_sea_green]Wallet name: ({ new_hotkey_ .name } ), path: ({ new_hotkey_ .path } ), "
258
- f"hotkey ss58: ({ new_hotkey_ .hotkey .ss58_address } )" ,
259
+ f"hotkey ss58: ({ new_hotkey_ .hotkeypub .ss58_address } )" ,
259
260
)
260
261
if json_output :
261
262
json_console .print (
@@ -266,7 +267,7 @@ async def regen_hotkey(
266
267
"name" : new_hotkey_ .name ,
267
268
"path" : new_hotkey_ .path ,
268
269
"hotkey" : new_hotkey_ .hotkey_str ,
269
- "hotkey_ss58" : new_hotkey_ .hotkey .ss58_address ,
270
+ "hotkey_ss58" : new_hotkey_ .hotkeypub .ss58_address ,
270
271
"coldkey_ss58" : new_hotkey_ .coldkeypub .ss58_address ,
271
272
},
272
273
"error" : "" ,
@@ -316,7 +317,7 @@ async def regen_hotkey_pub(
316
317
"name" : new_hotkeypub .name ,
317
318
"path" : new_hotkeypub .path ,
318
319
"hotkey" : new_hotkeypub .hotkey_str ,
319
- "hotkey_ss58" : new_hotkeypub .hotkey .ss58_address ,
320
+ "hotkey_ss58" : new_hotkeypub .hotkeypub .ss58_address ,
320
321
"coldkey_ss58" : new_hotkeypub .coldkeypub .ss58_address ,
321
322
},
322
323
"error" : "" ,
@@ -367,7 +368,7 @@ async def new_hotkey(
367
368
"name" : wallet .name ,
368
369
"path" : wallet .path ,
369
370
"hotkey" : wallet .hotkey_str ,
370
- "hotkey_ss58" : wallet . hotkey . ss58_address ,
371
+ "hotkey_ss58" : get_hotkey_pub_ss58 ( wallet ) ,
371
372
"coldkey_ss58" : wallet .coldkeypub .ss58_address ,
372
373
},
373
374
"error" : "" ,
@@ -446,19 +447,24 @@ async def wallet_create(
446
447
json_output : bool = False ,
447
448
):
448
449
"""Creates a new wallet."""
449
- output_dict = {"success" : False , "error" : "" , "data" : None }
450
+ output_dict : dict [str , Optional [Union [bool , str , dict ]]] = {
451
+ "success" : False ,
452
+ "error" : "" ,
453
+ "data" : None ,
454
+ }
450
455
if uri :
451
456
try :
452
457
keypair = Keypair .create_from_uri (uri )
453
458
wallet .set_coldkey (keypair = keypair , encrypt = False , overwrite = False )
454
459
wallet .set_coldkeypub (keypair = keypair , encrypt = False , overwrite = False )
455
460
wallet .set_hotkey (keypair = keypair , encrypt = False , overwrite = False )
461
+ wallet .set_coldkeypub (keypair = keypair , encrypt = False , overwrite = False )
456
462
output_dict ["success" ] = True
457
463
output_dict ["data" ] = {
458
464
"name" : wallet .name ,
459
465
"path" : wallet .path ,
460
466
"hotkey" : wallet .hotkey_str ,
461
- "hotkey_ss58" : wallet .hotkey .ss58_address ,
467
+ "hotkey_ss58" : wallet .hotkeypub .ss58_address ,
462
468
"coldkey_ss58" : wallet .coldkeypub .ss58_address ,
463
469
}
464
470
except Exception as e :
@@ -499,7 +505,7 @@ async def wallet_create(
499
505
"name" : wallet .name ,
500
506
"path" : wallet .path ,
501
507
"hotkey" : wallet .hotkey_str ,
502
- "hotkey_ss58" : wallet .hotkey .ss58_address ,
508
+ "hotkey_ss58" : wallet .hotkeypub .ss58_address ,
503
509
}
504
510
except KeyFileError as error :
505
511
err = str (error )
@@ -838,13 +844,14 @@ async def wallet_list(wallet_path: str, json_output: bool):
838
844
data = f"[bold red]Hotkey[/bold red][green] { hkey } [/green] (?)"
839
845
hk_data = {"name" : hkey .name , "ss58_address" : "?" }
840
846
if hkey :
847
+ hkey_ss58 = get_hotkey_pub_ss58 (hkey )
841
848
try :
842
849
data = (
843
850
f"[bold red]Hotkey[/bold red] [green]{ hkey .hotkey_str } [/green] "
844
- f"ss58_address [green]{ hkey . hotkey . ss58_address } [/green]\n "
851
+ f"ss58_address [green]{ hkey_ss58 } [/green]\n "
845
852
)
846
853
hk_data ["name" ] = hkey .hotkey_str
847
- hk_data ["ss58_address" ] = hkey . hotkey . ss58_address
854
+ hk_data ["ss58_address" ] = hkey_ss58
848
855
except UnicodeDecodeError :
849
856
pass
850
857
wallet_tree .add (data )
@@ -1297,7 +1304,7 @@ def _get_hotkeys(
1297
1304
1298
1305
def is_hotkey_matched (wallet : Wallet , item : str ) -> bool :
1299
1306
if is_valid_ss58_address (item ):
1300
- return wallet . hotkey . ss58_address == item
1307
+ return get_hotkey_pub_ss58 ( wallet ) == item
1301
1308
else :
1302
1309
return wallet .hotkey_str == item
1303
1310
@@ -1329,9 +1336,10 @@ def _get_key_address(all_hotkeys: list[Wallet]) -> tuple[list[str], dict[str, Wa
1329
1336
hotkey_coldkey_to_hotkey_wallet = {}
1330
1337
for hotkey_wallet in all_hotkeys :
1331
1338
if hotkey_wallet .coldkeypub :
1332
- if hotkey_wallet .hotkey .ss58_address not in hotkey_coldkey_to_hotkey_wallet :
1333
- hotkey_coldkey_to_hotkey_wallet [hotkey_wallet .hotkey .ss58_address ] = {}
1334
- hotkey_coldkey_to_hotkey_wallet [hotkey_wallet .hotkey .ss58_address ][
1339
+ hotkey_ss58 = get_hotkey_pub_ss58 (hotkey_wallet )
1340
+ if hotkey_ss58 not in hotkey_coldkey_to_hotkey_wallet :
1341
+ hotkey_coldkey_to_hotkey_wallet [hotkey_ss58 ] = {}
1342
+ hotkey_coldkey_to_hotkey_wallet [hotkey_ss58 ][
1335
1343
hotkey_wallet .coldkeypub .ss58_address
1336
1344
] = hotkey_wallet
1337
1345
else :
@@ -1515,7 +1523,7 @@ def neuron_row_maker(
1515
1523
if hotkey_names := [
1516
1524
w .hotkey_str
1517
1525
for w in hotkeys
1518
- if w . hotkey . ss58_address == n .hotkey
1526
+ if get_hotkey_pub_ss58 ( w ) == n .hotkey
1519
1527
]:
1520
1528
hotkey_name = f"{ hotkey_names [0 ]} -"
1521
1529
yield ["" ] * 5 + [
0 commit comments