Skip to content

Commit

Permalink
use specific keyset for returned change (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc authored Oct 29, 2023
1 parent 48f732e commit 22e0ad4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ async def mint(
return promises

async def melt(
self, proofs: List[Proof], invoice: str, outputs: Optional[List[BlindedMessage]]
self,
proofs: List[Proof],
invoice: str,
outputs: Optional[List[BlindedMessage]],
keyset: Optional[MintKeyset] = None,
) -> Tuple[bool, str, List[BlindedSignature]]:
"""Invalidates proofs and pays a Lightning invoice.
Expand Down Expand Up @@ -386,6 +390,7 @@ async def melt(
invoice_amount=invoice_amount,
ln_fee_msat=payment.fee_msat,
outputs=outputs,
keyset=keyset,
)

except Exception as e:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,17 @@ async def test_melt(wallet1: Wallet):
assert fee_reserve_sat == 2
_, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount)

await wallet1.pay_lightning(
melt_response = await wallet1.pay_lightning(
send_proofs, invoice=invoice.bolt11, fee_reserve_sat=fee_reserve_sat
)

assert melt_response.change
assert len(melt_response.change) == 1
# NOTE: we assume that we will get a token back from the same keyset as the ones we melted
# this could be wrong if we melted tokens from an old keyset but the returned ones are
# from a newer one.
assert melt_response.change[0].id == send_proofs[0].id

# verify that proofs in proofs_used db have the same melt_id as the invoice in the db
assert invoice.payment_hash
invoice_db = await get_lightning_invoice(
Expand Down

0 comments on commit 22e0ad4

Please sign in to comment.