Skip to content

Commit 8a6c025

Browse files
authored
Merge pull request #613 from opentensor/feat/thewhaleking/subnet-symbol-set
subnet symbol set command
2 parents e24801a + 0c5b70a commit 8a6c025

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

bittensor_cli/cli.py

Lines changed: 52 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,55 @@ 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 to a different available symbol. The full list of available symbols can be found here:
5814+
[#8CB9E9]https://github.com/opentensor/subtensor/blob/main/pallets/subtensor/src/subnets/symbols.rs#L8[/#8CB9E9]
5815+
5816+
5817+
EXAMPLE
5818+
5819+
[green]$[/green] btcli subnets set-symbol [dark_orange]--netuid 1 シ[/dark_orange]
5820+
5821+
5822+
JSON OUTPUT:
5823+
If --json-output is used, the output will be in the following schema:
5824+
[#AFEFFF]{success: [dark_orange]bool[/dark_orange], message: [dark_orange]str[/dark_orange]}[/#AFEFFF]
5825+
"""
5826+
self.verbosity_handler(quiet, verbose, json_output)
5827+
if len(symbol) > 1:
5828+
err_console.print("Your symbol must be a single character.")
5829+
return False
5830+
wallet = self.wallet_ask(
5831+
wallet_name,
5832+
wallet_path,
5833+
wallet_hotkey,
5834+
ask_for=[WO.NAME, WO.HOTKEY],
5835+
validate=WV.WALLET_AND_HOTKEY,
5836+
)
5837+
return self._run_command(
5838+
subnets.set_symbol(
5839+
wallet=wallet,
5840+
subtensor=self.initialize_chain(network),
5841+
netuid=netuid,
5842+
symbol=symbol,
5843+
prompt=prompt,
5844+
json_output=json_output,
5845+
)
5846+
)
5847+
57965848
def weights_reveal(
57975849
self,
57985850
network: Optional[list[str]] = Options.network,

bittensor_cli/src/commands/subnets/subnets.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,3 +2448,71 @@ 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+
"""
2462+
Set a subtensor's symbol, given the netuid and symbol.
2463+
2464+
The symbol must be a symbol that subtensor recognizes as available
2465+
(defined in https://github.com/opentensor/subtensor/blob/main/pallets/subtensor/src/subnets/symbols.rs#L8)
2466+
"""
2467+
if not await subtensor.subnet_exists(netuid):
2468+
err = f"Subnet {netuid} does not exist."
2469+
if json_output:
2470+
json_console.print_json(data={"success": False, "message": err})
2471+
else:
2472+
err_console.print(err)
2473+
return False
2474+
2475+
if prompt and not json_output:
2476+
sn_info = await subtensor.subnet(netuid=netuid)
2477+
if not Confirm.ask(
2478+
f"Your current subnet symbol for SN{netuid} is {sn_info.symbol}. Do you want to update it to {symbol}?"
2479+
):
2480+
return False
2481+
2482+
if not (unlock_status := unlock_key(wallet, print_out=False)).success:
2483+
err = unlock_status.message
2484+
if json_output:
2485+
json_console.print_json(data={"success": False, "message": err})
2486+
else:
2487+
console.print(err)
2488+
return False
2489+
2490+
start_call = await subtensor.substrate.compose_call(
2491+
call_module="SubtensorModule",
2492+
call_function="update_symbol",
2493+
call_params={"netuid": netuid, "symbol": symbol.encode("utf-8")},
2494+
)
2495+
2496+
signed_ext = await subtensor.substrate.create_signed_extrinsic(
2497+
call=start_call,
2498+
keypair=wallet.coldkey,
2499+
)
2500+
2501+
response = await subtensor.substrate.submit_extrinsic(
2502+
extrinsic=signed_ext,
2503+
wait_for_inclusion=True,
2504+
)
2505+
if await response.is_success:
2506+
message = f"Successfully updated SN{netuid}'s symbol to {symbol}."
2507+
if json_output:
2508+
json_console.print_json(data={"success": True, "message": message})
2509+
else:
2510+
console.print(f":white_heavy_check_mark:[dark_sea_green3] {message}\n")
2511+
return True
2512+
else:
2513+
err = format_error_message(await response.error_message)
2514+
if json_output:
2515+
json_console.print_json(data={"success": False, "message": err})
2516+
else:
2517+
err_console.print(f":cross_mark: [red]Failed[/red]: {err}")
2518+
return False

tests/e2e_tests/test_staking_sudo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* btcli subnets create
1111
* btcli subnets set-identity
1212
* btcli subnets get-identity
13+
* btcli subnets set-symbol
1314
* btcli subnets register
1415
* btcli subnets price
1516
* btcli stake add
@@ -235,6 +236,34 @@ def test_staking(local_chain, wallet_setup):
235236
assert get_identity_output["logo_url"] == sn_logo_url
236237
assert get_identity_output["additional"] == sn_add_info
237238

239+
# set symbol
240+
set_symbol = exec_command_alice(
241+
"subnets",
242+
"set-symbol",
243+
extra_args=[
244+
"--wallet-path",
245+
wallet_path_alice,
246+
"--wallet-name",
247+
wallet_alice.name,
248+
"--hotkey",
249+
wallet_alice.hotkey_str,
250+
"--chain",
251+
"ws://127.0.0.1:9945",
252+
"--netuid",
253+
netuid,
254+
"--json-output",
255+
"--no-prompt",
256+
"シ",
257+
],
258+
)
259+
set_symbol_output = json.loads(set_symbol.stdout)
260+
assert set_symbol_output["success"] is True, set_symbol_output
261+
assert set_symbol_output["success"] is True, set_symbol_output
262+
assert (
263+
set_symbol_output["message"]
264+
== f"Successfully updated SN{netuid}'s symbol to シ."
265+
)
266+
238267
get_s_price = exec_command_alice(
239268
"subnets",
240269
"price",

0 commit comments

Comments
 (0)