From ca3444939edddb9e57f480c0bc0bc8124d9f5aa1 Mon Sep 17 00:00:00 2001 From: David Caseria Date: Thu, 2 Oct 2025 07:24:36 -0400 Subject: [PATCH] Add MultiMintWallet check and wait for mint quotes (#1146) * Add MultiMintWallet check and wait for mint quotes --- crates/cdk-ffi/src/multi_mint_wallet.rs | 40 +++++++++++++++ crates/cdk/src/wallet/multi_mint_wallet.rs | 57 ++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/crates/cdk-ffi/src/multi_mint_wallet.rs b/crates/cdk-ffi/src/multi_mint_wallet.rs index 6fc72af9..f63a56fe 100644 --- a/crates/cdk-ffi/src/multi_mint_wallet.rs +++ b/crates/cdk-ffi/src/multi_mint_wallet.rs @@ -227,6 +227,20 @@ impl MultiMintWallet { Ok(quote.into()) } + /// Check a specific mint quote status + pub async fn check_mint_quote( + &self, + mint_url: MintUrl, + quote_id: String, + ) -> Result { + let cdk_mint_url: cdk::mint_url::MintUrl = mint_url.try_into()?; + let quote = self + .inner + .check_mint_quote(&cdk_mint_url, "e_id) + .await?; + Ok(quote.into()) + } + /// Mint tokens at a specific mint pub async fn mint( &self, @@ -244,6 +258,32 @@ impl MultiMintWallet { Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) } + /// Wait for a mint quote to be paid and automatically mint the proofs + #[cfg(not(target_arch = "wasm32"))] + pub async fn wait_for_mint_quote( + &self, + mint_url: MintUrl, + quote_id: String, + split_target: SplitTarget, + spending_conditions: Option, + timeout_secs: u64, + ) -> Result { + let cdk_mint_url: cdk::mint_url::MintUrl = mint_url.try_into()?; + let conditions = spending_conditions.map(|sc| sc.try_into()).transpose()?; + + let proofs = self + .inner + .wait_for_mint_quote( + &cdk_mint_url, + "e_id, + split_target.into(), + conditions, + timeout_secs, + ) + .await?; + Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) + } + /// Get a melt quote from a specific mint pub async fn melt_quote( &self, diff --git a/crates/cdk/src/wallet/multi_mint_wallet.rs b/crates/cdk/src/wallet/multi_mint_wallet.rs index ad34a459..125a4eb2 100644 --- a/crates/cdk/src/wallet/multi_mint_wallet.rs +++ b/crates/cdk/src/wallet/multi_mint_wallet.rs @@ -741,6 +741,32 @@ impl MultiMintWallet { wallet.mint_quote(amount, description).await } + /// Check a specific mint quote status + #[instrument(skip(self))] + pub async fn check_mint_quote( + &self, + mint_url: &MintUrl, + quote_id: &str, + ) -> Result { + 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.mint_quote_state(quote_id).await?; + + // Get the updated quote from local storage + let quote = wallet + .localstore + .get_mint_quote(quote_id) + .await + .map_err(Error::Database)? + .ok_or(Error::UnknownQuote)?; + + Ok(quote) + } + /// Check all mint quotes /// If quote is paid, wallet will mint #[instrument(skip(self))] @@ -784,6 +810,37 @@ impl MultiMintWallet { .await } + /// Wait for a mint quote to be paid and automatically mint the proofs + #[cfg(not(target_arch = "wasm32"))] + #[instrument(skip(self))] + pub async fn wait_for_mint_quote( + &self, + mint_url: &MintUrl, + quote_id: &str, + split_target: SplitTarget, + conditions: Option, + timeout_secs: u64, + ) -> Result { + let wallets = self.wallets.read().await; + let wallet = wallets.get(mint_url).ok_or(Error::UnknownMint { + mint_url: mint_url.to_string(), + })?; + + // Get the mint quote from local storage + let quote = wallet + .localstore + .get_mint_quote(quote_id) + .await + .map_err(Error::Database)? + .ok_or(Error::UnknownQuote)?; + + // Wait for the quote to be paid and mint the proofs + let timeout_duration = tokio::time::Duration::from_secs(timeout_secs); + wallet + .wait_and_mint_quote(quote, split_target, conditions, timeout_duration) + .await + } + /// Receive token with multi-mint options /// /// This method can: