Skip to content

Commit

Permalink
receive pending from all mints and catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jul 11, 2024
1 parent 2c469cf commit f87106b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,9 @@ async def pending(ctx: Context, legacy, number: int, offset: int):
)
print(f"Legacy token: {token_legacy}\n")
print("--------------------------\n")
print("To remove all spent tokens use: cashu burn -a")
print("To remove all pending tokens that are already spent use: cashu burn -a")
print("To remove a specific pending token use: cashu burn <token>")
print("To receive all pending tokens use: cashu receive -a")


@cli.command("lock", help="Generate receiving lock.")
Expand Down
13 changes: 8 additions & 5 deletions cashu/wallet/cli/cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from click import Context
from loguru import logger

from ...core.base import TokenV4, Unit
from ...core.base import Unit
from ...core.settings import settings
from ...wallet.crud import (
get_keysets,
get_reserved_proofs,
)
from ...wallet.wallet import Wallet as Wallet
from ..helpers import (
deserialize_token_from_string,
receive,
)

Expand Down Expand Up @@ -193,23 +194,25 @@ async def receive_all_pending(ctx: Context, wallet: Wallet):
proofs = list(value)
mint_url, unit = await wallet._get_proofs_mint_unit(proofs)
mint_wallet = await Wallet.with_db(
mint_url,
os.path.join(settings.cashu_dir, wallet.name),
url=mint_url,
db=os.path.join(settings.cashu_dir, wallet.name),
name=wallet.name,
unit=unit.name,
)
# verify that we trust the mint of this token
# ask the user if they want to trust the mint
await verify_mint(mint_wallet, mint_url)

token = await mint_wallet.serialize_proofs(proofs)
token_obj = TokenV4.deserialize(token)
token_obj = deserialize_token_from_string(token)
mint_url = token_obj.mint
receive_wallet = await receive(mint_wallet, token_obj)
ctx.obj["WALLET"] = receive_wallet
except Exception as e:
if mint_url and token_obj:
unit = Unit[token_obj.unit]
print(
f"Could not receive {token_obj.amount} from mint {mint_url}: {str(e)}"
f"Could not receive {unit.str(token_obj.amount)} from mint {mint_url}: {str(e)}"
)
else:
print(f"Could not receive token: {str(e)}")
Expand Down

0 comments on commit f87106b

Please sign in to comment.