Skip to content

Commit 220c2a0

Browse files
committed
feat(ffi): expose mint_unissued_quotes
1 parent 7c1ed40 commit 220c2a0

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

crates/cdk-common/src/wallet/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@ pub trait Wallet: Send + Sync {
995995
spending_conditions: Option<SpendingConditions>,
996996
) -> Result<Proofs, Self::Error>;
997997

998+
/// Check and mint any paid but unissued mint quotes
999+
async fn mint_unissued_quotes(&self) -> Result<Self::Amount, Self::Error>;
1000+
9981001
/// Check mint quote status
9991002
async fn check_mint_quote_status(&self, quote_id: &str)
10001003
-> Result<Self::MintQuote, Self::Error>;

crates/cdk-ffi/src/wallet.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ impl Wallet {
345345
Ok(proofs.into_iter().map(|p| p.into()).collect())
346346
}
347347

348+
/// Check and mint any paid but unissued mint quotes.
349+
///
350+
/// This is useful during startup or recovery after incomplete mint quote flows.
351+
/// It may perform network requests and write newly issued proofs to the wallet store.
352+
pub async fn mint_unissued_quotes(&self) -> Result<Amount, FfiError> {
353+
let minted = self.inner.mint_unissued_quotes().await?;
354+
Ok(minted.into())
355+
}
356+
348357
/// Prepare a melt operation
349358
///
350359
/// Returns a `PreparedMelt` that can be confirmed or cancelled.
@@ -925,3 +934,44 @@ pub fn mnemonic_to_entropy(mnemonic: String) -> Result<Vec<u8>, FfiError> {
925934
.map_err(|e| FfiError::internal(format!("Invalid mnemonic: {}", e)))?;
926935
Ok(m.to_entropy())
927936
}
937+
938+
#[cfg(test)]
939+
mod tests {
940+
use cdk_common::wallet::Wallet as WalletTrait;
941+
942+
use crate::database::custom_wallet_store;
943+
use crate::sqlite::WalletSqliteDatabase;
944+
945+
use super::*;
946+
947+
fn test_wallet() -> Wallet {
948+
let db = WalletSqliteDatabase::new_in_memory().expect("in-memory wallet db should open");
949+
Wallet::new(
950+
"https://mint.example.com".to_string(),
951+
CurrencyUnit::Sat,
952+
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
953+
.to_string(),
954+
custom_wallet_store(db),
955+
WalletConfig {
956+
target_proof_count: None,
957+
},
958+
)
959+
.expect("wallet should be created")
960+
}
961+
962+
#[tokio::test(flavor = "multi_thread")]
963+
async fn mint_unissued_quotes_is_available_on_wallet_and_trait() {
964+
let wallet = test_wallet();
965+
966+
let minted = wallet
967+
.mint_unissued_quotes()
968+
.await
969+
.expect("empty quote store should mint zero");
970+
assert!(minted.is_zero());
971+
972+
let trait_minted = <Wallet as WalletTrait>::mint_unissued_quotes(&wallet)
973+
.await
974+
.expect("trait call should mint zero from empty quote store");
975+
assert!(trait_minted.is_zero());
976+
}
977+
}

crates/cdk-ffi/src/wallet_trait.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ impl WalletTraitDef for Wallet {
286286
Ok(proofs)
287287
}
288288

289+
async fn mint_unissued_quotes(&self) -> Result<Self::Amount, Self::Error> {
290+
let amount = WalletTraitDef::mint_unissued_quotes(self.inner().as_ref()).await?;
291+
Ok(amount.into())
292+
}
293+
289294
async fn check_mint_quote_status(
290295
&self,
291296
quote_id: &str,

crates/cdk/src/wallet/wallet_trait.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ impl WalletTrait for super::Wallet {
240240
self.mint(quote_id, split_target, spending_conditions).await
241241
}
242242

243+
#[instrument(skip(self))]
244+
async fn mint_unissued_quotes(&self) -> Result<Amount, Self::Error> {
245+
self.mint_unissued_quotes().await
246+
}
247+
243248
#[instrument(skip(self))]
244249
async fn check_mint_quote_status(&self, quote_id: &str) -> Result<MintQuote, Self::Error> {
245250
self.check_mint_quote_status(quote_id).await

0 commit comments

Comments
 (0)