Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 92 additions & 28 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9449,13 +9449,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 Down Expand Up @@ -9487,41 +9492,100 @@ def proxy_remove(
[green]$[/green] btcli proxy remove --all

"""
# 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"
)
self.verbosity_handler(quiet, verbose, json_output, prompt)
wallet = self.wallet_ask(
wallet_name=wallet_name,
wallet_path=wallet_path,
wallet_hotkey=wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
validate=WV.WALLET,
)
return self._run_command(
proxy_commands.remove_proxy(
subtensor=self.initialize_chain(network),
wallet=wallet,
delegate=delegate,
proxy_type=proxy_type,
delay=delay,
prompt=prompt,
decline=decline,
quiet=quiet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
json_output=json_output,
# Validate that either delegate is provided or --all is used
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 is used, delegate and proxy_type/delay should not be required
if all:
if delegate:
if not json_output:
console.print(
"[yellow]Warning: --delegate is ignored when --all flag is used.[/yellow]"
)
self.verbosity_handler(quiet, verbose, json_output, prompt)
wallet = self.wallet_ask(
wallet_name=wallet_name,
wallet_path=wallet_path,
wallet_hotkey=wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
validate=WV.WALLET,
)
return self._run_command(
proxy_commands.remove_proxies(
subtensor=self.initialize_chain(network),
wallet=wallet,
prompt=prompt,
decline=decline,
quiet=quiet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
json_output=json_output,
)
)
else:
# Single proxy removal - delegate is required
if not delegate:
if not json_output:
print_error("--delegate is required when --all flag is not used.")
else:
json_console.print_json(
data={
"success": False,
"message": "--delegate is required when --all flag is not used.",
"extrinsic_identifier": None,
}
)
return

self.verbosity_handler(quiet, verbose, json_output, prompt)
wallet = self.wallet_ask(
wallet_name=wallet_name,
wallet_path=wallet_path,
wallet_hotkey=wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
validate=WV.WALLET,
)
return self._run_command(
proxy_commands.remove_proxy(
subtensor=self.initialize_chain(network),
wallet=wallet,
delegate=delegate,
proxy_type=proxy_type,
delay=delay,
prompt=prompt,
decline=decline,
quiet=quiet,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
json_output=json_output,
)
)
)

def proxy_kill(
self,
Expand Down
53 changes: 52 additions & 1 deletion bittensor_cli/src/commands/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def remove_proxy(
"""
if prompt:
if not confirm_action(
f"This will remove a proxy of type {proxy_type.value} for delegate {delegate}."
f"This will remove a proxy of type {proxy_type.value} for delegate {delegate}. "
f"Do you want to proceed?",
decline=decline,
quiet=quiet,
Expand Down Expand Up @@ -309,6 +309,57 @@ async def remove_proxy(
)


async def remove_proxies(
subtensor: "SubtensorInterface",
wallet: "Wallet",
prompt: bool,
decline: bool,
quiet: bool,
wait_for_inclusion: bool,
wait_for_finalization: bool,
period: int,
json_output: bool,
) -> None:
"""
Executes the remove_proxies call on the chain to remove all proxies for the account
"""
if prompt:
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
if not (ulw := unlock_key(wallet, print_out=not json_output)).success:
if not json_output:
print_error(ulw.message)
else:
json_console.print_json(
data={
"success": ulw.success,
"message": ulw.message,
"extrinsic_identifier": None,
}
)
return None
call = await subtensor.substrate.compose_call(
call_module="Proxy",
call_function="remove_proxies",
call_params={},
)
return await submit_proxy(
subtensor=subtensor,
wallet=wallet,
call=call,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
period=period,
json_output=json_output,
)


async def add_proxy(
subtensor: "SubtensorInterface",
wallet: "Wallet",
Expand Down
Loading
Loading