From 30752f1e13767fff51eb4570a748c08a6eceeefc Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Wed, 30 Oct 2024 21:43:27 +0000 Subject: [PATCH] feat: allow minting after expiry --- crates/cdk/src/mint/mint_nut04.rs | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/cdk/src/mint/mint_nut04.rs b/crates/cdk/src/mint/mint_nut04.rs index 33e0c3240..e657fa806 100644 --- a/crates/cdk/src/mint/mint_nut04.rs +++ b/crates/cdk/src/mint/mint_nut04.rs @@ -205,9 +205,24 @@ impl Mint { mint_quote.id, request_lookup_id ); - self.localstore - .update_mint_quote_state(&mint_quote.id, MintQuoteState::Paid) - .await?; + + let unix_time = unix_time(); + + if mint_quote.expiry < unix_time { + tracing::warn!( + "Mint quote {} paid at {} expired at {}", + mint_quote.id, + mint_quote.expiry, + unix_time + ); + return Err(Error::ExpiredQuote(mint_quote.expiry, unix_time)); + } + + if mint_quote.state != MintQuoteState::Issued { + self.localstore + .update_mint_quote_state(&mint_quote.id, MintQuoteState::Paid) + .await?; + } } Ok(()) } @@ -218,16 +233,13 @@ impl Mint { &self, mint_request: nut04::MintBolt11Request, ) -> Result { - // Check quote is known and not expired - match self.localstore.get_mint_quote(&mint_request.quote).await? { - Some(quote) => { - if quote.expiry < unix_time() { - return Err(Error::ExpiredQuote(quote.expiry, unix_time())); - } - } - None => { - return Err(Error::UnknownQuote); - } + if self + .localstore + .get_mint_quote(&mint_request.quote) + .await? + .is_none() + { + return Err(Error::UnknownQuote); } let state = self