-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CLI): add support for viewing and modifying delegates
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import click | ||
from ape.cli import ConnectedProviderCommand | ||
from ape.types import AddressType | ||
from eth_typing import ChecksumAddress | ||
|
||
from ape_safe._cli.click_ext import callback_factory, safe_argument, safe_cli_ctx, safe_option | ||
|
||
|
||
@click.group() | ||
def delegates(): | ||
""" | ||
Commands for viewing and configuring delegates thru the configured Safe API | ||
""" | ||
|
||
|
||
@delegates.command("list", cls=ConnectedProviderCommand) | ||
@safe_cli_ctx() | ||
@safe_argument | ||
def _list(cli_ctx, safe): | ||
""" | ||
Show delegates for signers in a Safe | ||
""" | ||
if delegates := safe.client.get_delegates(): | ||
cli_ctx.logger.success(f"Found delegates for {safe.address} ({safe.alias})") | ||
for delegator in delegates: | ||
click.echo(f"\nSigner {delegator}:") | ||
click.echo("- " + "\n- ".join(delegates[delegator])) | ||
|
||
else: | ||
cli_ctx.logger.error(f"No delegates for {safe.address} ({safe.alias})") | ||
|
||
|
||
@delegates.command(cls=ConnectedProviderCommand) | ||
@safe_cli_ctx() | ||
@safe_option | ||
@click.argument("delegate", type=ChecksumAddress) | ||
@click.argument("label") | ||
@click.argument("signer", callback=callback_factory.submitter_callback) | ||
def add(cli_ctx, safe, delegate, label, signer): | ||
""" | ||
Add a delegate for a specific signer in a Safe | ||
""" | ||
delegate = cli_ctx.conversion_manager.convert(delegate, AddressType) | ||
safe.client.add_delegate(delegate, label, signer) | ||
|
||
|
||
@delegates.command(cls=ConnectedProviderCommand) | ||
@safe_cli_ctx() | ||
@safe_option | ||
@click.argument("delegate", type=ChecksumAddress) | ||
@click.argument("signer", callback=callback_factory.submitter_callback) | ||
def remove(cli_ctx, safe, delegate, signer): | ||
""" | ||
Remove a delegate for a specific signer in a Safe | ||
""" | ||
delegate = cli_ctx.conversion_manager.convert(delegate, AddressType) | ||
safe.client.remove_delegate(delegate, signer) |