Skip to content

Commit aa70fb3

Browse files
committed
Update some commands.
1 parent 714cafb commit aa70fb3

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

bittensor_cli/src/commands/sudo.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
json_console,
2727
string_to_u16,
2828
string_to_u64,
29+
get_hotkey_pub_ss58,
2930
)
3031

3132
if TYPE_CHECKING:
@@ -497,7 +498,7 @@ async def vote_senate_extrinsic(
497498
call_module="SubtensorModule",
498499
call_function="vote",
499500
call_params={
500-
"hotkey": wallet.hotkey.ss58_address,
501+
"hotkey": get_hotkey_pub_ss58(wallet),
501502
"proposal": proposal_hash,
502503
"index": proposal_idx,
503504
"approve": vote,
@@ -513,9 +514,10 @@ async def vote_senate_extrinsic(
513514
# Successful vote, final check for data
514515
else:
515516
if vote_data := await subtensor.get_vote_data(proposal_hash):
517+
hotkey_ss58 = get_hotkey_pub_ss58(wallet)
516518
if (
517-
vote_data.ayes.count(wallet.hotkey.ss58_address) > 0
518-
or vote_data.nays.count(wallet.hotkey.ss58_address) > 0
519+
vote_data.ayes.count(hotkey_ss58) > 0
520+
or vote_data.nays.count(hotkey_ss58) > 0
519521
):
520522
console.print(":white_heavy_check_mark: [green]Vote cast.[/green]")
521523
return True
@@ -859,10 +861,9 @@ async def senate_vote(
859861
return False
860862

861863
print_verbose(f"Fetching senate status of {wallet.hotkey_str}")
862-
if not await _is_senate_member(subtensor, hotkey_ss58=wallet.hotkey.ss58_address):
863-
err_console.print(
864-
f"Aborting: Hotkey {wallet.hotkey.ss58_address} isn't a senate member."
865-
)
864+
hotkey_ss58 = get_hotkey_pub_ss58(wallet)
865+
if not await _is_senate_member(subtensor, hotkey_ss58=hotkey_ss58):
866+
err_console.print(f"Aborting: Hotkey {hotkey_ss58} isn't a senate member.")
866867
return False
867868

868869
# Unlock the wallet.
@@ -890,7 +891,7 @@ async def senate_vote(
890891

891892

892893
async def get_current_take(subtensor: "SubtensorInterface", wallet: Wallet):
893-
current_take = await subtensor.current_take(wallet.hotkey.ss58_address)
894+
current_take = await subtensor.current_take(get_hotkey_pub_ss58(wallet))
894895
return current_take
895896

896897

@@ -912,12 +913,13 @@ async def _do_set_take() -> bool:
912913
return False
913914

914915
block_hash = await subtensor.substrate.get_chain_head()
916+
hotkey_ss58 = get_hotkey_pub_ss58(wallet)
915917
netuids_registered = await subtensor.get_netuids_for_hotkey(
916-
wallet.hotkey.ss58_address, block_hash=block_hash
918+
hotkey_ss58, block_hash=block_hash
917919
)
918920
if not len(netuids_registered) > 0:
919921
err_console.print(
920-
f"Hotkey [{COLOR_PALETTE.G.HK}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE.G.HK}] is not registered to"
922+
f"Hotkey [{COLOR_PALETTE.G.HK}]{hotkey_ss58}[/{COLOR_PALETTE.G.HK}] is not registered to"
921923
f" any subnet. Please register using [{COLOR_PALETTE.G.SUBHEAD}]`btcli subnets register`"
922924
f"[{COLOR_PALETTE.G.SUBHEAD}] and try again."
923925
)
@@ -926,7 +928,7 @@ async def _do_set_take() -> bool:
926928
result: bool = await set_take_extrinsic(
927929
subtensor=subtensor,
928930
wallet=wallet,
929-
delegate_ss58=wallet.hotkey.ss58_address,
931+
delegate_ss58=hotkey_ss58,
930932
take=take,
931933
)
932934

bittensor_cli/src/commands/wallets.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55
from collections import defaultdict
6-
from typing import Generator, Optional
6+
from typing import Generator, Optional, Union
77

88
import aiohttp
99
from bittensor_wallet import Wallet, Keypair
@@ -48,6 +48,7 @@
4848
WalletLike,
4949
blocks_to_duration,
5050
decode_account_id,
51+
get_hotkey_pub_ss58,
5152
)
5253

5354

@@ -159,7 +160,7 @@ async def regen_coldkey(
159160
"name": new_wallet.name,
160161
"path": new_wallet.path,
161162
"hotkey": new_wallet.hotkey_str,
162-
"hotkey_ss58": new_wallet.hotkey.ss58_address,
163+
"hotkey_ss58": get_hotkey_pub_ss58(new_wallet),
163164
"coldkey_ss58": new_wallet.coldkeypub.ss58_address,
164165
},
165166
"error": "",
@@ -209,7 +210,7 @@ async def regen_coldkey_pub(
209210
"name": new_coldkeypub.name,
210211
"path": new_coldkeypub.path,
211212
"hotkey": new_coldkeypub.hotkey_str,
212-
"hotkey_ss58": new_coldkeypub.hotkey.ss58_address,
213+
"hotkey_ss58": get_hotkey_pub_ss58(new_coldkeypub),
213214
"coldkey_ss58": new_coldkeypub.coldkeypub.ss58_address,
214215
},
215216
"error": "",
@@ -255,7 +256,7 @@ async def regen_hotkey(
255256
console.print(
256257
"\n✅ [dark_sea_green]Regenerated hotkey successfully!\n",
257258
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})",
259260
)
260261
if json_output:
261262
json_console.print(
@@ -266,7 +267,7 @@ async def regen_hotkey(
266267
"name": new_hotkey_.name,
267268
"path": new_hotkey_.path,
268269
"hotkey": new_hotkey_.hotkey_str,
269-
"hotkey_ss58": new_hotkey_.hotkey.ss58_address,
270+
"hotkey_ss58": new_hotkey_.hotkeypub.ss58_address,
270271
"coldkey_ss58": new_hotkey_.coldkeypub.ss58_address,
271272
},
272273
"error": "",
@@ -316,7 +317,7 @@ async def regen_hotkey_pub(
316317
"name": new_hotkeypub.name,
317318
"path": new_hotkeypub.path,
318319
"hotkey": new_hotkeypub.hotkey_str,
319-
"hotkey_ss58": new_hotkeypub.hotkey.ss58_address,
320+
"hotkey_ss58": new_hotkeypub.hotkeypub.ss58_address,
320321
"coldkey_ss58": new_hotkeypub.coldkeypub.ss58_address,
321322
},
322323
"error": "",
@@ -367,7 +368,7 @@ async def new_hotkey(
367368
"name": wallet.name,
368369
"path": wallet.path,
369370
"hotkey": wallet.hotkey_str,
370-
"hotkey_ss58": wallet.hotkey.ss58_address,
371+
"hotkey_ss58": get_hotkey_pub_ss58(wallet),
371372
"coldkey_ss58": wallet.coldkeypub.ss58_address,
372373
},
373374
"error": "",
@@ -446,19 +447,24 @@ async def wallet_create(
446447
json_output: bool = False,
447448
):
448449
"""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+
}
450455
if uri:
451456
try:
452457
keypair = Keypair.create_from_uri(uri)
453458
wallet.set_coldkey(keypair=keypair, encrypt=False, overwrite=False)
454459
wallet.set_coldkeypub(keypair=keypair, encrypt=False, overwrite=False)
455460
wallet.set_hotkey(keypair=keypair, encrypt=False, overwrite=False)
461+
wallet.set_coldkeypub(keypair=keypair, encrypt=False, overwrite=False)
456462
output_dict["success"] = True
457463
output_dict["data"] = {
458464
"name": wallet.name,
459465
"path": wallet.path,
460466
"hotkey": wallet.hotkey_str,
461-
"hotkey_ss58": wallet.hotkey.ss58_address,
467+
"hotkey_ss58": wallet.hotkeypub.ss58_address,
462468
"coldkey_ss58": wallet.coldkeypub.ss58_address,
463469
}
464470
except Exception as e:
@@ -499,7 +505,7 @@ async def wallet_create(
499505
"name": wallet.name,
500506
"path": wallet.path,
501507
"hotkey": wallet.hotkey_str,
502-
"hotkey_ss58": wallet.hotkey.ss58_address,
508+
"hotkey_ss58": wallet.hotkeypub.ss58_address,
503509
}
504510
except KeyFileError as error:
505511
err = str(error)
@@ -838,13 +844,14 @@ async def wallet_list(wallet_path: str, json_output: bool):
838844
data = f"[bold red]Hotkey[/bold red][green] {hkey}[/green] (?)"
839845
hk_data = {"name": hkey.name, "ss58_address": "?"}
840846
if hkey:
847+
hkey_ss58 = get_hotkey_pub_ss58(hkey)
841848
try:
842849
data = (
843850
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"
845852
)
846853
hk_data["name"] = hkey.hotkey_str
847-
hk_data["ss58_address"] = hkey.hotkey.ss58_address
854+
hk_data["ss58_address"] = hkey_ss58
848855
except UnicodeDecodeError:
849856
pass
850857
wallet_tree.add(data)
@@ -1297,7 +1304,7 @@ def _get_hotkeys(
12971304

12981305
def is_hotkey_matched(wallet: Wallet, item: str) -> bool:
12991306
if is_valid_ss58_address(item):
1300-
return wallet.hotkey.ss58_address == item
1307+
return get_hotkey_pub_ss58(wallet) == item
13011308
else:
13021309
return wallet.hotkey_str == item
13031310

@@ -1329,9 +1336,10 @@ def _get_key_address(all_hotkeys: list[Wallet]) -> tuple[list[str], dict[str, Wa
13291336
hotkey_coldkey_to_hotkey_wallet = {}
13301337
for hotkey_wallet in all_hotkeys:
13311338
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][
13351343
hotkey_wallet.coldkeypub.ss58_address
13361344
] = hotkey_wallet
13371345
else:
@@ -1515,7 +1523,7 @@ def neuron_row_maker(
15151523
if hotkey_names := [
15161524
w.hotkey_str
15171525
for w in hotkeys
1518-
if w.hotkey.ss58_address == n.hotkey
1526+
if get_hotkey_pub_ss58(w) == n.hotkey
15191527
]:
15201528
hotkey_name = f"{hotkey_names[0]}-"
15211529
yield [""] * 5 + [

0 commit comments

Comments
 (0)