Skip to content

Commit 7cc53eb

Browse files
authored
Merge pull request #370 from opentensor/update/identitiy-lengths
Updates subnet and neuron identity
2 parents f4ea991 + 21f50dd commit 7cc53eb

File tree

3 files changed

+59
-63
lines changed

3 files changed

+59
-63
lines changed

bittensor_cli/cli.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,23 +2682,29 @@ def wallet_get_id(
26822682
[bold]Note[/bold]: This command is primarily used for informational purposes and has no side effects on the blockchain network state.
26832683
"""
26842684
wallet = None
2685-
if coldkey_ss58:
2686-
if not is_valid_ss58_address(coldkey_ss58):
2687-
print_error("You entered an invalid ss58 address")
2688-
raise typer.Exit()
2689-
else:
2690-
coldkey_or_ss58 = Prompt.ask(
2691-
"Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]",
2692-
default=self.config.get("wallet_name") or defaults.wallet.name,
2693-
)
2694-
if is_valid_ss58_address(coldkey_or_ss58):
2695-
coldkey_ss58 = coldkey_or_ss58
2685+
if not wallet_name:
2686+
if coldkey_ss58:
2687+
if not is_valid_ss58_address(coldkey_ss58):
2688+
print_error("You entered an invalid ss58 address")
2689+
raise typer.Exit()
26962690
else:
2697-
wallet_name = coldkey_or_ss58 if coldkey_or_ss58 else wallet_name
2698-
wallet = self.wallet_ask(
2699-
wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME]
2691+
coldkey_or_ss58 = Prompt.ask(
2692+
"Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]",
2693+
default=self.config.get("wallet_name") or defaults.wallet.name,
27002694
)
2701-
coldkey_ss58 = wallet.coldkeypub.ss58_address
2695+
if is_valid_ss58_address(coldkey_or_ss58):
2696+
coldkey_ss58 = coldkey_or_ss58
2697+
else:
2698+
wallet_name = coldkey_or_ss58 if coldkey_or_ss58 else wallet_name
2699+
wallet = self.wallet_ask(
2700+
wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME]
2701+
)
2702+
coldkey_ss58 = wallet.coldkeypub.ss58_address
2703+
else:
2704+
wallet = self.wallet_ask(
2705+
wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME]
2706+
)
2707+
coldkey_ss58 = wallet.coldkeypub.ss58_address
27022708

27032709
self.verbosity_handler(quiet, verbose)
27042710
return self._run_command(

bittensor_cli/src/bittensor/utils.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,38 +1097,30 @@ def prompt_for_identity(
10971097
identity_fields = {}
10981098

10991099
fields = [
1100-
("name", "[blue]Display name[/blue]", name),
1101-
("url", "[blue]Web URL[/blue]", web_url),
1102-
("image", "[blue]Image URL[/blue]", image_url),
1103-
("discord", "[blue]Discord handle[/blue]", discord),
1104-
("description", "[blue]Description[/blue]", description),
1105-
("additional", "[blue]Additional information[/blue]", additional),
1106-
("github_repo", "[blue]GitHub repository URL[/blue]", github_repo),
1100+
("name", "[blue]Display name[/blue]", name, 256),
1101+
("url", "[blue]Web URL[/blue]", web_url, 256),
1102+
("image", "[blue]Image URL[/blue]", image_url, 1024),
1103+
("discord", "[blue]Discord handle[/blue]", discord, 256),
1104+
("description", "[blue]Description[/blue]", description, 1024),
1105+
("additional", "[blue]Additional information[/blue]", additional, 1024),
1106+
("github_repo", "[blue]GitHub repository URL[/blue]", github_repo, 256),
11071107
]
11081108

1109-
text_rejection = partial(
1110-
retry_prompt,
1111-
rejection=lambda x: sys.getsizeof(x) > 113,
1112-
rejection_text="[red]Error:[/red] Identity field must be <= 64 raw bytes.",
1113-
)
1114-
11151109
if not any(
1116-
[
1117-
name,
1118-
web_url,
1119-
image_url,
1120-
discord,
1121-
description,
1122-
additional,
1123-
github_repo,
1124-
]
1110+
[name, web_url, image_url, discord, description, additional, github_repo]
11251111
):
11261112
console.print(
11271113
"\n[yellow]All fields are optional. Press Enter to skip and keep the default/existing value.[/yellow]\n"
11281114
"[dark_sea_green3]Tip: Entering a space and pressing Enter will clear existing default value.\n"
11291115
)
11301116

1131-
for key, prompt, value in fields:
1117+
for key, prompt, value, byte_limit in fields:
1118+
text_rejection = partial(
1119+
retry_prompt,
1120+
rejection=lambda x: len(x.encode("utf-8")) > byte_limit,
1121+
rejection_text=f"[red]Error:[/red] {key} field must be <= {byte_limit} bytes.",
1122+
)
1123+
11321124
if value:
11331125
identity_fields[key] = value
11341126
else:
@@ -1170,50 +1162,51 @@ def prompt_for_subnet_identity(
11701162
"subnet_name",
11711163
"[blue]Subnet name [dim](optional)[/blue]",
11721164
subnet_name,
1173-
lambda x: x and sys.getsizeof(x) > 113,
1174-
"[red]Error:[/red] Subnet name must be <= 64 raw bytes.",
1165+
lambda x: x and len(x.encode("utf-8")) > 256,
1166+
"[red]Error:[/red] Subnet name must be <= 256 bytes.",
11751167
),
11761168
(
11771169
"github_repo",
11781170
"[blue]GitHub repository URL [dim](optional)[/blue]",
11791171
github_repo,
1180-
lambda x: x and not is_valid_github_url(x),
1172+
lambda x: x
1173+
and (not is_valid_github_url(x) or len(x.encode("utf-8")) > 1024),
11811174
"[red]Error:[/red] Please enter a valid GitHub repository URL (e.g., https://github.com/username/repo).",
11821175
),
11831176
(
11841177
"subnet_contact",
11851178
"[blue]Contact email [dim](optional)[/blue]",
11861179
subnet_contact,
1187-
lambda x: x and not is_valid_contact(x),
1180+
lambda x: x and (not is_valid_contact(x) or len(x.encode("utf-8")) > 1024),
11881181
"[red]Error:[/red] Please enter a valid email address.",
11891182
),
11901183
(
11911184
"subnet_url",
11921185
"[blue]Subnet URL [dim](optional)[/blue]",
11931186
subnet_url,
1194-
lambda x: x and sys.getsizeof(x) > 113,
1195-
"[red]Error:[/red] Please enter a valid URL.",
1187+
lambda x: x and len(x.encode("utf-8")) > 1024,
1188+
"[red]Error:[/red] Please enter a valid URL <= 1024 bytes.",
11961189
),
11971190
(
11981191
"discord",
11991192
"[blue]Discord handle [dim](optional)[/blue]",
12001193
discord,
1201-
lambda x: x and sys.getsizeof(x) > 113,
1202-
"[red]Error:[/red] Please enter a valid Discord handle.",
1194+
lambda x: x and len(x.encode("utf-8")) > 256,
1195+
"[red]Error:[/red] Please enter a valid Discord handle <= 256 bytes.",
12031196
),
12041197
(
12051198
"description",
12061199
"[blue]Description [dim](optional)[/blue]",
12071200
description,
1208-
lambda x: x and sys.getsizeof(x) > 113,
1209-
"[red]Error:[/red] Description must be <= 64 raw bytes.",
1201+
lambda x: x and len(x.encode("utf-8")) > 1024,
1202+
"[red]Error:[/red] Description must be <= 1024 bytes.",
12101203
),
12111204
(
12121205
"additional",
12131206
"[blue]Additional information [dim](optional)[/blue]",
12141207
additional,
1215-
lambda x: x and sys.getsizeof(x) > 113,
1216-
"[red]Error:[/red] Additional information must be <= 64 raw bytes.",
1208+
lambda x: x and len(x.encode("utf-8")) > 1024,
1209+
"[red]Error:[/red] Additional information must be <= 1024 bytes.",
12171210
),
12181211
]
12191212

@@ -1273,23 +1266,29 @@ def is_valid_contact(contact: str) -> bool:
12731266
return bool(re.match(email_pattern, contact))
12741267

12751268

1276-
def get_subnet_name(subnet_info) -> str:
1269+
def get_subnet_name(subnet_info, max_length: int = 20) -> str:
12771270
"""Get the subnet name, prioritizing subnet_identity.subnet_name over subnet.subnet_name.
1271+
Truncates the name if it exceeds max_length.
12781272
12791273
Args:
1280-
subnet: The subnet dynamic info
1274+
subnet_info: The subnet dynamic info
1275+
max_length: Maximum length of the returned name. Names longer than this will be truncated with '...'
12811276
12821277
Returns:
1283-
str: The subnet name or empty string if no name is found
1278+
str: The subnet name (truncated if necessary) or empty string if no name is found
12841279
"""
1285-
return (
1280+
name = (
12861281
subnet_info.subnet_identity.subnet_name
12871282
if hasattr(subnet_info, "subnet_identity")
12881283
and subnet_info.subnet_identity is not None
12891284
and subnet_info.subnet_identity.subnet_name is not None
12901285
else (subnet_info.subnet_name if subnet_info.subnet_name is not None else "")
12911286
)
12921287

1288+
if len(name) > max_length:
1289+
return name[: max_length - 3] + "..."
1290+
return name
1291+
12931292

12941293
def print_linux_dependency_message():
12951294
"""Prints the WebKit dependency message for Linux systems."""

bittensor_cli/src/commands/wallets.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,15 +1361,6 @@ async def set_id(
13611361
"github_repo": github_repo.encode(),
13621362
}
13631363

1364-
for field, value in identity_data.items():
1365-
max_size = 64 # bytes
1366-
if len(value) > max_size:
1367-
err_console.print(
1368-
f"[red]Error:[/red] Identity field [white]{field}[/white] must be <= {max_size} bytes.\n"
1369-
f"Value '{value.decode()}' is {len(value)} bytes."
1370-
)
1371-
return False
1372-
13731364
if not unlock_key(wallet).success:
13741365
return False
13751366

0 commit comments

Comments
 (0)