|
25 | 25 | )
|
26 | 26 | from aleph.sdk.utils import bytes_from_hex, displayable_amount
|
27 | 27 | from aleph_message.models import Chain
|
| 28 | +from rich import box |
28 | 29 | from rich.console import Console
|
29 | 30 | from rich.panel import Panel
|
30 | 31 | from rich.prompt import Prompt
|
@@ -406,6 +407,64 @@ async def list_accounts():
|
406 | 407 | console.print(table)
|
407 | 408 |
|
408 | 409 |
|
| 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 | + |
409 | 468 | @app.command(name="config")
|
410 | 469 | async def configure(
|
411 | 470 | private_key_file: Annotated[Optional[Path], typer.Option(help="New path to the private key file")] = None,
|
|
0 commit comments