Skip to content

Commit

Permalink
fix: mint and melt quote expiry time (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid authored Mar 14, 2024
1 parent f4777aa commit 6cb967f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 10 additions & 2 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6cb967f

Please sign in to comment.