Cesar Rodas пре 5 дана
родитељ
комит
cb9737756d
2 измењених фајлова са 17 додато и 23 уклоњено
  1. 0 3
      crates/cdk/src/mint/issue/issue_nut04.rs
  2. 17 20
      crates/cdk/src/mint/melt.rs

+ 0 - 3
crates/cdk/src/mint/issue/issue_nut04.rs

@@ -279,9 +279,6 @@ impl Mint {
                 Ok(verification) => verification,
                 Err(err) => {
                     tracing::debug!("Could not verify mint outputs");
-                    tx.update_mint_quote_state(&mint_request.quote, MintQuoteState::Paid)
-                        .await?;
-                    tx.commit().await?;
                     return Err(err);
                 }
             };

+ 17 - 20
crates/cdk/src/mint/melt.rs

@@ -231,16 +231,6 @@ impl Mint {
         Ok(quotes)
     }
 
-    /// Remove melt quote
-    #[instrument(skip(self))]
-    pub async fn remove_melt_quote(&self, quote_id: &Uuid) -> Result<(), Error> {
-        let mut tx = self.localstore.begin_transaction().await?;
-        tx.remove_melt_quote(quote_id).await?;
-        tx.commit().await?;
-
-        Ok(())
-    }
-
     /// Check melt has expected fees
     #[instrument(skip_all)]
     pub async fn check_melt_expected_ln_fees(
@@ -435,10 +425,6 @@ impl Mint {
                 err
             })?;
 
-        tx.commit().await?;
-
-        let mut tx = self.localstore.begin_transaction().await?;
-
         let (preimage, amount_spent_quote_unit, quote) = match settled_internally_amount {
             Some(amount_spent) => (None, amount_spent, quote),
             None => {
@@ -482,12 +468,17 @@ impl Mint {
                         if pay.status == MeltQuoteState::Unknown
                             || pay.status == MeltQuoteState::Failed =>
                     {
-                        let check_response = check_payment_state(Arc::clone(ln), &quote)
-                            .await
-                            .map_err(|_| Error::Internal)?;
+                        let check_response =
+                            if let Ok(ok) = check_payment_state(Arc::clone(ln), &quote).await {
+                                ok
+                            } else {
+                                tx.commit().await?;
+                                return Err(Error::Internal);
+                            };
 
                         if check_response.status == MeltQuoteState::Paid {
                             tracing::warn!("Pay invoice returned {} but check returned {}. Proofs stuck as pending", pay.status.to_string(), check_response.status.to_string());
+                            tx.commit().await?;
 
                             return Err(Error::Internal);
                         }
@@ -505,12 +496,17 @@ impl Mint {
 
                         tracing::error!("Error returned attempting to pay: {} {}", quote.id, err);
 
-                        let check_response = check_payment_state(Arc::clone(ln), &quote)
-                            .await
-                            .map_err(|_| Error::Internal)?;
+                        let check_response =
+                            if let Ok(ok) = check_payment_state(Arc::clone(ln), &quote).await {
+                                ok
+                            } else {
+                                tx.commit().await?;
+                                return Err(Error::Internal);
+                            };
                         // If there error is something else we want to check the status of the payment ensure it is not pending or has been made.
                         if check_response.status == MeltQuoteState::Paid {
                             tracing::warn!("Pay invoice returned an error but check returned {}. Proofs stuck as pending", check_response.status.to_string());
+                            tx.commit().await?;
 
                             return Err(Error::Internal);
                         }
@@ -532,6 +528,7 @@ impl Mint {
                             "LN payment pending, proofs are stuck as pending for quote: {}",
                             melt_request.quote()
                         );
+                        tx.commit().await?;
                         return Err(Error::PendingQuote);
                     }
                 }