From 29f789b8553301e21bd1ed188194052f2ef382ac Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 16 Mar 2024 18:31:19 +0100 Subject: [PATCH 1/2] use lowerstr melt quote --- cashu/mint/ledger.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 8f8a2316..8713ad6f 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -469,6 +469,7 @@ async def melt_quote( """ unit = Unit[melt_quote.unit] method = Method.bolt11 + request = melt_quote.request.lower() invoice_obj = bolt11.decode(melt_quote.request) assert invoice_obj.amount_msat, "invoice has no amount." @@ -476,7 +477,7 @@ async def melt_quote( # so that we can handle the transaction internally without lightning # and respond with zero fees mint_quote = await self.crud.get_mint_quote_by_request( - request=melt_quote.request, db=self.db + request=request, db=self.db ) if mint_quote: # internal transaction, validate and return amount from @@ -485,9 +486,7 @@ async def melt_quote( Amount(unit, mint_quote.amount).to(Unit.msat).amount == invoice_obj.amount_msat ), "amounts do not match" - assert ( - melt_quote.request == mint_quote.request - ), "bolt11 requests do not match" + assert request == mint_quote.request, "bolt11 requests do not match" assert mint_quote.unit == melt_quote.unit, "units do not match" assert mint_quote.method == method.name, "methods do not match" assert not mint_quote.paid, "mint quote already paid" @@ -499,14 +498,12 @@ async def melt_quote( fee=Amount(unit=Unit.msat, amount=0), ) logger.info( - f"Issuing internal melt quote: {melt_quote.request} ->" + f"Issuing internal melt quote: {request} ->" f" {mint_quote.quote} ({mint_quote.amount} {mint_quote.unit})" ) else: # not internal, get quote by backend - payment_quote = await self.backends[method][unit].get_payment_quote( - melt_quote.request - ) + payment_quote = await self.backends[method][unit].get_payment_quote(request) assert payment_quote.checking_id, "quote has no checking id" expiry = None @@ -516,9 +513,9 @@ async def melt_quote( quote = MeltQuote( quote=random_hash(), method=method.name, - request=melt_quote.request, + request=request, checking_id=payment_quote.checking_id, - unit=melt_quote.unit, + unit=unit.name, amount=payment_quote.amount.to(unit).amount, paid=False, fee_reserve=payment_quote.fee.to(unit).amount, From d2799581ca63802f26c89247c2c1834a997b30d1 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 16 Mar 2024 18:37:13 +0100 Subject: [PATCH 2/2] case insensitive melt quotes --- cashu/mint/ledger.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 8713ad6f..3bb0cb8a 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -348,6 +348,10 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote: # get invoice expiry time invoice_obj = bolt11.decode(invoice_response.payment_request) + # NOTE: we normalize the request to lowercase to avoid case sensitivity + # This works with Lightning but might not work with other methods + request = invoice_response.payment_request.lower() + expiry = None if invoice_obj.expiry is not None: expiry = invoice_obj.date + invoice_obj.expiry @@ -355,7 +359,7 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote: quote = MintQuote( quote=random_hash(), method=method.name, - request=invoice_response.payment_request, + request=request, checking_id=invoice_response.checking_id, unit=quote_request.unit, amount=quote_request.amount, @@ -469,6 +473,8 @@ async def melt_quote( """ unit = Unit[melt_quote.unit] method = Method.bolt11 + # NOTE: we normalize the request to lowercase to avoid case sensitivity + # This works with Lightning but might not work with other methods request = melt_quote.request.lower() invoice_obj = bolt11.decode(melt_quote.request) assert invoice_obj.amount_msat, "invoice has no amount."