diff --git a/crates/cdk-rexie/src/wallet.rs b/crates/cdk-rexie/src/wallet.rs index 589e2e57..d406dc6c 100644 --- a/crates/cdk-rexie/src/wallet.rs +++ b/crates/cdk-rexie/src/wallet.rs @@ -64,15 +64,9 @@ impl RexieWalletDatabase { // Set the version of the database to 1.0 .version(DATABASE_VERSION) // Add an object store named `employees` + .add_object_store(ObjectStore::new(PROOFS).add_index(Index::new("y", "y").unique(true))) .add_object_store( - ObjectStore::new(PROOFS) - // Add an index named `email` with the key path `email` with unique enabled - .add_index(Index::new("y", "y").unique(true)), - ) - .add_object_store( - ObjectStore::new(MINTS) - // Add an index named `email` with the key path `email` with unique enabled - .add_index(Index::new("mint_url", "mint_url").unique(true)), + ObjectStore::new(MINTS).add_index(Index::new("mint_url", "mint_url").unique(true)), ) .add_object_store( ObjectStore::new(MINT_KEYSETS) @@ -82,22 +76,10 @@ impl RexieWalletDatabase { ObjectStore::new(MINT_KEYS) .add_index(Index::new("keyset_id", "keyset_id").unique(true)), ) - .add_object_store( - ObjectStore::new(MINT_QUOTES) - .add_index(Index::new("keyset_id", "keyset_id").unique(true)), - ) - .add_object_store( - ObjectStore::new(MELT_QUOTES) - .add_index(Index::new("keyset_id", "keyset_id").unique(true)), - ) - .add_object_store( - ObjectStore::new(CONFIG) - .add_index(Index::new("keyset_id", "keyset_id").unique(true)), - ) - .add_object_store( - ObjectStore::new(KEYSET_COUNTER) - .add_index(Index::new("keyset_id", "keyset_id").unique(true)), - ) + .add_object_store(ObjectStore::new(MINT_QUOTES)) + .add_object_store(ObjectStore::new(MELT_QUOTES)) + .add_object_store(ObjectStore::new(CONFIG)) + .add_object_store(ObjectStore::new(KEYSET_COUNTER)) // Build the database .build() .await @@ -245,7 +227,7 @@ impl WalletDatabase for RexieWalletDatabase { let quote = serde_wasm_bindgen::to_value("e).map_err(Error::from)?; quotes_store - .add("e, Some("e_id)) + .put("e, Some("e_id)) .await .map_err(Error::from)?; @@ -323,7 +305,7 @@ impl WalletDatabase for RexieWalletDatabase { let quote = serde_wasm_bindgen::to_value("e).map_err(Error::from)?; quotes_store - .add("e, Some("e_id)) + .put("e, Some("e_id)) .await .map_err(Error::from)?; diff --git a/crates/cdk/src/wallet.rs b/crates/cdk/src/wallet.rs index 27830f08..1325821c 100644 --- a/crates/cdk/src/wallet.rs +++ b/crates/cdk/src/wallet.rs @@ -908,15 +908,21 @@ impl Wallet { conditions: Option, ) -> Result { let (condition_input_proofs, input_proofs) = self - .select_proofs(mint_url.clone(), unit.clone(), amount, conditions.clone()) + .select_proofs( + mint_url.clone(), + unit.clone(), + amount, + conditions.clone().map(|p| vec![p]), + ) .await?; let send_proofs = match conditions { Some(_) => { - let needed_amount = condition_input_proofs - .iter() - .map(|p| p.amount) - .sum::(); + let needed_amount = amount + - condition_input_proofs + .iter() + .map(|p| p.amount) + .sum::(); let top_up_proofs = self .swap( @@ -1038,7 +1044,7 @@ impl Wallet { mint_url: UncheckedUrl, unit: CurrencyUnit, amount: Amount, - conditions: Option, + conditions: Option>, ) -> Result<(Proofs, Proofs), Error> { let mut condition_mint_proofs = Vec::new(); @@ -1049,7 +1055,7 @@ impl Wallet { Some(mint_url.clone()), Some(unit.clone()), Some(vec![State::Unspent]), - None, + conditions, ) .await? .unwrap_or_default() @@ -1139,7 +1145,8 @@ impl Wallet { } } - if selected_proofs.iter().map(|p| p.amount).sum::() < amount { + if selected_proofs.iter().map(|p| p.amount).sum::() + condition_proof_total < amount + { return Err(Error::InsufficientFunds); }