From 6cb967fc026dcbce9389be2336ff1493022bcb03 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Thu, 14 Mar 2024 11:17:42 +0000 Subject: [PATCH] fix: mint and melt quote expiry time (#453) --- cashu/mint/ledger.py | 12 ++++++++++-- tests/test_mint_api.py | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 532df73f..1849d3cb 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -343,6 +343,10 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote: # get invoice expiry time invoice_obj = bolt11.decode(invoice_response.payment_request) + expiry = None + if invoice_obj.expiry is not None: + expiry = invoice_obj.date + invoice_obj.expiry + quote = MintQuote( quote=random_hash(), method=method.name, @@ -353,7 +357,7 @@ async def mint_quote(self, quote_request: PostMintQuoteRequest) -> MintQuote: issued=False, paid=False, created_time=int(time.time()), - expiry=invoice_obj.expiry, + expiry=expiry, ) await self.crud.store_mint_quote( quote=quote, @@ -499,6 +503,10 @@ async def melt_quote( melt_quote.request ) assert payment_quote.checking_id, "quote has no checking id" + + expiry = None + if invoice_obj.expiry is not None: + expiry = invoice_obj.date + invoice_obj.expiry quote = MeltQuote( quote=random_hash(), @@ -510,7 +518,7 @@ async def melt_quote( paid=False, fee_reserve=payment_quote.fee.to(unit).amount, created_time=int(time.time()), - expiry=invoice_obj.expiry, + expiry=expiry, ) await self.crud.store_melt_quote(quote=quote, db=self.db) return PostMeltQuoteResponse( diff --git a/tests/test_mint_api.py b/tests/test_mint_api.py index 6685af30..5a571416 100644 --- a/tests/test_mint_api.py +++ b/tests/test_mint_api.py @@ -183,7 +183,12 @@ async def test_mint_quote(ledger: Ledger): assert result["request"] invoice = bolt11.decode(result["request"]) assert invoice.amount_msat == 100 * 1000 - assert result["expiry"] == invoice.expiry + + expiry = None + if invoice.expiry is not None: + expiry = invoice.date + invoice.expiry + + assert result["expiry"] == expiry # get mint quote again from api response = httpx.get( @@ -246,7 +251,12 @@ async def test_melt_quote_internal(ledger: Ledger, wallet: Wallet): # TODO: internal invoice, fee should be 0 assert result["fee_reserve"] == 0 invoice_obj = bolt11.decode(request) - assert result["expiry"] == invoice_obj.expiry + + expiry = None + if invoice_obj.expiry is not None: + expiry = invoice_obj.date + invoice_obj.expiry + + assert result["expiry"] == expiry # get melt quote again from api response = httpx.get(