Kaynağa Gözat

feat: update mint state

thesimplekid 8 ay önce
ebeveyn
işleme
de47ad9ac1
2 değiştirilmiş dosya ile 18 ekleme ve 2 silme
  1. 17 2
      crates/cdk/src/mint/mod.rs
  2. 1 0
      crates/cdk/src/nuts/nut04.rs

+ 17 - 2
crates/cdk/src/mint/mod.rs

@@ -148,11 +148,18 @@ impl Mint {
 
         let paid = quote.state == MintQuoteState::Paid;
 
+        // Since the pending state is not part of the NUT it should not be part of the response.
+        // In practice the wallet should not be checking the state of a quote while waiting for the mint response.
+        let state = match quote.state {
+            MintQuoteState::Pending => MintQuoteState::Paid,
+            s => s,
+        };
+
         Ok(MintQuoteBolt11Response {
             quote: quote.id,
             request: quote.request,
             paid: Some(paid),
-            state: quote.state,
+            state,
             expiry: Some(quote.expiry),
         })
     }
@@ -354,10 +361,18 @@ impl Mint {
                 .await?
                 .is_some()
             {
-                tracing::error!(
+                tracing::info!(
                     "Output has already been signed: {}",
                     blinded_message.blinded_secret
                 );
+                tracing::info!(
+                    "Mint {} did not succeed returning quote to Paid state",
+                    mint_request.quote
+                );
+
+                self.localstore
+                    .update_mint_quote_state(&mint_request.quote, MintQuoteState::Paid)
+                    .await?;
                 return Err(Error::BlindedMessageAlreadySigned);
             }
         }

+ 1 - 0
crates/cdk/src/nuts/nut04.rs

@@ -40,6 +40,7 @@ pub enum QuoteState {
     /// Quote has been paid and wallet can mint
     Paid,
     /// Minting is in progress
+    /// **Note:** This state is to be used internally but is not part of the nut.
     Pending,
     /// ecash issued for quote
     Issued,