mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-23 19:54:18 +01:00
add cli decode + fix crash when mint is offline (#709)
This commit is contained in:
@@ -922,6 +922,9 @@ class Token(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def unit(self, unit: str): ...
|
def unit(self, unit: str): ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def serialize_to_dict(self, include_dleq: bool): ...
|
||||||
|
|
||||||
|
|
||||||
class TokenV3Token(BaseModel):
|
class TokenV3Token(BaseModel):
|
||||||
mint: Optional[str] = None
|
mint: Optional[str] = None
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import getpass
|
import getpass
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
@@ -760,6 +761,26 @@ async def receive_cli(
|
|||||||
return
|
return
|
||||||
await print_balance(ctx)
|
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.")
|
@cli.command("burn", help="Burn spent tokens.")
|
||||||
@click.argument("token", required=False, type=str)
|
@click.argument("token", required=False, type=str)
|
||||||
|
|||||||
@@ -400,12 +400,12 @@ class Wallet(
|
|||||||
Defaults to False.
|
Defaults to False.
|
||||||
"""
|
"""
|
||||||
logger.trace(f"Loading mint {self.url}")
|
logger.trace(f"Loading mint {self.url}")
|
||||||
|
try:
|
||||||
await self.load_mint_keysets(force_old_keysets)
|
await self.load_mint_keysets(force_old_keysets)
|
||||||
await self.activate_keyset(keyset_id)
|
await self.activate_keyset(keyset_id)
|
||||||
try:
|
|
||||||
await self.load_mint_info(reload=True)
|
await self.load_mint_info(reload=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Could not load mint info: {e}")
|
logger.error(f"Could not load mint info: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def load_proofs(self, reload: bool = False, all_keysets=False) -> None:
|
async def load_proofs(self, reload: bool = False, all_keysets=False) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user