Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btcli fixes #41

Merged
merged 6 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def initialize_chain(
if not self.not_subtensor:
if network or chain:
self.not_subtensor = SubtensorInterface(network, chain)
elif self.config["chain"] or self.config["chain"]:
elif self.config["network"] or self.config["chain"]:
self.not_subtensor = SubtensorInterface(
self.config["network"], self.config["chain"]
)
Expand Down Expand Up @@ -1717,6 +1717,9 @@ def wallet_get_id(
[italic]Note[/italic]: This function is designed for CLI use and should be executed in a terminal.
It is primarily used for informational purposes and has no side effects on the network state.
"""
return self._run_command(
wallets.get_id(self.initialize_chain(network, chain), key)
)

def wallet_sign(
self,
Expand Down Expand Up @@ -2436,12 +2439,13 @@ def root_list_delegates(
[italic]Note[/italic]: This function is part of the Bittensor CLI tools and is intended for use within a
console application. It prints directly to the console and does not return any value.
"""
if network not in ["local", "test"]:
network_to_use = network or self.config["network"]
if network_to_use not in ["local", "test"]:
sub = self.initialize_chain(
"archive", "wss://archive.chain.opentensor.ai:443"
)
else:
sub = self.initialize_chain(network, chain)
sub = self.initialize_chain(network_to_use, chain)

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

Expand Down
6 changes: 3 additions & 3 deletions bittensor_cli/src/bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def from_vec_u8(cls, vec_u8: bytes) -> Optional["DelegateInfo"]:
total_stake=total_stake,
nominators=nominators,
owner_ss58=owner,
take=decoded.take,
take=u16_normalized_float(decoded.take),
validator_permits=decoded.validator_permits,
registrations=decoded.registrations,
return_per_1000=Balance.from_rao(decoded.return_per_1000),
Expand All @@ -485,7 +485,7 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["DelegateInfo"]:
total_stake=total_stake,
nominators=nominators,
owner_ss58=owner,
take=d.take,
take=u16_normalized_float(d.take),
validator_permits=d.validator_permits,
registrations=d.registrations,
return_per_1000=Balance.from_rao(d.return_per_1000),
Expand All @@ -510,7 +510,7 @@ def delegated_list_from_vec_u8(
total_stake=total_stake,
nominators=nominators,
owner_ss58=decode_account_id(d.owner_ss58),
take=d.take,
take=u16_normalized_float(d.take),
validator_permits=d.validator_permits,
registrations=d.registrations,
return_per_1000=Balance.from_rao(d.return_per_1000),
Expand Down
18 changes: 12 additions & 6 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import json
from typing import Optional, TypedDict, cast
from typing import Optional, TypedDict

from bittensor_wallet import Wallet
import numpy as np
Expand Down Expand Up @@ -966,9 +966,12 @@ async def set_boost(
):
"""Boosts weight of a given netuid for root network."""

my_uid = await subtensor.substrate.query(
"SubtensorModule", "Uids", [0, wallet.hotkey.ss58_address]
)
my_uid = (
await subtensor.substrate.query(
"SubtensorModule", "Uids", [0, wallet.hotkey.ss58_address]
)
).value

if my_uid is None:
err_console.print("Your hotkey is not registered to the root network")
return False
Expand Down Expand Up @@ -1003,7 +1006,7 @@ async def set_slash(
amount: float,
prompt: bool,
):
"""Slashes weight I think"""
"""Slashes weight"""

my_uid = (
await subtensor.substrate.query(
Expand Down Expand Up @@ -1565,7 +1568,10 @@ async def list_delegates(subtensor: SubtensorInterface):
if delegate.hotkey_ss58 in prev_delegates_dict:
prev_stake = prev_delegates_dict[delegate.hotkey_ss58].total_stake
if prev_stake == 0:
rate_change_in_stake_str = "[green]100%[/green]"
if delegate.total_stake > 0:
rate_change_in_stake_str = "[green]100%[/green]"
else:
rate_change_in_stake_str = "[grey0]0%[/grey0]"
else:
rate_change_in_stake = (
100
Expand Down
56 changes: 40 additions & 16 deletions bittensor_cli/src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,30 +1400,47 @@ async def set_id(
):
"""Create a new or update existing identity on-chain."""

id_dict = {
"additional": [[]],
"display": display_name,
"legal": legal_name,
"web": web_url,
"pgp_fingerprint": pgp_fingerprint,
"riot": riot_handle,
"email": email,
"image": image,
"twitter": twitter,
"info": info_,
}

for field, string in id_dict.items():
if (size := getsizeof(string)) > 113: # 64 + 49 overhead bytes for string
err_console.print(
f"[red]Error:[/red] Identity field [white]{field}[/white] must be <= 64 raw bytes.\n"
f"Value: '{string}' currently [white]{size} bytes[/white]."
)
return False

identified = (
wallet.hotkey.ss58_address if validator_id else wallet.coldkey.ss58_address
)
id_dict = {
encoded_id_dict = {
"info": {
"additional": [[]],
"display": display_name,
"legal": legal_name,
"web": web_url,
"pgp_fingerprint": pgp_fingerprint,
"riot": riot_handle,
"email": email,
"image": image,
"twitter": twitter,
"info": info_,
"display": {f"Raw{len(display_name.encode())}": display_name.encode()},
"legal": {f"Raw{len(legal_name.encode())}": legal_name.encode()},
"web": {f"Raw{len(web_url.encode())}": web_url.encode()},
"riot": {f"Raw{len(riot_handle.encode())}": riot_handle.encode()},
"email": {f"Raw{len(email.encode())}": email.encode()},
"pgp_fingerprint": pgp_fingerprint.encode() if pgp_fingerprint else None,
"image": {f"Raw{len(image.encode())}": image.encode()},
"info": {f"Raw{len(info_.encode())}": info_.encode()},
"twitter": {f"Raw{len(twitter.encode())}": twitter.encode()},
},
"identified": identified,
}

for field, string in id_dict["info"].items():
if getsizeof(string) > 113: # 64 + 49 overhead bytes for string
raise ValueError(f"Identity value `{field}` must be <= 64 raw bytes")

if not Confirm(
if not Confirm.ask(
"Cost to register an Identity is [bold white italic]0.1 Tao[/bold white italic],"
" are you sure you wish to continue?"
):
Expand All @@ -1436,7 +1453,7 @@ async def set_id(
call = await subtensor.substrate.compose_call(
call_module="Registry",
call_function="set_identity",
call_params=id_dict,
call_params=encoded_id_dict,
)
success, err_msg = await subtensor.sign_and_send_extrinsic(call, wallet)

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

if not identity:
err_console.print(
f"[red]Identity not found[/red]"
f" for [light_goldenrod3]{ss58_address}[/light_goldenrod3]"
f" on [white]{subtensor}[/white]"
)
return
table = Table(
Column("Item", justify="right", style="cyan", no_wrap=True),
Column("Value", style="magenta"),
Expand Down
5 changes: 4 additions & 1 deletion bittensor_cli/src/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,10 @@ def decode_hex_identity_dict(info_dictionary):
block_hash=block_hash,
reuse_block_hash=reuse_block,
)
return decode_hex_identity_dict(identity_info.value["info"])
try:
return decode_hex_identity_dict(identity_info.value["info"])
except TypeError:
return {}

async def weights(
self, netuid: int, block_hash: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ scalecodec==1.2.11
substrate-interface~=1.7.9
typer~=0.12
websockets>=12.0
git+ssh://git@github.com/opentensor/btwallet.git@main#egg=bittensor-wallet
git+https://github.com/opentensor/btwallet.git#egg=bittensor-wallet
bt-decode
Loading