Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 9.8.7 /2025-07-23
* Fix for handling tuples for `additional` by @thewhaleking in https://github.com/opentensor/btcli/pull/557

**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.8.6...v9.8.7

## 9.8.6 /2025-07-22
* Hyperparam discrepancy between set/get by @thewhaleking in https://github.com/opentensor/btcli/pull/552
* Hyperparameters in alphabetical order for `btcli sudo get/set` by @basfroman in https://github.com/opentensor/btcli/pull/553
Expand Down
33 changes: 19 additions & 14 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,20 +622,23 @@ def decode_hex_identity_dict(info_dictionary) -> dict[str, Any]:

Examples:
input_dict = {
... "name": {"value": "0x6a6f686e"},
... "additional": [
... [{"data": "0x64617461"}]
... ]
... }
"name": {"value": "0x6a6f686e"},
"additional": [
{"data1": "0x64617461"},
("data2", "0x64617461")
]
}
decode_hex_identity_dict(input_dict)
{'name': 'john', 'additional': [('data', 'data')]}
{'name': 'john', 'additional': [('data1', 'data'), ('data2', 'data')]}
"""

def get_decoded(data: str) -> str:
def get_decoded(data: Optional[str]) -> str:
"""Decodes a hex-encoded string."""
if data is None:
return ""
try:
return hex_to_bytes(data).decode()
except UnicodeDecodeError:
except (UnicodeDecodeError, ValueError):
print(f"Could not decode: {key}: {item}")

for key, value in info_dictionary.items():
Expand All @@ -651,12 +654,14 @@ def get_decoded(data: str) -> str:
if key == "additional":
additional = []
for item in value:
additional.append(
tuple(
get_decoded(data=next(iter(sub_item.values())))
for sub_item in item
)
)
if isinstance(item, dict):
for k, v in item.items():
additional.append((k, get_decoded(v)))
else:
if isinstance(item, (tuple, list)) and len(item) == 2:
k_, v = item
k = k_ if k_ is not None else ""
additional.append((k, get_decoded(v)))
info_dictionary[key] = additional

return info_dictionary
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "bittensor-cli"
version = "9.8.6"
version = "9.8.7"
description = "Bittensor CLI"
readme = "README.md"
authors = [
Expand Down
29 changes: 29 additions & 0 deletions tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from bittensor_cli.src.bittensor import utils
import pytest


@pytest.mark.parametrize(
"input_dict,expected_result",
[
(
{
"name": {"value": "0x6a6f686e"},
"additional": [{"data1": "0x64617461"}, ("data2", "0x64617461")],
},
{"name": "john", "additional": [("data1", "data"), ("data2", "data")]},
),
(
{"name": {"value": "0x6a6f686e"}, "additional": [("data2", "0x64617461")]},
{"name": "john", "additional": [("data2", "data")]},
),
(
{
"name": {"value": "0x6a6f686e"},
"additional": [(None, None)],
},
{"name": "john", "additional": [("", "")]},
),
],
)
def test_decode_hex_identity_dict(input_dict, expected_result):
assert utils.decode_hex_identity_dict(input_dict) == expected_result
Loading