Skip to content

Commit 89dc06d

Browse files
committed
Feature: new command aleph account vouchers to display Vouchers info for address
1 parent 72fd20a commit 89dc06d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/aleph_client/commands/account.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from aleph.sdk.utils import bytes_from_hex, displayable_amount
2727
from aleph_message.models import Chain
28+
from rich import box
2829
from rich.console import Console
2930
from rich.panel import Panel
3031
from rich.prompt import Prompt
@@ -406,6 +407,64 @@ async def list_accounts():
406407
console.print(table)
407408

408409

410+
@app.command(name="vouchers")
411+
async def vouchers(
412+
address: Annotated[Optional[str], typer.Option(help="Address")] = None,
413+
private_key: Annotated[Optional[str], typer.Option(help=help_strings.PRIVATE_KEY)] = settings.PRIVATE_KEY_STRING,
414+
private_key_file: Annotated[
415+
Optional[Path], typer.Option(help=help_strings.PRIVATE_KEY_FILE)
416+
] = settings.PRIVATE_KEY_FILE,
417+
chain: Annotated[Optional[Chain], typer.Option(help=help_strings.ADDRESS_CHAIN)] = None,
418+
):
419+
"""Display detailed information about your vouchers."""
420+
account = _load_account(private_key, private_key_file, chain=chain)
421+
422+
if account and not address:
423+
address = account.get_address()
424+
425+
voucher_manager = VoucherManager(account=account, chain=chain)
426+
427+
if address:
428+
try:
429+
vouchers = await voucher_manager.get_all(address=address)
430+
if vouchers:
431+
voucher_table = Table(title="", show_header=True, box=box.ROUNDED)
432+
voucher_table.add_column("Name", style="bright_cyan")
433+
voucher_table.add_column("Description", style="green")
434+
voucher_table.add_column("Attributes", style="magenta")
435+
436+
for voucher in vouchers:
437+
attr_text = ""
438+
for attr in voucher.attributes:
439+
attr_text += f"{attr.trait_type}: {attr.value}\n"
440+
441+
voucher_table.add_row(voucher.name, voucher.description, attr_text.strip())
442+
443+
console.print(
444+
Panel(
445+
voucher_table,
446+
title="Vouchers",
447+
border_style="bright_cyan",
448+
expand=False,
449+
title_align="left",
450+
)
451+
)
452+
else:
453+
console.print(
454+
Panel(
455+
"No vouchers found for this address",
456+
title="Vouchers",
457+
border_style="bright_cyan",
458+
expand=False,
459+
title_align="left",
460+
)
461+
)
462+
except Exception as e:
463+
typer.echo(e)
464+
else:
465+
typer.echo("Error: Please provide either a private key, private key file, or an address.")
466+
467+
409468
@app.command(name="config")
410469
async def configure(
411470
private_key_file: Annotated[Optional[Path], typer.Option(help="New path to the private key file")] = None,

0 commit comments

Comments
 (0)