@@ -2448,3 +2448,71 @@ async def start_subnet(
2448
2448
await get_start_schedule (subtensor , netuid )
2449
2449
print_error (f":cross_mark: Failed to start subnet: { error_msg } " )
2450
2450
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
0 commit comments