Skip to content

Commit da8215c

Browse files
committed
Adds cmd for setting subnet symbol.
1 parent b65a548 commit da8215c

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

bittensor_cli/cli.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ def __init__(self):
960960
self.subnets_app.command(
961961
"check-start", rich_help_panel=HELP_PANELS["SUBNETS"]["INFO"]
962962
)(self.subnets_check_start)
963+
self.subnets_app.command(
964+
"set-symbol", rich_help_panel=HELP_PANELS["SUBNETS"]["IDENTITY"]
965+
)(self.subnets_set_symbol)
963966

964967
# weights commands
965968
self.weights_app.command(
@@ -5793,6 +5796,35 @@ def subnets_metagraph(
57935796
)
57945797
)
57955798

5799+
def subnets_set_symbol(
5800+
self,
5801+
wallet_name: str = Options.wallet_name,
5802+
wallet_path: str = Options.wallet_path,
5803+
wallet_hotkey: str = Options.wallet_hotkey,
5804+
network: Optional[list[str]] = Options.network,
5805+
netuid: int = Options.netuid,
5806+
json_output: bool = Options.json_output,
5807+
prompt: bool = Options.prompt,
5808+
quiet: bool = Options.quiet,
5809+
verbose: bool = Options.verbose,
5810+
symbol: str = typer.Argument(help="The symbol to set for your subnet."),
5811+
):
5812+
"""
5813+
Allows the user to update their subnet symbol.
5814+
5815+
EXAMPLE
5816+
5817+
[green]$[/green] btcli subnets set-symbol --netuid 1 ‡
5818+
"""
5819+
self.verbosity_handler(quiet, verbose, json_output)
5820+
wallet = self.wallet_ask(
5821+
wallet_name,
5822+
wallet_path,
5823+
wallet_hotkey,
5824+
ask_for=[WO.NAME, WO.HOTKEY],
5825+
validate=WV.WALLET_AND_HOTKEY,
5826+
)
5827+
57965828
def weights_reveal(
57975829
self,
57985830
network: Optional[list[str]] = Options.network,

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,3 +2448,66 @@ async def start_subnet(
24482448
await get_start_schedule(subtensor, netuid)
24492449
print_error(f":cross_mark: Failed to start subnet: {error_msg}")
24502450
return False
2451+
2452+
2453+
async def set_symbol(
2454+
wallet: "Wallet",
2455+
subtensor: "SubtensorInterface",
2456+
netuid: int,
2457+
symbol: str,
2458+
prompt: bool = False,
2459+
json_output: bool = False,
2460+
) -> bool:
2461+
"""Set a subtensor's symbol"""
2462+
if not await subtensor.subnet_exists(netuid):
2463+
err = f"Subnet {netuid} does not exist."
2464+
if json_output:
2465+
json_console.print_json(data={"success": False, "message": err})
2466+
else:
2467+
err_console.print(err)
2468+
return False
2469+
2470+
if prompt and not json_output:
2471+
sn_info = await subtensor.subnet(netuid=netuid)
2472+
if not Confirm.ask(
2473+
f"Your current subnet symbol for SN{netuid} is {sn_info.symbol}. Do you want to update it to {symbol}?"
2474+
):
2475+
return False
2476+
2477+
if not (unlock_status := unlock_key(wallet, print_out=False)).success:
2478+
err = unlock_status.message
2479+
if json_output:
2480+
json_console.print_json(data={"success": False, "message": err})
2481+
else:
2482+
console.print(err)
2483+
return False
2484+
2485+
start_call = await subtensor.substrate.compose_call(
2486+
call_module="SubtensorModule",
2487+
call_function="update_symbol",
2488+
call_params={"netuid": netuid, "symbol": symbol},
2489+
)
2490+
2491+
signed_ext = await subtensor.substrate.create_signed_extrinsic(
2492+
call=start_call,
2493+
keypair=wallet.coldkey,
2494+
)
2495+
2496+
response = await subtensor.substrate.submit_extrinsic(
2497+
extrinsic=signed_ext,
2498+
wait_for_inclusion=True,
2499+
)
2500+
if await response.is_success:
2501+
message = f"Successfully updated SN{netuid}'s symbol to {symbol}."
2502+
if json_output:
2503+
json_console.print_json(data={"success": True, "message": message})
2504+
else:
2505+
console.print(f":white_heavy_check_mark:[dark_sea_green3] {message}\n")
2506+
return True
2507+
else:
2508+
err = format_error_message(await response.error_message)
2509+
if json_output:
2510+
json_console.print_json(data={"success": False, "message": err})
2511+
else:
2512+
err_console.print(f":cross_mark: [red]Failed[/red]: {err}")
2513+
return False

0 commit comments

Comments
 (0)