Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
34328ad
Compatibility init
thewhaleking Apr 2, 2026
a34def9
More stripping
thewhaleking Apr 2, 2026
f5ed67b
More stripping
thewhaleking Apr 2, 2026
15448af
No longer needed to extract bytes to hex
thewhaleking Apr 7, 2026
9e8e8a4
Merge branch 'staging' into feat/thewhaleking/cyscale
thewhaleking Apr 7, 2026
a5e62a5
No longer needed to decode account id
thewhaleking Apr 7, 2026
7fc6afc
No need to decode from bytes
thewhaleking Apr 7, 2026
b71067e
Decoding
thewhaleking Apr 7, 2026
7a74276
Check-in
thewhaleking Apr 7, 2026
3597358
Remove `decode_account_id` fn
thewhaleking Apr 8, 2026
b742762
Fixed tests and issues with child key setting.
thewhaleking Apr 8, 2026
92cce61
Bump cyscale
thewhaleking Apr 8, 2026
5d0e609
Fix setting to None
thewhaleking Apr 8, 2026
d666721
Pin to release branch of ASI
thewhaleking Apr 10, 2026
ff44f8f
Update for new query_map and query return types
thewhaleking Apr 10, 2026
c5aaafe
Fixes
thewhaleking Apr 13, 2026
aa12bcf
Bump cyscale
thewhaleking Apr 13, 2026
6726689
Raise ValueError instead of implicitly returning None. Ensure we use …
thewhaleking Apr 13, 2026
42a77be
Remove reuse_block
thewhaleking Apr 13, 2026
d17ef49
Import cleanup and added TODOs
thewhaleking Apr 14, 2026
08a0186
Import cleanup
thewhaleking Apr 14, 2026
697e7c7
Add TODO
thewhaleking Apr 14, 2026
c4f6440
Merge branch 'staging' into feat/thewhaleking/cyscale
thewhaleking Apr 14, 2026
171b004
Debugging
thewhaleking Apr 14, 2026
82fdb23
Bump cyscale
thewhaleking Apr 14, 2026
dce83ba
Bump cyscale
thewhaleking Apr 16, 2026
0dbf972
Clean up logic
thewhaleking Apr 16, 2026
20e1f3f
Clean up
thewhaleking Apr 16, 2026
7370333
Debug
thewhaleking Apr 16, 2026
1bace1e
Ruff
thewhaleking Apr 16, 2026
78e5d45
Test fix
thewhaleking Apr 16, 2026
628e7e3
Bug fix
thewhaleking Apr 16, 2026
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
4 changes: 2 additions & 2 deletions .github/workflows/ruff-formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

on:
pull_request:
types: [opened, synchronize, reopened]
types: [ opened, synchronize, reopened ]

jobs:
ruff:
Expand All @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v6

- name: Ruff format check
uses: astral-sh/ruff-action@v3
uses: astral-sh/ruff-action@v4.0.0
with:
version: "0.11.5"
args: "format --diff"
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
from .version import __version__, __version_as_int__


__all__ = ["CLIManager"]
__all__ = ["CLIManager", "__version__", "__version_as_int__"]
5 changes: 3 additions & 2 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6537,6 +6537,7 @@ def stake_childkey_take(
wait_for_inclusion: bool = Options.wait_for_inclusion,
wait_for_finalization: bool = Options.wait_for_finalization,
prompt: bool = Options.prompt,
decline: bool = Options.decline,
quiet: bool = Options.quiet,
verbose: bool = Options.verbose,
json_output: bool = Options.json_output,
Expand All @@ -6562,7 +6563,7 @@ def stake_childkey_take(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=[WO.NAME, WO.HOTKEY],
ask_for=[WO.NAME],
validate=WV.WALLET_AND_HOTKEY,
)
if all_netuids and netuid:
Expand Down Expand Up @@ -6594,6 +6595,7 @@ def stake_childkey_take(
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
prompt=prompt,
decline=decline,
)
)
if json_output:
Expand Down Expand Up @@ -7738,7 +7740,6 @@ def subnets_show(
selected_mechanism_id = self.ask_subnet_mechanism(
mechanism_id, mechanism_count, netuid
)

return self._run_command(
subnets.show(
subtensor=subtensor,
Expand Down
16 changes: 2 additions & 14 deletions bittensor_cli/src/bittensor/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from typing import Union
from bittensor_cli.src import UNITS
from scalecodec.utils.math import fixed_to_float


class Balance:
Expand Down Expand Up @@ -297,17 +298,4 @@ def set_unit(self, netuid: int):
return self


def fixed_to_float(fixed, frac_bits: int = 64, total_bits: int = 128) -> float:
# By default, this is a U64F64
# which is 64 bits of integer and 64 bits of fractional

data: int = fixed["bits"]

# Logical and to get the fractional part; remaining is the integer part
fractional_part = data & (2**frac_bits - 1)
# Shift to get the integer part from the remaining bits
integer_part = data >> (total_bits - frac_bits)

frac_float = fractional_part / (2**frac_bits)

return integer_part + frac_float
__all__ = ["Balance", "UNITS", "fixed_to_float"]
133 changes: 33 additions & 100 deletions bittensor_cli/src/bittensor/chain_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from abc import abstractmethod
from dataclasses import dataclass
from collections.abc import Sequence
from enum import Enum
from typing import Optional, Any, Union, Callable, Hashable
from typing import Optional, Any, Union

import netaddr
from scalecodec.utils.ss58 import ss58_encode
Expand All @@ -13,7 +12,6 @@
SS58_FORMAT,
u16_normalized_float as u16tf,
u64_normalized_float as u64tf,
decode_account_id,
get_netuid_and_subuid_by_storage_index,
)

Expand All @@ -37,28 +35,9 @@ class ChainDataType(Enum):
SubnetIdentity = 11


def decode_hex_identity(info_dictionary):
decoded_info = {}
for k, v in info_dictionary.items():
if isinstance(v, dict):
item = next(iter(v.values()))
else:
item = v

if isinstance(item, tuple):
try:
decoded_info[k] = bytes(item).decode()
except UnicodeDecodeError:
print(f"Could not decode: {k}: {item}")
else:
decoded_info[k] = item
return decoded_info


def process_stake_data(stake_data, netuid):
decoded_stake_data = {}
for account_id_bytes, stake_ in stake_data:
account_id = decode_account_id(account_id_bytes)
for account_id, stake_ in stake_data:
decoded_stake_data.update(
{account_id: Balance.from_rao(stake_).set_unit(netuid)}
)
Expand All @@ -70,32 +49,6 @@ def _tbwu(val: int, netuid: Optional[int] = 0) -> Balance:
return Balance.from_rao(val).set_unit(netuid)


def _chr_str(codes: tuple[int]) -> str:
"""Converts a tuple of integer Unicode code points into a string."""
return "".join(map(chr, codes))


def process_nested(
data: Sequence[dict[Hashable, tuple[int]]] | dict | Any,
chr_transform: Callable[[tuple[int]], str],
) -> list[dict[Hashable, str]] | dict[Hashable, str] | Any:
"""Processes nested data structures by applying a transformation function to their elements."""
if isinstance(data, Sequence):
if len(data) > 0 and isinstance(data[0], dict):
return [
{k: chr_transform(v) for k, v in item.items()}
if item is not None
else None
for item in data
]
# TODO @abe why do we kind of silently fail here?
return {}
elif isinstance(data, dict):
return {k: chr_transform(v) for k, v in data.items()}
else:
return data


@dataclass
class AxonInfo:
version: int
Expand Down Expand Up @@ -292,8 +245,8 @@ class StakeInfo(InfoBase):

@classmethod
def _fix_decoded(cls, decoded: Any) -> "StakeInfo":
hotkey = decode_account_id(decoded.get("hotkey"))
coldkey = decode_account_id(decoded.get("coldkey"))
hotkey = decoded.get("hotkey")
coldkey = decoded.get("coldkey")
netuid = int(decoded.get("netuid"))
stake = Balance.from_rao(decoded.get("stake")).set_unit(netuid)
locked = Balance.from_rao(decoded.get("locked")).set_unit(netuid)
Expand Down Expand Up @@ -390,8 +343,8 @@ def _fix_decoded(cls, decoded: Any) -> "NeuronInfo":
stake_dict = process_stake_data(decoded.get("stake"), netuid=netuid)
total_stake = sum(stake_dict.values()) if stake_dict else Balance(0)
axon_info = decoded.get("axon_info", {})
coldkey = decode_account_id(decoded.get("coldkey"))
hotkey = decode_account_id(decoded.get("hotkey"))
coldkey = decoded.get("coldkey")
hotkey = decoded.get("hotkey")
return cls(
hotkey=hotkey,
coldkey=coldkey,
Expand Down Expand Up @@ -484,11 +437,11 @@ def get_null_neuron() -> "NeuronInfoLite":
def _fix_decoded(cls, decoded: Union[dict, "NeuronInfoLite"]) -> "NeuronInfoLite":
active = decoded.get("active")
axon_info = decoded.get("axon_info", {})
coldkey = decode_account_id(decoded.get("coldkey"))
coldkey = decoded.get("coldkey")
consensus = decoded.get("consensus")
dividends = decoded.get("dividends")
emission = decoded.get("emission")
hotkey = decode_account_id(decoded.get("hotkey"))
hotkey = decoded.get("hotkey")
incentive = decoded.get("incentive")
last_update = decoded.get("last_update")
netuid = decoded.get("netuid")
Expand Down Expand Up @@ -569,12 +522,9 @@ class DelegateInfo(InfoBase):

@classmethod
def _fix_decoded(cls, decoded: "DelegateInfo") -> "DelegateInfo":
hotkey = decode_account_id(decoded.get("hotkey_ss58"))
owner = decode_account_id(decoded.get("owner_ss58"))
nominators = [
(decode_account_id(x), Balance.from_rao(y))
for x, y in decoded.get("nominators")
]
hotkey = decoded.get("hotkey_ss58")
owner = decoded.get("owner_ss58")
nominators = [(x, Balance.from_rao(y)) for x, y in decoded.get("nominators")]
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
return cls(
hotkey_ss58=hotkey,
Expand Down Expand Up @@ -675,7 +625,7 @@ def _fix_decoded(cls, decoded: "SubnetInfo") -> "SubnetInfo":
},
emission_value=decoded.get("emission_value"),
burn=Balance.from_rao(decoded.get("burn")),
owner_ss58=decode_account_id(decoded.get("owner")),
owner_ss58=decoded.get("owner"),
)


Expand All @@ -695,14 +645,14 @@ class SubnetIdentity(InfoBase):
@classmethod
def _fix_decoded(cls, decoded: dict) -> "SubnetIdentity":
return cls(
subnet_name=bytes(decoded["subnet_name"]).decode(),
github_repo=bytes(decoded["github_repo"]).decode(),
subnet_contact=bytes(decoded["subnet_contact"]).decode(),
subnet_url=bytes(decoded["subnet_url"]).decode(),
discord=bytes(decoded["discord"]).decode(),
description=bytes(decoded["description"]).decode(),
logo_url=bytes(decoded["logo_url"]).decode(),
additional=bytes(decoded["additional"]).decode(),
subnet_name=decoded["subnet_name"],
github_repo=decoded["github_repo"],
subnet_contact=decoded["subnet_contact"],
subnet_url=decoded["subnet_url"],
discord=decoded["discord"],
description=decoded["description"],
logo_url=decoded["logo_url"],
additional=decoded["additional"],
)


Expand Down Expand Up @@ -742,8 +692,8 @@ def _fix_decoded(cls, decoded: Any) -> "DynamicInfo":
subnet_name = bytes([int(b) for b in decoded.get("subnet_name")]).decode()
is_dynamic = True if netuid > 0 else False # Patching for netuid 0

owner_hotkey = decode_account_id(decoded.get("owner_hotkey"))
owner_coldkey = decode_account_id(decoded.get("owner_coldkey"))
owner_hotkey = decoded.get("owner_hotkey")
owner_coldkey = decoded.get("owner_coldkey")

emission = Balance.from_rao(decoded.get("emission")).set_unit(0)
alpha_in = Balance.from_rao(decoded.get("alpha_in")).set_unit(netuid)
Expand Down Expand Up @@ -829,7 +779,7 @@ def tao_to_alpha_with_slippage(
if self.is_dynamic:
new_tao_in = self.tao_in + tao
if new_tao_in == 0:
return tao, Balance.from_rao(0)
return tao, Balance.from_rao(0), 0.0
new_alpha_in = self.k / new_tao_in

# Amount of alpha given to the staker
Expand Down Expand Up @@ -919,11 +869,10 @@ def _fix_decoded(
cls, coldkey: str, decoded: tuple
) -> "ColdkeySwapAnnouncementInfo":
execution_block, new_coldkey_hash = decoded
hash_str = "0x" + bytes(new_coldkey_hash[0]).hex()
return cls(
coldkey=coldkey,
execution_block=int(execution_block),
new_coldkey_hash=hash_str,
new_coldkey_hash=new_coldkey_hash,
)


Expand Down Expand Up @@ -953,8 +902,8 @@ def _fix_decoded(cls, decoded: Any) -> "SubnetState":
netuid = decoded.get("netuid")
return cls(
netuid=netuid,
hotkeys=[decode_account_id(val) for val in decoded.get("hotkeys")],
coldkeys=[decode_account_id(val) for val in decoded.get("coldkeys")],
hotkeys=decoded.get("hotkeys"),
coldkeys=decoded.get("coldkeys"),
active=decoded.get("active"),
validator_permit=decoded.get("validator_permit"),
pruning_score=[u16tf(val) for val in decoded.get("pruning_score")],
Expand Down Expand Up @@ -1122,10 +1071,6 @@ def _fix_decoded(cls, decoded: dict) -> "MetagraphInfo":
# Name and symbol
decoded.update({"name": bytes(decoded.get("name")).decode()})
decoded.update({"symbol": bytes(decoded.get("symbol")).decode()})
for key in ["identities", "identity"]:
raw_data = decoded.get(key)
processed = process_nested(raw_data, _chr_str)
decoded.update({key: processed})

return cls(
# Subnet index
Expand Down Expand Up @@ -1194,8 +1139,8 @@ def _fix_decoded(cls, decoded: dict) -> "MetagraphInfo":
alpha_low=u16tf(decoded["alpha_low"]),
bonds_moving_avg=u64tf(decoded["bonds_moving_avg"]),
# Metagraph info.
hotkeys=[decode_account_id(ck) for ck in decoded.get("hotkeys", [])],
coldkeys=[decode_account_id(hk) for hk in decoded.get("coldkeys", [])],
hotkeys=decoded.get("hotkeys", []),
coldkeys=decoded.get("coldkeys", []),
identities=decoded["identities"],
axons=decoded.get("axons", []),
active=decoded["active"],
Expand All @@ -1214,11 +1159,11 @@ def _fix_decoded(cls, decoded: dict) -> "MetagraphInfo":
total_stake=[_tbwu(ts, _netuid) for ts in decoded["total_stake"]],
# Dividend break down
tao_dividends_per_hotkey=[
(decode_account_id(alpha[0]), _tbwu(alpha[1]))
(alpha[0], _tbwu(alpha[1]))
for alpha in decoded["tao_dividends_per_hotkey"]
],
alpha_dividends_per_hotkey=[
(decode_account_id(adphk[0]), _tbwu(adphk[1], _netuid))
(adphk[0], _tbwu(adphk[1], _netuid))
for adphk in decoded["alpha_dividends_per_hotkey"]
],
)
Expand Down Expand Up @@ -1258,21 +1203,9 @@ class CrowdloanData(InfoBase):

@classmethod
def _fix_decoded(cls, decoded: dict[str, Any]) -> "CrowdloanData":
creator = (
decode_account_id(creator_raw)
if (creator_raw := decoded.get("creator"))
else None
)
funds_account = (
decode_account_id(funds_raw)
if (funds_raw := decoded.get("funds_account"))
else None
)
target_address = (
decode_account_id(target_raw)
if (target_raw := decoded.get("target_address"))
else None
)
creator = decoded.get("creator")
funds_account = decoded.get("funds_account")
target_address = decoded.get("target_address")
return cls(
creator=creator,
funds_account=funds_account,
Expand Down
2 changes: 0 additions & 2 deletions bittensor_cli/src/bittensor/extrinsics/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
millify,
get_human_readable,
print_verbose,
print_error,
unlock_key,
hex_to_bytes,
get_hotkey_pub_ss58,
Expand Down Expand Up @@ -784,7 +783,6 @@ async def burned_register_extrinsic(
subtensor.get_balance(
wallet.coldkeypub.ss58_address,
block_hash=block_hash,
reuse_block=False,
),
subtensor.get_netuids_for_hotkey(
get_hotkey_pub_ss58(wallet), block_hash=block_hash
Expand Down
3 changes: 1 addition & 2 deletions bittensor_cli/src/bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
print_success,
print_verbose,
is_valid_bittensor_address_or_public_key,
print_error,
unlock_key,
)

Expand Down Expand Up @@ -228,7 +227,7 @@ async def do_transfer() -> tuple[bool, str, str, Optional[AsyncExtrinsicReceipt]
if success:
with console.status(":satellite: Checking Balance...", spinner="aesthetic"):
new_balance = await subtensor.get_balance(
proxy or wallet.coldkeypub.ss58_address, reuse_block=False
proxy or wallet.coldkeypub.ss58_address
)
console.print(
f"Balance:\n"
Expand Down
1 change: 0 additions & 1 deletion bittensor_cli/src/bittensor/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ async def get_total_subnets():
module="SubtensorModule",
storage_function="TotalNetworks",
params=[],
reuse_block_hash=True,
)
return _result

Expand Down
Loading
Loading