Skip to content

Commit b0e07e4

Browse files
authored
btcli fixes (#41)
* Changed btwallet to https to avoid requiriing SSH keys * Fixed error in config that wouldn't load if a network was specified but not a chain * We were checking `if my_uid is None`, but my_uid is a ScaleType, and thus could never be None. Instead use `my_uid.value`, which will be None. Consistent with root slash * u16 normalise the take from delegates, fix setting archive node when a network is specified in config. Fix 0% when previous stake is 0 and current stake is also 0. * get-identity working correctly. * `set-identity` fixed.
1 parent 68db298 commit b0e07e4

File tree

6 files changed

+67
-30
lines changed

6 files changed

+67
-30
lines changed

bittensor_cli/cli.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def initialize_chain(
563563
if not self.not_subtensor:
564564
if network or chain:
565565
self.not_subtensor = SubtensorInterface(network, chain)
566-
elif self.config["chain"] or self.config["chain"]:
566+
elif self.config["network"] or self.config["chain"]:
567567
self.not_subtensor = SubtensorInterface(
568568
self.config["network"], self.config["chain"]
569569
)
@@ -1717,6 +1717,9 @@ def wallet_get_id(
17171717
[italic]Note[/italic]: This function is designed for CLI use and should be executed in a terminal.
17181718
It is primarily used for informational purposes and has no side effects on the network state.
17191719
"""
1720+
return self._run_command(
1721+
wallets.get_id(self.initialize_chain(network, chain), key)
1722+
)
17201723

17211724
def wallet_sign(
17221725
self,
@@ -2436,12 +2439,13 @@ def root_list_delegates(
24362439
[italic]Note[/italic]: This function is part of the Bittensor CLI tools and is intended for use within a
24372440
console application. It prints directly to the console and does not return any value.
24382441
"""
2439-
if network not in ["local", "test"]:
2442+
network_to_use = network or self.config["network"]
2443+
if network_to_use not in ["local", "test"]:
24402444
sub = self.initialize_chain(
24412445
"archive", "wss://archive.chain.opentensor.ai:443"
24422446
)
24432447
else:
2444-
sub = self.initialize_chain(network, chain)
2448+
sub = self.initialize_chain(network_to_use, chain)
24452449

24462450
return self._run_command(root.list_delegates(sub))
24472451

bittensor_cli/src/bittensor/chain_data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def from_vec_u8(cls, vec_u8: bytes) -> Optional["DelegateInfo"]:
461461
total_stake=total_stake,
462462
nominators=nominators,
463463
owner_ss58=owner,
464-
take=decoded.take,
464+
take=u16_normalized_float(decoded.take),
465465
validator_permits=decoded.validator_permits,
466466
registrations=decoded.registrations,
467467
return_per_1000=Balance.from_rao(decoded.return_per_1000),
@@ -485,7 +485,7 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["DelegateInfo"]:
485485
total_stake=total_stake,
486486
nominators=nominators,
487487
owner_ss58=owner,
488-
take=d.take,
488+
take=u16_normalized_float(d.take),
489489
validator_permits=d.validator_permits,
490490
registrations=d.registrations,
491491
return_per_1000=Balance.from_rao(d.return_per_1000),
@@ -510,7 +510,7 @@ def delegated_list_from_vec_u8(
510510
total_stake=total_stake,
511511
nominators=nominators,
512512
owner_ss58=decode_account_id(d.owner_ss58),
513-
take=d.take,
513+
take=u16_normalized_float(d.take),
514514
validator_permits=d.validator_permits,
515515
registrations=d.registrations,
516516
return_per_1000=Balance.from_rao(d.return_per_1000),

bittensor_cli/src/commands/root.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import json
3-
from typing import Optional, TypedDict, cast
3+
from typing import Optional, TypedDict
44

55
from bittensor_wallet import Wallet
66
import numpy as np
@@ -966,9 +966,12 @@ async def set_boost(
966966
):
967967
"""Boosts weight of a given netuid for root network."""
968968

969-
my_uid = await subtensor.substrate.query(
970-
"SubtensorModule", "Uids", [0, wallet.hotkey.ss58_address]
971-
)
969+
my_uid = (
970+
await subtensor.substrate.query(
971+
"SubtensorModule", "Uids", [0, wallet.hotkey.ss58_address]
972+
)
973+
).value
974+
972975
if my_uid is None:
973976
err_console.print("Your hotkey is not registered to the root network")
974977
return False
@@ -1003,7 +1006,7 @@ async def set_slash(
10031006
amount: float,
10041007
prompt: bool,
10051008
):
1006-
"""Slashes weight I think"""
1009+
"""Slashes weight"""
10071010

10081011
my_uid = (
10091012
await subtensor.substrate.query(
@@ -1565,7 +1568,10 @@ async def list_delegates(subtensor: SubtensorInterface):
15651568
if delegate.hotkey_ss58 in prev_delegates_dict:
15661569
prev_stake = prev_delegates_dict[delegate.hotkey_ss58].total_stake
15671570
if prev_stake == 0:
1568-
rate_change_in_stake_str = "[green]100%[/green]"
1571+
if delegate.total_stake > 0:
1572+
rate_change_in_stake_str = "[green]100%[/green]"
1573+
else:
1574+
rate_change_in_stake_str = "[grey0]0%[/grey0]"
15691575
else:
15701576
rate_change_in_stake = (
15711577
100

bittensor_cli/src/commands/wallets.py

+40-16
Original file line numberDiff line numberDiff line change
@@ -1400,30 +1400,47 @@ async def set_id(
14001400
):
14011401
"""Create a new or update existing identity on-chain."""
14021402

1403+
id_dict = {
1404+
"additional": [[]],
1405+
"display": display_name,
1406+
"legal": legal_name,
1407+
"web": web_url,
1408+
"pgp_fingerprint": pgp_fingerprint,
1409+
"riot": riot_handle,
1410+
"email": email,
1411+
"image": image,
1412+
"twitter": twitter,
1413+
"info": info_,
1414+
}
1415+
1416+
for field, string in id_dict.items():
1417+
if (size := getsizeof(string)) > 113: # 64 + 49 overhead bytes for string
1418+
err_console.print(
1419+
f"[red]Error:[/red] Identity field [white]{field}[/white] must be <= 64 raw bytes.\n"
1420+
f"Value: '{string}' currently [white]{size} bytes[/white]."
1421+
)
1422+
return False
1423+
14031424
identified = (
14041425
wallet.hotkey.ss58_address if validator_id else wallet.coldkey.ss58_address
14051426
)
1406-
id_dict = {
1427+
encoded_id_dict = {
14071428
"info": {
14081429
"additional": [[]],
1409-
"display": display_name,
1410-
"legal": legal_name,
1411-
"web": web_url,
1412-
"pgp_fingerprint": pgp_fingerprint,
1413-
"riot": riot_handle,
1414-
"email": email,
1415-
"image": image,
1416-
"twitter": twitter,
1417-
"info": info_,
1430+
"display": {f"Raw{len(display_name.encode())}": display_name.encode()},
1431+
"legal": {f"Raw{len(legal_name.encode())}": legal_name.encode()},
1432+
"web": {f"Raw{len(web_url.encode())}": web_url.encode()},
1433+
"riot": {f"Raw{len(riot_handle.encode())}": riot_handle.encode()},
1434+
"email": {f"Raw{len(email.encode())}": email.encode()},
1435+
"pgp_fingerprint": pgp_fingerprint.encode() if pgp_fingerprint else None,
1436+
"image": {f"Raw{len(image.encode())}": image.encode()},
1437+
"info": {f"Raw{len(info_.encode())}": info_.encode()},
1438+
"twitter": {f"Raw{len(twitter.encode())}": twitter.encode()},
14181439
},
14191440
"identified": identified,
14201441
}
14211442

1422-
for field, string in id_dict["info"].items():
1423-
if getsizeof(string) > 113: # 64 + 49 overhead bytes for string
1424-
raise ValueError(f"Identity value `{field}` must be <= 64 raw bytes")
1425-
1426-
if not Confirm(
1443+
if not Confirm.ask(
14271444
"Cost to register an Identity is [bold white italic]0.1 Tao[/bold white italic],"
14281445
" are you sure you wish to continue?"
14291446
):
@@ -1436,7 +1453,7 @@ async def set_id(
14361453
call = await subtensor.substrate.compose_call(
14371454
call_module="Registry",
14381455
call_function="set_identity",
1439-
call_params=id_dict,
1456+
call_params=encoded_id_dict,
14401457
)
14411458
success, err_msg = await subtensor.sign_and_send_extrinsic(call, wallet)
14421459

@@ -1466,6 +1483,13 @@ async def get_id(subtensor: SubtensorInterface, ss58_address: str):
14661483
with console.status(":satellite: [bold green]Querying chain identity..."):
14671484
identity = await subtensor.query_identity(ss58_address)
14681485

1486+
if not identity:
1487+
err_console.print(
1488+
f"[red]Identity not found[/red]"
1489+
f" for [light_goldenrod3]{ss58_address}[/light_goldenrod3]"
1490+
f" on [white]{subtensor}[/white]"
1491+
)
1492+
return
14691493
table = Table(
14701494
Column("Item", justify="right", style="cyan", no_wrap=True),
14711495
Column("Value", style="magenta"),

bittensor_cli/src/subtensor_interface.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,10 @@ def decode_hex_identity_dict(info_dictionary):
715715
block_hash=block_hash,
716716
reuse_block_hash=reuse_block,
717717
)
718-
return decode_hex_identity_dict(identity_info.value["info"])
718+
try:
719+
return decode_hex_identity_dict(identity_info.value["info"])
720+
except TypeError:
721+
return {}
719722

720723
async def weights(
721724
self, netuid: int, block_hash: Optional[str] = None

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ scalecodec==1.2.11
1515
substrate-interface~=1.7.9
1616
typer~=0.12
1717
websockets>=12.0
18-
git+ssh://git@github.com/opentensor/btwallet.git@main#egg=bittensor-wallet
18+
git+https://github.com/opentensor/btwallet.git#egg=bittensor-wallet
1919
bt-decode

0 commit comments

Comments
 (0)