Skip to content

Commit

Permalink
feat: allow minting after expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 31, 2024
1 parent 661a6a1 commit 93e91d2
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions crates/cdk/src/mint/mint_nut04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,29 @@ impl Mint {
.get_mint_quote_by_request_lookup_id(request_lookup_id)
.await
{
tracing::debug!(
"Quote {} paid by lookup id {}",
mint_quote.id,
request_lookup_id
);
self.localstore
.update_mint_quote_state(&mint_quote.id, MintQuoteState::Paid)
.await?;
if mint_quote.state != MintQuoteState::Issued {
tracing::debug!(
"Quote {} paid by lookup id {}",
mint_quote.id,
request_lookup_id
);

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));
}

self.localstore
.update_mint_quote_state(&mint_quote.id, MintQuoteState::Paid)
.await?;
}
}
Ok(())
}
Expand All @@ -218,16 +233,13 @@ impl Mint {
&self,
mint_request: nut04::MintBolt11Request,
) -> Result<nut04::MintBolt11Response, Error> {
// 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
Expand Down

0 comments on commit 93e91d2

Please sign in to comment.