Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI Decode Command #709

Merged
merged 1 commit into from
Mar 4, 2025
Merged
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
3 changes: 3 additions & 0 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ def unit(self) -> str: ...
@abstractmethod
def unit(self, unit: str): ...

@abstractmethod
def serialize_to_dict(self, include_dleq: bool): ...


class TokenV3Token(BaseModel):
mint: Optional[str] = None
Expand Down
21 changes: 21 additions & 0 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import getpass
import json
import os
import time
from datetime import datetime, timezone
Expand Down Expand Up @@ -760,6 +761,26 @@ async def receive_cli(
return
await print_balance(ctx)

@cli.command("decode", help="Decode a cashu token and print in JSON format.")
@click.option(
"--no-dleq", default=False, is_flag=True, help="Do not include DLEQ proofs."
)
@click.option(
"--indent", "-i", default=2, is_flag=False, help="Number of spaces to indent JSON with."
)
@click.argument("token", type=str, default="")
def decode_to_json(token: str, no_dleq: bool, indent: int):
include_dleq = not no_dleq
if token:
token_obj = deserialize_token_from_string(token)
token_json = json.dumps(
token_obj.serialize_to_dict(include_dleq),
default=lambda obj: obj.hex() if isinstance(obj, bytes) else obj,
indent=indent,
)
print(token_json)
else:
print("Error: enter a token")

@cli.command("burn", help="Burn spent tokens.")
@click.argument("token", required=False, type=str)
Expand Down
6 changes: 3 additions & 3 deletions cashu/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ async def load_mint(self, keyset_id: str = "", force_old_keysets=False) -> None:
Defaults to False.
"""
logger.trace(f"Loading mint {self.url}")
await self.load_mint_keysets(force_old_keysets)
await self.activate_keyset(keyset_id)
try:
await self.load_mint_keysets(force_old_keysets)
await self.activate_keyset(keyset_id)
await self.load_mint_info(reload=True)
except Exception as e:
logger.debug(f"Could not load mint info: {e}")
logger.error(f"Could not load mint info: {e}")
pass

async def load_proofs(self, reload: bool = False, all_keysets=False) -> None:
Expand Down
Loading