Browse Source

fix: check melt quote in ffi (#1340)

tsk 2 months ago
parent
commit
681f7082c3
2 changed files with 41 additions and 1 deletions
  1. 14 0
      crates/cdk-ffi/src/multi_mint_wallet.rs
  2. 27 1
      crates/cdk/src/wallet/multi_mint_wallet.rs

+ 14 - 0
crates/cdk-ffi/src/multi_mint_wallet.rs

@@ -442,6 +442,20 @@ impl MultiMintWallet {
         Ok(melted.into())
     }
 
+    /// Check melt quote status
+    pub async fn check_melt_quote(
+        &self,
+        mint_url: MintUrl,
+        quote_id: String,
+    ) -> Result<MeltQuote, FfiError> {
+        let cdk_mint_url: cdk::mint_url::MintUrl = mint_url.try_into()?;
+        let melted = self
+            .inner
+            .check_melt_quote(&cdk_mint_url, &quote_id)
+            .await?;
+        Ok(melted.into())
+    }
+
     /// Melt tokens (pay a bolt11 invoice)
     pub async fn melt(
         &self,

+ 27 - 1
crates/cdk/src/wallet/multi_mint_wallet.rs

@@ -12,7 +12,7 @@ use anyhow::Result;
 use cdk_common::database;
 use cdk_common::database::WalletDatabase;
 use cdk_common::task::spawn;
-use cdk_common::wallet::{Transaction, TransactionDirection};
+use cdk_common::wallet::{MeltQuote, Transaction, TransactionDirection};
 use tokio::sync::RwLock;
 use tracing::instrument;
 use zeroize::Zeroize;
@@ -1299,6 +1299,32 @@ impl MultiMintWallet {
         wallet.melt(quote_id).await
     }
 
+    /// Check a specific melt quote status
+    #[instrument(skip(self))]
+    pub async fn check_melt_quote(
+        &self,
+        mint_url: &MintUrl,
+        quote_id: &str,
+    ) -> Result<MeltQuote, Error> {
+        let wallets = self.wallets.read().await;
+        let wallet = wallets.get(mint_url).ok_or(Error::UnknownMint {
+            mint_url: mint_url.to_string(),
+        })?;
+
+        // Check the quote state from the mint
+        wallet.melt_quote_status(quote_id).await?;
+
+        // Get the updated quote from local storage
+        let quote = wallet
+            .localstore
+            .get_melt_quote(quote_id)
+            .await
+            .map_err(Error::Database)?
+            .ok_or(Error::UnknownQuote)?;
+
+        Ok(quote)
+    }
+
     /// Create MPP (Multi-Path Payment) melt quotes from multiple mints
     ///
     /// This function allows manual specification of which mints and amounts to use for MPP.