Skip to content
45 changes: 40 additions & 5 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9712,13 +9712,18 @@ def proxy_add(
def proxy_remove(
self,
delegate: Annotated[
str,
Optional[str],
typer.Option(
callback=is_valid_ss58_address_param,
prompt="Enter the SS58 address of the delegate to remove, e.g. 5dxds...",
help="The SS58 address of the delegate to remove",
prompt=False,
help="The SS58 address of the delegate to remove (required if --all is not used)",
),
] = "",
] = None,
all: bool = typer.Option(
False,
"--all",
help="Remove all proxies associated with this account",
),
network: Optional[list[str]] = Options.network,
proxy_type: ProxyType = Options.proxy_type,
delay: int = typer.Option(0, help="Delay, in number of blocks"),
Expand All @@ -9745,17 +9750,46 @@ def proxy_remove(
[green]$[/green] btcli proxy remove --delegate 5GDel... --proxy-type Transfer

"""
# TODO should add a --all flag to call Proxy.remove_proxies ?
logger.debug(
"args:\n"
f"delegate: {delegate}\n"
f"all: {all}\n"
f"network: {network}\n"
f"proxy_type: {proxy_type}\n"
f"delay: {delay}\n"
f"wait_for_finalization: {wait_for_finalization}\n"
f"wait_for_inclusion: {wait_for_inclusion}\n"
f"era: {period}\n"
)
# Validate that either delegate is provided or --all is used, but not both
if not all and not delegate:
if not json_output:
print_error(
"Either --delegate must be provided or --all flag must be used."
)
else:
json_console.print_json(
data={
"success": False,
"message": "Either --delegate must be provided or --all flag must be used.",
"extrinsic_identifier": None,
}
)
return

if all and delegate:
if not json_output:
print_error("--delegate cannot be used together with --all flag.")
else:
json_console.print_json(
data={
"success": False,
"message": "--delegate cannot be used together with --all flag.",
"extrinsic_identifier": None,
}
)
return

self.verbosity_handler(quiet, verbose, json_output, prompt)
wallet = self.wallet_ask(
wallet_name=wallet_name,
Expand All @@ -9778,6 +9812,7 @@ def proxy_remove(
wait_for_finalization=wait_for_finalization,
period=period,
json_output=json_output,
remove_all=all,
)
)

Expand Down
5 changes: 3 additions & 2 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,8 +1757,9 @@ def prompt_for_subnet_identity(
"github_repo",
"[blue]GitHub repository URL [dim](optional)[/blue]",
github_repo,
lambda x: x
and (not is_valid_github_url(x) or len(x.encode("utf-8")) > 1024),
lambda x: (
x and (not is_valid_github_url(x) or len(x.encode("utf-8")) > 1024)
),
"[red]Error:[/red] Please enter a valid GitHub repository URL (e.g., https://github.com/username/repo).",
),
(
Expand Down
65 changes: 46 additions & 19 deletions bittensor_cli/src/commands/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ async def create_proxy(
async def remove_proxy(
subtensor: "SubtensorInterface",
wallet: "Wallet",
proxy_type: ProxyType,
delegate: str,
proxy_type: Optional[ProxyType],
delegate: Optional[str],
delay: int,
prompt: bool,
decline: bool,
Expand All @@ -265,18 +265,35 @@ async def remove_proxy(
wait_for_finalization: bool,
period: int,
json_output: bool,
remove_all: bool = False,
) -> None:
"""
Executes the remove proxy call on the chain
Executes the remove proxy call on the chain.

If remove_all is True, removes all proxies for the account.
Otherwise, removes a specific proxy identified by delegate, proxy_type, and delay.
"""
# Handle confirmation prompt
if prompt:
if not confirm_action(
f"This will remove a proxy of type {proxy_type.value} for delegate {delegate}."
f"Do you want to proceed?",
decline=decline,
quiet=quiet,
):
return None
if remove_all:
confirmation = Prompt.ask(
"[red]WARNING:[/red] This will remove ALL proxies associated with this account.\n"
"[red]All proxy relationships will be permanently lost.[/red]\n"
"To proceed, enter [red]REMOVE[/red]"
)
if confirmation != "REMOVE":
print_error("Invalid input. Operation cancelled.")
return None
else:
if not confirm_action(
f"This will remove a proxy of type {proxy_type.value} for delegate {delegate}. "
f"Do you want to proceed?",
decline=decline,
quiet=quiet,
):
return None

# Unlock wallet
if not (ulw := unlock_key(wallet, print_out=not json_output)).success:
if not json_output:
print_error(ulw.message)
Expand All @@ -289,15 +306,25 @@ async def remove_proxy(
}
)
return None
call = await subtensor.substrate.compose_call(
call_module="Proxy",
call_function="remove_proxy",
call_params={
"proxy_type": proxy_type.value,
"delay": delay,
"delegate": delegate,
},
)

# Compose the appropriate call
if remove_all:
call = await subtensor.substrate.compose_call(
call_module="Proxy",
call_function="remove_proxies",
call_params={},
)
else:
call = await subtensor.substrate.compose_call(
call_module="Proxy",
call_function="remove_proxy",
call_params={
"proxy_type": proxy_type.value,
"delay": delay,
"delegate": delegate,
},
)

return await submit_proxy(
subtensor=subtensor,
wallet=wallet,
Expand Down
16 changes: 10 additions & 6 deletions bittensor_cli/src/commands/stake/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ def create_table(
root_stakes = [s for s in substakes_ if s.netuid == 0]
other_stakes = sorted(
[s for s in substakes_ if s.netuid != 0],
key=lambda x: dynamic_info[x.netuid]
.alpha_to_tao(Balance.from_rao(int(x.stake.rao)).set_unit(x.netuid))
.tao,
key=lambda x: (
dynamic_info[x.netuid]
.alpha_to_tao(Balance.from_rao(int(x.stake.rao)).set_unit(x.netuid))
.tao
),
reverse=True,
)
sorted_substakes = root_stakes + other_stakes
Expand Down Expand Up @@ -328,9 +330,11 @@ def format_cell(
root_stakes = [s for s in substakes if s.netuid == 0]
other_stakes = sorted(
[s for s in substakes if s.netuid != 0],
key=lambda x: dynamic_info_for_lt[x.netuid]
.alpha_to_tao(Balance.from_rao(int(x.stake.rao)).set_unit(x.netuid))
.tao,
key=lambda x: (
dynamic_info_for_lt[x.netuid]
.alpha_to_tao(Balance.from_rao(int(x.stake.rao)).set_unit(x.netuid))
.tao
),
reverse=True,
)
sorted_substakes = root_stakes + other_stakes
Expand Down
Loading
Loading