浏览代码

Update with_tx

Cesar Rodas 2 月之前
父节点
当前提交
de71ddc6da

+ 2 - 9
crates/cdk-cli/src/sub_commands/check_pending.rs

@@ -9,12 +9,10 @@ pub async fn check_pending(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
         let mint_url = wallet.mint_url.clone();
         println!("{i}: {mint_url}");
 
-        let mut tx = wallet.localstore.begin_db_transaction().await?;
-
         // Get all pending proofs
         //
 
-        let pending_proofs = wallet.get_pending_proofs_with_tx(&mut tx).await?;
+        let pending_proofs = wallet.get_pending_proofs().await?;
         if pending_proofs.is_empty() {
             println!("No pending proofs found");
             continue;
@@ -28,15 +26,10 @@ pub async fn check_pending(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
         );
 
         // Try to reclaim any proofs that are no longer pending
-        match wallet
-            .reclaim_unspent_with_tx(&mut tx, pending_proofs)
-            .await
-        {
+        match wallet.reclaim_unspent(pending_proofs).await {
             Ok(()) => println!("Successfully reclaimed pending proofs"),
             Err(e) => println!("Error reclaimed pending proofs: {e}"),
         }
-
-        tx.commit().await?;
     }
     Ok(())
 }

+ 1 - 3
crates/cdk-ffi/src/wallet.rs

@@ -123,12 +123,10 @@ impl Wallet {
             proofs.into_iter().map(|p| p.try_into()).collect();
         let cdk_proofs = cdk_proofs?;
 
-        let mut tx = self.inner.localstore.begin_db_transaction().await?;
         let amount = self
             .inner
-            .receive_proofs_with_tx(&mut tx, cdk_proofs, options.into(), memo)
+            .receive_proofs(cdk_proofs, options.into(), memo)
             .await?;
-        tx.commit().await?;
         Ok(amount.into())
     }
 

+ 1 - 1
crates/cdk-integration-tests/tests/bolt12.rs

@@ -330,7 +330,7 @@ async fn test_regtest_bolt12_mint_extra() -> Result<()> {
     assert_eq!(state.amount_paid, Amount::ZERO);
     assert_eq!(state.amount_issued, Amount::ZERO);
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await?.id;
+    let active_keyset_id = wallet.fetch_active_keyset().await?.id;
 
     let pay_amount_msats = 10_000;
 

+ 12 - 12
crates/cdk-integration-tests/tests/fake_auth.rs

@@ -41,7 +41,7 @@ async fn test_invalid_credentials() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");
@@ -277,7 +277,7 @@ async fn test_mint_blind_auth() {
         .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
         .build()
         .expect("Wallet");
-    let mint_info = wallet.fetch_mint_info(None).await.unwrap().unwrap();
+    let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
 
     let (access_token, _) = get_access_token(&mint_info).await;
 
@@ -309,7 +309,7 @@ async fn test_mint_with_auth() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");
@@ -355,7 +355,7 @@ async fn test_swap_with_auth() {
         .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
         .build()
         .expect("Wallet");
-    let mint_info = wallet.fetch_mint_info(None).await.unwrap().unwrap();
+    let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
     let (access_token, _) = get_access_token(&mint_info).await;
 
     wallet.set_cat(access_token).await.unwrap();
@@ -384,7 +384,7 @@ async fn test_swap_with_auth() {
         .expect("Could not swap");
 
     let check_spent = wallet
-        .check_proofs_spent(proofs.clone(), None)
+        .check_proofs_spent(proofs.clone())
         .await
         .expect("Could not check proofs");
 
@@ -410,7 +410,7 @@ async fn test_melt_with_auth() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("Mint info not found")
         .expect("Mint info not found");
@@ -452,7 +452,7 @@ async fn test_mint_auth_over_max() {
     let wallet = Arc::new(wallet);
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("Mint info not found")
         .expect("Mint info not found");
@@ -490,7 +490,7 @@ async fn test_reuse_auth_proof() {
         .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
         .build()
         .expect("Wallet");
-    let mint_info = wallet.fetch_mint_info(None).await.unwrap().unwrap();
+    let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
 
     let (access_token, _) = get_access_token(&mint_info).await;
 
@@ -542,7 +542,7 @@ async fn test_melt_with_invalid_auth() {
         .seed(Mnemonic::generate(12).unwrap().to_seed_normalized(""))
         .build()
         .expect("Wallet");
-    let mint_info = wallet.fetch_mint_info(None).await.unwrap().unwrap();
+    let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap();
 
     let (access_token, _) = get_access_token(&mint_info).await;
 
@@ -607,7 +607,7 @@ async fn test_refresh_access_token() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");
@@ -663,7 +663,7 @@ async fn test_invalid_refresh_token() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");
@@ -699,7 +699,7 @@ async fn test_auth_token_spending_order() {
         .expect("Wallet");
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");

+ 18 - 18
crates/cdk-integration-tests/tests/fake_wallet.rs

@@ -135,7 +135,7 @@ async fn test_fake_melt_payment_fail() {
 
     // The mint should have unset proofs from pending since payment failed
     let all_proof = wallet.get_unspent_proofs().await.unwrap();
-    let states = wallet.check_proofs_spent(all_proof, None).await.unwrap();
+    let states = wallet.check_proofs_spent(all_proof).await.unwrap();
     for state in states {
         assert!(state.state == State::Unspent);
     }
@@ -408,7 +408,7 @@ async fn test_fake_melt_change_in_quote() {
 
     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-    let keyset = wallet.fetch_active_keyset(None).await.unwrap();
+    let keyset = wallet.fetch_active_keyset().await.unwrap();
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let premint_secrets = PreMintSecrets::random(
@@ -491,7 +491,7 @@ async fn test_fake_mint_without_witness() {
 
     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let premint_secrets = PreMintSecrets::random(
@@ -541,7 +541,7 @@ async fn test_fake_mint_with_wrong_witness() {
 
     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let premint_secrets = PreMintSecrets::random(
@@ -595,7 +595,7 @@ async fn test_fake_mint_inflated() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let pre_mint = PreMintSecrets::random(
@@ -663,7 +663,7 @@ async fn test_fake_mint_multiple_units() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let pre_mint = PreMintSecrets::random(
@@ -683,7 +683,7 @@ async fn test_fake_mint_multiple_units() {
     )
     .expect("failed to create new wallet");
 
-    let active_keyset_id = wallet_usd.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
     let usd_pre_mint = PreMintSecrets::random(
         active_keyset_id,
@@ -746,7 +746,7 @@ async fn test_fake_mint_multiple_unit_swap() {
     )
     .expect("failed to create new wallet");
 
-    wallet.refresh_keysets(None).await.unwrap();
+    wallet.refresh_keysets().await.unwrap();
 
     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
@@ -766,7 +766,7 @@ async fn test_fake_mint_multiple_unit_swap() {
         None,
     )
     .expect("failed to create usd wallet");
-    wallet_usd.refresh_keysets(None).await.unwrap();
+    wallet_usd.refresh_keysets().await.unwrap();
 
     let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
 
@@ -779,7 +779,7 @@ async fn test_fake_mint_multiple_unit_swap() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     {
@@ -815,7 +815,7 @@ async fn test_fake_mint_multiple_unit_swap() {
     }
 
     {
-        let usd_active_keyset_id = wallet_usd.fetch_active_keyset(None).await.unwrap().id;
+        let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
         let inputs: Proofs = proofs.into_iter().take(2).collect();
 
         let total_inputs = inputs.total_amount().unwrap();
@@ -941,8 +941,8 @@ async fn test_fake_mint_multiple_unit_melt() {
         let input_amount: u64 = inputs.total_amount().unwrap().into();
 
         let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
-        let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
-        let usd_active_keyset_id = wallet_usd.fetch_active_keyset(None).await.unwrap().id;
+        let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
+        let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
         let usd_pre_mint = PreMintSecrets::random(
             usd_active_keyset_id,
@@ -1015,7 +1015,7 @@ async fn test_fake_mint_input_output_mismatch() {
         None,
     )
     .expect("failed to create new  usd wallet");
-    let usd_active_keyset_id = wallet_usd.fetch_active_keyset(None).await.unwrap().id;
+    let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let inputs = proofs;
@@ -1067,7 +1067,7 @@ async fn test_fake_mint_swap_inflated() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let pre_mint = PreMintSecrets::random(
         active_keyset_id,
         101.into(),
@@ -1116,7 +1116,7 @@ async fn test_fake_mint_swap_spend_after_fail() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let pre_mint = PreMintSecrets::random(
@@ -1203,7 +1203,7 @@ async fn test_fake_mint_melt_spend_after_fail() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let pre_mint = PreMintSecrets::random(
@@ -1286,7 +1286,7 @@ async fn test_fake_mint_duplicate_proofs_swap() {
         .expect("payment")
         .expect("no error");
 
-    let active_keyset_id = wallet.fetch_active_keyset(None).await.unwrap().id;
+    let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let inputs = vec![proofs[0].clone(), proofs[0].clone()];

+ 3 - 3
crates/cdk-integration-tests/tests/happy_path_mint_wallet.rs

@@ -322,7 +322,7 @@ async fn test_restore() {
 
     assert!(!proofs.is_empty());
 
-    let expected_fee = wallet.get_proofs_fee(None, &proofs).await.unwrap();
+    let expected_fee = wallet.get_proofs_fee(&proofs).await.unwrap();
     wallet_2
         .swap(None, SplitTarget::default(), proofs, None, false)
         .await
@@ -338,7 +338,7 @@ async fn test_restore() {
 
     let proofs = wallet.get_unspent_proofs().await.unwrap();
 
-    let states = wallet.check_proofs_spent(proofs, None).await.unwrap();
+    let states = wallet.check_proofs_spent(proofs).await.unwrap();
 
     for state in states {
         if state.state != State::Spent {
@@ -390,7 +390,7 @@ async fn test_fake_melt_change_in_quote() {
 
     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-    let keyset = wallet.fetch_active_keyset(None).await.unwrap();
+    let keyset = wallet.fetch_active_keyset().await.unwrap();
     let fee_and_amounts = (0, ((0..32).map(|x| 2u64.pow(x)).collect::<Vec<_>>())).into();
 
     let premint_secrets = PreMintSecrets::random(

+ 2 - 14
crates/cdk-integration-tests/tests/integration_tests_pure.rs

@@ -126,21 +126,14 @@ async fn test_swap_to_send() {
     let wallet_carol = create_test_wallet_for_mint(mint_bob.clone())
         .await
         .expect("Failed to create Carol's wallet");
-    let mut tx = wallet_carol
-        .localstore
-        .begin_db_transaction()
-        .await
-        .expect("valid begin tx");
     let received_amount = wallet_carol
-        .receive_proofs_with_tx(
-            &mut tx,
+        .receive_proofs(
             token_proofs.clone(),
             ReceiveOptions::default(),
             token.memo().clone(),
         )
         .await
         .expect("Failed to receive proofs");
-    tx.commit().await.expect("valid commit");
 
     assert_eq!(Amount::from(40), received_amount);
     assert_eq!(
@@ -772,13 +765,8 @@ async fn test_mint_change_with_fee_melt() {
         .await
         .unwrap();
 
-    let tx = wallet_alice
-        .localstore
-        .begin_db_transaction()
-        .await
-        .unwrap();
     let w = wallet_alice
-        .melt_proofs_with_metadata_with_tx(tx, &melt_quote.id, proofs, HashMap::new())
+        .melt_proofs_with_metadata(&melt_quote.id, proofs, HashMap::new())
         .await
         .unwrap();
 

+ 2 - 2
crates/cdk-integration-tests/tests/test_fees.rs

@@ -53,7 +53,7 @@ async fn test_swap() {
 
     let proofs = send.proofs();
 
-    let fee = wallet.get_proofs_fee(None, &proofs).await.unwrap();
+    let fee = wallet.get_proofs_fee(&proofs).await.unwrap();
 
     assert_eq!(fee, 1.into());
 
@@ -108,7 +108,7 @@ async fn test_fake_melt_change_in_quote() {
 
     let proofs_total = proofs.total_amount().unwrap();
 
-    let fee = wallet.get_proofs_fee(None, &proofs).await.unwrap();
+    let fee = wallet.get_proofs_fee(&proofs).await.unwrap();
 
     let melt = wallet
         .melt_proofs_with_metadata(&melt_quote.id, proofs, HashMap::new())

+ 1 - 1
crates/cdk/examples/auth_wallet.rs

@@ -37,7 +37,7 @@ async fn main() -> Result<(), Error> {
     let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), seed, None)?;
 
     let mint_info = wallet
-        .fetch_mint_info(None)
+        .fetch_mint_info()
         .await
         .expect("mint info")
         .expect("could not get mint info");

+ 1 - 1
crates/cdk/examples/proof-selection.rs

@@ -52,7 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
     // Select proofs to send
     let amount = Amount::from(64);
     let active_keyset_ids = wallet
-        .refresh_keysets(None)
+        .refresh_keysets()
         .await?
         .active()
         .map(|keyset| keyset.id)

+ 131 - 53
crates/cdk/src/wallet/auth/auth_wallet.rs

@@ -192,31 +192,26 @@ impl AuthWallet {
         Ok(keys)
     }
 
-    /// Get blind auth keysets from local database or go online if missing
+    /// Get blind auth keysets from local database or go online if missing (with transaction)
     ///
     /// First checks the local database for cached blind auth keysets. If keysets are not found locally,
     /// goes online to refresh keysets from the mint and updates the local database.
     /// This is the main method for getting auth keysets in operations that can work offline
     /// but will fall back to online if needed.
+    ///
+    /// This version requires a database transaction to be passed in.
     #[instrument(skip(self, tx))]
-    pub async fn load_mint_keysets(
+    pub(crate) async fn load_mint_keysets_with_tx(
         &self,
-        tx: Option<&mut Tx<'_, '_>>,
+        tx: &mut Tx<'_, '_>,
     ) -> Result<Vec<KeySetInfo>, Error> {
-        let mut tx = tx;
-        match if let Some(tx) = tx.as_mut() {
-            tx.get_mint_keysets(self.mint_url.clone()).await?
-        } else {
-            self.localstore
-                .get_mint_keysets(self.mint_url.clone())
-                .await?
-        } {
+        match tx.get_mint_keysets(self.mint_url.clone()).await? {
             Some(keysets_info) => {
                 let auth_keysets: Vec<KeySetInfo> =
                     keysets_info.unit(CurrencyUnit::Sat).cloned().collect();
                 if auth_keysets.is_empty() {
                     // If we don't have any auth keysets, fetch them from the mint
-                    let keysets = self.refresh_keysets(tx).await?;
+                    let keysets = self.refresh_keysets_with_tx(tx).await?;
                     Ok(keysets)
                 } else {
                     Ok(auth_keysets)
@@ -224,37 +219,99 @@ impl AuthWallet {
             }
             None => {
                 // If we don't have any keysets, fetch them from the mint
-                let keysets = self.refresh_keysets(tx).await?;
+                let keysets = self.refresh_keysets_with_tx(tx).await?;
                 Ok(keysets)
             }
         }
     }
 
-    /// Refresh blind auth keysets by fetching the latest from mint - always goes online
+    /// Get blind auth keysets from local database or go online if missing
+    ///
+    /// First checks the local database for cached blind auth keysets. If keysets are not found locally,
+    /// goes online to refresh keysets from the mint and updates the local database.
+    /// This is the main method for getting auth keysets in operations that can work offline
+    /// but will fall back to online if needed.
+    #[instrument(skip(self))]
+    pub async fn load_mint_keysets(&self) -> Result<Vec<KeySetInfo>, Error> {
+        match self
+            .localstore
+            .get_mint_keysets(self.mint_url.clone())
+            .await?
+        {
+            Some(keysets_info) => {
+                let auth_keysets: Vec<KeySetInfo> =
+                    keysets_info.unit(CurrencyUnit::Sat).cloned().collect();
+                if auth_keysets.is_empty() {
+                    // If we don't have any auth keysets, fetch them from the mint
+                    let keysets = self.refresh_keysets().await?;
+                    Ok(keysets)
+                } else {
+                    Ok(auth_keysets)
+                }
+            }
+            None => {
+                // If we don't have any keysets, fetch them from the mint
+                let keysets = self.refresh_keysets().await?;
+                Ok(keysets)
+            }
+        }
+    }
+
+    /// Refresh blind auth keysets by fetching the latest from mint - always goes online (with transaction)
     ///
     /// This method always goes online to fetch the latest blind auth keyset information from the mint.
     /// It updates the local database with the fetched keysets and ensures we have keys for all keysets.
     /// Returns only the keysets with Auth currency unit. This is used when operations need the most
     /// up-to-date keyset information and are willing to go online.
+    ///
+    /// This version requires a database transaction to be passed in.
     #[instrument(skip(self, tx))]
-    pub async fn refresh_keysets(
+    pub(crate) async fn refresh_keysets_with_tx(
         &self,
-        tx: Option<&mut Tx<'_, '_>>,
+        tx: &mut Tx<'_, '_>,
     ) -> Result<Vec<KeySetInfo>, Error> {
         let keysets_response = self.client.get_mint_blind_auth_keysets().await?;
         let keysets = keysets_response.keysets;
 
         // Update local store with keysets
-        if let Some(tx) = tx {
-            tx.add_mint_keysets(self.mint_url.clone(), keysets.clone())
-                .await?;
-        } else {
-            let mut tx = self.localstore.begin_db_transaction().await?;
-            tx.add_mint_keysets(self.mint_url.clone(), keysets.clone())
-                .await?;
-            tx.commit().await?;
+        tx.add_mint_keysets(self.mint_url.clone(), keysets.clone())
+            .await?;
+
+        // Filter for auth keysets
+        let auth_keysets = keysets
+            .clone()
+            .into_iter()
+            .filter(|k| k.unit == CurrencyUnit::Auth)
+            .collect::<Vec<KeySetInfo>>();
+
+        // Ensure we have keys for all auth keysets
+        for keyset in &auth_keysets {
+            if self.localstore.get_keys(&keyset.id).await?.is_none() {
+                tracing::debug!("Fetching missing keys for auth keyset {}", keyset.id);
+                self.load_keyset_keys(keyset.id).await?;
+            }
         }
 
+        Ok(auth_keysets)
+    }
+
+    /// Refresh blind auth keysets by fetching the latest from mint - always goes online
+    ///
+    /// This method always goes online to fetch the latest blind auth keyset information from the mint.
+    /// It updates the local database with the fetched keysets and ensures we have keys for all keysets.
+    /// Returns only the keysets with Auth currency unit. This is used when operations need the most
+    /// up-to-date keyset information and are willing to go online.
+    #[instrument(skip(self))]
+    pub async fn refresh_keysets(&self) -> Result<Vec<KeySetInfo>, Error> {
+        let keysets_response = self.client.get_mint_blind_auth_keysets().await?;
+        let keysets = keysets_response.keysets;
+
+        // Update local store with keysets
+        let mut tx = self.localstore.begin_db_transaction().await?;
+        tx.add_mint_keysets(self.mint_url.clone(), keysets.clone())
+            .await?;
+        tx.commit().await?;
+
         // Filter for auth keysets
         let auth_keysets = keysets
             .clone()
@@ -273,35 +330,49 @@ impl AuthWallet {
         Ok(auth_keysets)
     }
 
-    /// Get the first active blind auth keyset - always goes online
+    /// Get the first active blind auth keyset - always goes online (with transaction)
     ///
     /// This method always goes online to refresh keysets from the mint and then returns
     /// the first active keyset found. Use this when you need the most up-to-date
     /// keyset information for blind auth operations.
+    ///
+    /// This version requires a database transaction to be passed in.
     #[instrument(skip(self, tx))]
-    pub async fn fetch_active_keyset(
+    pub(crate) async fn fetch_active_keyset_with_tx(
         &self,
-        tx: Option<&mut Tx<'_, '_>>,
+        tx: &mut Tx<'_, '_>,
     ) -> Result<KeySetInfo, Error> {
-        let auth_keysets = self.refresh_keysets(tx).await?;
+        let auth_keysets = self.refresh_keysets_with_tx(tx).await?;
         let keyset = auth_keysets.first().ok_or(Error::NoActiveKeyset)?;
         Ok(keyset.clone())
     }
 
-    /// Get unspent auth proofs from local database only - offline operation
+    /// Get the first active blind auth keyset - always goes online
+    ///
+    /// This method always goes online to refresh keysets from the mint and then returns
+    /// the first active keyset found. Use this when you need the most up-to-date
+    /// keyset information for blind auth operations.
+    #[instrument(skip(self))]
+    pub async fn fetch_active_keyset(&self) -> Result<KeySetInfo, Error> {
+        let auth_keysets = self.refresh_keysets().await?;
+        let keyset = auth_keysets.first().ok_or(Error::NoActiveKeyset)?;
+        Ok(keyset.clone())
+    }
+
+    /// Get unspent auth proofs from local database only - offline operation (with transaction)
     ///
     /// Returns auth proofs from the local database that are in the Unspent state.
     /// This is an offline operation that does not contact the mint.
     ///
-    /// If a DB Transaction is passed as an argument the selected proofs are locked for update
-    /// within this DBTransaction
+    /// This version requires a database transaction to be passed in.
+    /// The selected proofs are locked for update within this DBTransaction.
     #[instrument(skip(self, tx))]
-    pub async fn get_unspent_auth_proofs(
+    pub(crate) async fn get_unspent_auth_proofs_with_tx(
         &self,
-        tx: Option<&mut Tx<'_, '_>>,
+        tx: &mut Tx<'_, '_>,
     ) -> Result<Vec<AuthProof>, Error> {
-        Ok(if let Some(tx) = tx {
-            tx.get_proofs(
+        Ok(tx
+            .get_proofs(
                 Some(self.mint_url.clone()),
                 Some(CurrencyUnit::Auth),
                 Some(vec![State::Unspent]),
@@ -310,20 +381,27 @@ impl AuthWallet {
             .await?
             .into_iter()
             .map(|p| p.proof.try_into())
-            .collect::<Result<Vec<AuthProof>, _>>()?
-        } else {
-            self.localstore
-                .get_proofs(
-                    Some(self.mint_url.clone()),
-                    Some(CurrencyUnit::Auth),
-                    Some(vec![State::Unspent]),
-                    None,
-                )
-                .await?
-                .into_iter()
-                .map(|p| p.proof.try_into())
-                .collect::<Result<Vec<AuthProof>, _>>()?
-        })
+            .collect::<Result<Vec<AuthProof>, _>>()?)
+    }
+
+    /// Get unspent auth proofs from local database only - offline operation
+    ///
+    /// Returns auth proofs from the local database that are in the Unspent state.
+    /// This is an offline operation that does not contact the mint.
+    #[instrument(skip(self))]
+    pub async fn get_unspent_auth_proofs(&self) -> Result<Vec<AuthProof>, Error> {
+        Ok(self
+            .localstore
+            .get_proofs(
+                Some(self.mint_url.clone()),
+                Some(CurrencyUnit::Auth),
+                Some(vec![State::Unspent]),
+                None,
+            )
+            .await?
+            .into_iter()
+            .map(|p| p.proof.try_into())
+            .collect::<Result<Vec<AuthProof>, _>>()?)
     }
 
     /// Check if and what kind of auth is required for a method
@@ -339,7 +417,7 @@ impl AuthWallet {
     pub async fn get_blind_auth_token(&self) -> Result<Option<BlindAuthToken>, Error> {
         let mut tx = self.localstore.begin_db_transaction().await?;
 
-        let unspent = self.get_unspent_auth_proofs(Some(&mut tx)).await?;
+        let unspent = self.get_unspent_auth_proofs_with_tx(&mut tx).await?;
 
         let auth_proof = match unspent.first() {
             Some(proof) => {
@@ -435,13 +513,13 @@ impl AuthWallet {
         }
 
         let keysets = self
-            .load_mint_keysets(None)
+            .load_mint_keysets()
             .await?
             .into_iter()
             .map(|x| (x.id, x))
             .collect::<HashMap<_, _>>();
 
-        let active_keyset_id = self.fetch_active_keyset(None).await?.id;
+        let active_keyset_id = self.fetch_active_keyset().await?.id;
         let fee_and_amounts = (
             keysets
                 .get(&active_keyset_id)
@@ -519,7 +597,7 @@ impl AuthWallet {
     #[instrument(skip(self))]
     pub async fn total_blind_auth_balance(&self) -> Result<Amount, Error> {
         Ok(Amount::from(
-            self.get_unspent_auth_proofs(None).await?.len() as u64,
+            self.get_unspent_auth_proofs().await?.len() as u64
         ))
     }
 }

+ 1 - 1
crates/cdk/src/wallet/auth/mod.rs

@@ -30,7 +30,7 @@ impl Wallet {
             .await
             .as_ref()
             .ok_or(Error::AuthSettingsUndefined)?
-            .get_unspent_auth_proofs(None)
+            .get_unspent_auth_proofs()
             .await
     }
 

+ 8 - 5
crates/cdk/src/wallet/keysets.rs

@@ -36,7 +36,7 @@ impl Wallet {
 
     /// Load keyset keys with transaction
     #[instrument(skip(self, tx))]
-    pub async fn load_keyset_keys_with_tx(
+    pub(super) async fn load_keyset_keys_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         keyset_id: Id,
@@ -115,7 +115,10 @@ impl Wallet {
 
     /// Refresh keysets from mint with transaction
     #[instrument(skip(self, tx))]
-    pub async fn refresh_keysets_with_tx(&self, tx: &mut Tx<'_, '_>) -> Result<KeySetInfos, Error> {
+    pub(super) async fn refresh_keysets_with_tx(
+        &self,
+        tx: &mut Tx<'_, '_>,
+    ) -> Result<KeySetInfos, Error> {
         tracing::debug!("Refreshing keysets and ensuring we have keys");
 
         let _ = self.fetch_mint_info_with_tx(tx).await?;
@@ -156,7 +159,7 @@ impl Wallet {
 
     /// Get the active keyset with the lowest fees with transaction - always goes online
     #[instrument(skip(self, tx))]
-    pub async fn fetch_active_keyset_with_tx(
+    pub(super) async fn fetch_active_keyset_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
     ) -> Result<KeySetInfo, Error> {
@@ -220,7 +223,7 @@ impl Wallet {
     }
 
     /// Get keyset fees and amounts for mint with transaction
-    pub async fn get_keyset_fees_and_amounts_with_tx(
+    pub(super) async fn get_keyset_fees_and_amounts_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
     ) -> Result<KeysetFeeAndAmounts, Error> {
@@ -265,7 +268,7 @@ impl Wallet {
     }
 
     /// Get keyset fees and amounts for mint by keyset id with transaction
-    pub async fn get_keyset_fees_and_amounts_by_id_with_tx(
+    pub(super) async fn get_keyset_fees_and_amounts_by_id_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         keyset_id: Id,

+ 1 - 1
crates/cdk/src/wallet/melt/melt_bolt11.rs

@@ -151,7 +151,7 @@ impl Wallet {
 
     /// Melt specific proofs with transaction
     #[instrument(skip(self, tx, proofs))]
-    pub async fn melt_proofs_with_metadata_with_tx(
+    pub(super) async fn melt_proofs_with_metadata_with_tx(
         &self,
         mut tx: Tx<'_, '_>,
         quote_id: &str,

+ 4 - 4
crates/cdk/src/wallet/mod.rs

@@ -213,7 +213,7 @@ impl Wallet {
 
     /// Fee required for proof set with transaction
     #[instrument(skip_all)]
-    pub async fn get_proofs_fee_with_tx(
+    pub(super) async fn get_proofs_fee_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         proofs: &Proofs,
@@ -245,7 +245,7 @@ impl Wallet {
     }
 
     /// Fee required for proof set by count with transaction
-    pub async fn get_proofs_fee_by_count_with_tx(
+    pub(super) async fn get_proofs_fee_by_count_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         proofs_per_keyset: HashMap<Id, u64>,
@@ -307,7 +307,7 @@ impl Wallet {
 
     /// Query mint for current mint information with transaction
     #[instrument(skip(self, tx))]
-    pub async fn fetch_mint_info_with_tx(
+    pub(super) async fn fetch_mint_info_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
     ) -> Result<Option<MintInfo>, Error> {
@@ -416,7 +416,7 @@ impl Wallet {
 
     /// Get amounts needed to refill proof state with transaction
     #[instrument(skip(self, tx))]
-    pub async fn amounts_needed_for_state_target_with_tx(
+    pub(super) async fn amounts_needed_for_state_target_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         fee_and_amounts: &FeeAndAmounts,

+ 8 - 5
crates/cdk/src/wallet/proofs.rs

@@ -30,7 +30,10 @@ impl Wallet {
 
     /// Get pending [`Proofs`] with transaction
     #[instrument(skip(self, tx))]
-    pub async fn get_pending_proofs_with_tx(&self, tx: &mut Tx<'_, '_>) -> Result<Proofs, Error> {
+    pub(super) async fn get_pending_proofs_with_tx(
+        &self,
+        tx: &mut Tx<'_, '_>,
+    ) -> Result<Proofs, Error> {
         self.get_proofs_with_tx(tx, Some(vec![State::Pending]), None)
             .await
     }
@@ -49,7 +52,7 @@ impl Wallet {
     }
 
     /// Get pending spent [`Proofs`] with transaction
-    pub async fn get_pending_spent_proofs_with_tx(
+    pub(super) async fn get_pending_spent_proofs_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
     ) -> Result<Proofs, Error> {
@@ -78,7 +81,7 @@ impl Wallet {
     }
 
     /// Get this wallet's [Proofs] that match the args with transaction
-    pub async fn get_proofs_with_tx(
+    pub(super) async fn get_proofs_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         state: Option<Vec<State>>,
@@ -121,7 +124,7 @@ impl Wallet {
     ///
     /// Checks the stats of [`Proofs`] swapping for a new [`Proof`] if unspent
     #[instrument(skip(self, tx, proofs))]
-    pub async fn reclaim_unspent_with_tx(
+    pub(super) async fn reclaim_unspent_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         proofs: Proofs,
@@ -166,7 +169,7 @@ impl Wallet {
 
     /// NUT-07 Check the state of a [`Proof`] with the mint with transaction
     #[instrument(skip(self, tx, proofs))]
-    pub async fn check_proofs_spent_with_tx(
+    pub(super) async fn check_proofs_spent_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         proofs: Proofs,

+ 1 - 1
crates/cdk/src/wallet/receive.rs

@@ -36,7 +36,7 @@ impl Wallet {
 
     /// Receive proofs with transaction
     #[instrument(skip_all)]
-    pub async fn receive_proofs_with_tx(
+    pub(super) async fn receive_proofs_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         proofs: Proofs,

+ 2 - 2
crates/cdk/src/wallet/swap.rs

@@ -167,7 +167,7 @@ impl Wallet {
 
     /// Swap with transaction
     #[instrument(skip(self, tx, input_proofs))]
-    pub async fn swap_with_tx(
+    pub(super) async fn swap_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         amount: Option<Amount>,
@@ -275,7 +275,7 @@ impl Wallet {
 
     /// Create Swap Payload with transaction
     #[instrument(skip(self, tx, proofs))]
-    pub async fn create_swap_with_tx(
+    pub(super) async fn create_swap_with_tx(
         &self,
         tx: &mut Tx<'_, '_>,
         amount: Option<Amount>,