mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-04 12:45:55 +01:00
Add MultiMintWallet check and wait for mint quotes (#1146)
* Add MultiMintWallet check and wait for mint quotes
This commit is contained in:
@@ -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<MintQuote, FfiError> {
|
||||
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<SpendingConditions>,
|
||||
timeout_secs: u64,
|
||||
) -> Result<Proofs, FfiError> {
|
||||
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,
|
||||
|
||||
@@ -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<MintQuote, 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.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<SpendingConditions>,
|
||||
timeout_secs: u64,
|
||||
) -> Result<Proofs, Error> {
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user