diff --git a/crates/cdk-cli/src/sub_commands/cat_device_login.rs b/crates/cdk-cli/src/sub_commands/cat_device_login.rs index 8c958f5c..61f53c50 100644 --- a/crates/cdk-cli/src/sub_commands/cat_device_login.rs +++ b/crates/cdk-cli/src/sub_commands/cat_device_login.rs @@ -49,7 +49,7 @@ pub async fn cat_device_login( }; let mint_info = wallet - .get_mint_info() + .fetch_mint_info() .await? .ok_or(anyhow!("Mint info not found"))?; diff --git a/crates/cdk-cli/src/sub_commands/cat_login.rs b/crates/cdk-cli/src/sub_commands/cat_login.rs index dcfc57eb..038f1664 100644 --- a/crates/cdk-cli/src/sub_commands/cat_login.rs +++ b/crates/cdk-cli/src/sub_commands/cat_login.rs @@ -51,7 +51,7 @@ pub async fn cat_login( }; let mint_info = wallet - .get_mint_info() + .fetch_mint_info() .await? .ok_or(anyhow!("Mint info not found"))?; diff --git a/crates/cdk-cli/src/sub_commands/mint_blind_auth.rs b/crates/cdk-cli/src/sub_commands/mint_blind_auth.rs index ec894343..cf55b583 100644 --- a/crates/cdk-cli/src/sub_commands/mint_blind_auth.rs +++ b/crates/cdk-cli/src/sub_commands/mint_blind_auth.rs @@ -47,7 +47,7 @@ pub async fn mint_blind_auth( } }; - wallet.get_mint_info().await?; + wallet.fetch_mint_info().await?; // Try to get the token from the provided argument or from the stored file let cat = match &sub_command_args.cat { @@ -83,7 +83,7 @@ pub async fn mint_blind_auth( println!("Attempting to refresh the access token..."); // Get the mint info to access OIDC configuration - if let Some(mint_info) = wallet.get_mint_info().await? { + if let Some(mint_info) = wallet.fetch_mint_info().await? { match refresh_access_token(&mint_info, &token_data.refresh_token).await { Ok((new_access_token, new_refresh_token)) => { println!("Successfully refreshed access token"); @@ -137,7 +137,7 @@ pub async fn mint_blind_auth( Some(amount) => amount, None => { let mint_info = wallet - .get_mint_info() + .fetch_mint_info() .await? .ok_or(anyhow!("Unknown mint info"))?; mint_info diff --git a/crates/cdk-integration-tests/tests/bolt12.rs b/crates/cdk-integration-tests/tests/bolt12.rs index ca25a4c9..8a900a80 100644 --- a/crates/cdk-integration-tests/tests/bolt12.rs +++ b/crates/cdk-integration-tests/tests/bolt12.rs @@ -266,8 +266,6 @@ async fn test_regtest_bolt12_melt() -> Result<()> { None, )?; - wallet.get_mint_info().await?; - let mint_amount = Amount::from(20_000); // Create a single-use BOLT12 quote @@ -323,8 +321,6 @@ async fn test_regtest_bolt12_mint_extra() -> Result<()> { None, )?; - wallet.get_mint_info().await?; - // Create a single-use BOLT12 quote let mint_quote = wallet.mint_bolt12_quote(None, None).await?; diff --git a/crates/cdk-integration-tests/tests/fake_auth.rs b/crates/cdk-integration-tests/tests/fake_auth.rs index dba54fbd..26f089e3 100644 --- a/crates/cdk-integration-tests/tests/fake_auth.rs +++ b/crates/cdk-integration-tests/tests/fake_auth.rs @@ -42,7 +42,7 @@ async fn test_invalid_credentials() { .expect("Wallet"); let mint_info = wallet - .get_mint_info() + .fetch_mint_info() .await .expect("mint info") .expect("could not get mint info"); @@ -278,7 +278,7 @@ async fn test_mint_blind_auth() { .seed(Mnemonic::generate(12).unwrap().to_seed_normalized("")) .build() .expect("Wallet"); - let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); + let mint_info = wallet.fetch_mint_info().await.unwrap().unwrap(); let (access_token, _) = get_access_token(&mint_info).await; @@ -310,7 +310,7 @@ async fn test_mint_with_auth() { .expect("Wallet"); let mint_info = wallet - .get_mint_info() + .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.get_mint_info().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(); @@ -410,7 +410,7 @@ async fn test_melt_with_auth() { .expect("Wallet"); let mint_info = wallet - .get_mint_info() + .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 - .get_mint_info() + .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.get_mint_info().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.get_mint_info().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 - .get_mint_info() + .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 - .get_mint_info() + .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 - .get_mint_info() + .fetch_mint_info() .await .expect("mint info") .expect("could not get mint info"); diff --git a/crates/cdk-integration-tests/tests/integration_tests_pure.rs b/crates/cdk-integration-tests/tests/integration_tests_pure.rs index fe22cfbf..8cb645e7 100644 --- a/crates/cdk-integration-tests/tests/integration_tests_pure.rs +++ b/crates/cdk-integration-tests/tests/integration_tests_pure.rs @@ -196,7 +196,7 @@ async fn test_mint_nut06() { let initial_mint_url = wallet_alice.mint_url.clone(); let mint_info_before = wallet_alice - .get_mint_info() + .fetch_mint_info() .await .expect("Failed to get mint info") .unwrap(); diff --git a/crates/cdk/examples/auth_wallet.rs b/crates/cdk/examples/auth_wallet.rs index 27b28092..d6efe6bb 100644 --- a/crates/cdk/examples/auth_wallet.rs +++ b/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 - .get_mint_info() + .fetch_mint_info() .await .expect("mint info") .expect("could not get mint info"); diff --git a/crates/cdk/src/wallet/issue/issue_bolt11.rs b/crates/cdk/src/wallet/issue/issue_bolt11.rs index bf613ae5..af436ef2 100644 --- a/crates/cdk/src/wallet/issue/issue_bolt11.rs +++ b/crates/cdk/src/wallet/issue/issue_bolt11.rs @@ -52,6 +52,8 @@ impl Wallet { let mint_url = self.mint_url.clone(); let unit = self.unit.clone(); + self.refresh_keysets().await?; + // If we have a description, we check that the mint supports it. if description.is_some() { let settings = self @@ -194,15 +196,7 @@ impl Wallet { amount_split_target: SplitTarget, spending_conditions: Option, ) -> Result { - // Check that mint is in store of mints - if self - .localstore - .get_mint(self.mint_url.clone()) - .await? - .is_none() - { - self.get_mint_info().await?; - } + self.refresh_keysets().await?; let quote_info = self .localstore diff --git a/crates/cdk/src/wallet/issue/issue_bolt12.rs b/crates/cdk/src/wallet/issue/issue_bolt12.rs index 5ac6964e..cf547798 100644 --- a/crates/cdk/src/wallet/issue/issue_bolt12.rs +++ b/crates/cdk/src/wallet/issue/issue_bolt12.rs @@ -29,6 +29,8 @@ impl Wallet { let mint_url = self.mint_url.clone(); let unit = &self.unit; + self.refresh_keysets().await?; + // If we have a description, we check that the mint supports it. if description.is_some() { let mint_method_settings = self @@ -83,15 +85,7 @@ impl Wallet { amount_split_target: SplitTarget, spending_conditions: Option, ) -> Result { - // Check that mint is in store of mints - if self - .localstore - .get_mint(self.mint_url.clone()) - .await? - .is_none() - { - self.get_mint_info().await?; - } + self.refresh_keysets().await?; let quote_info = self.localstore.get_mint_quote(quote_id).await?; diff --git a/crates/cdk/src/wallet/keysets.rs b/crates/cdk/src/wallet/keysets.rs index ae999793..302b8e85 100644 --- a/crates/cdk/src/wallet/keysets.rs +++ b/crates/cdk/src/wallet/keysets.rs @@ -82,7 +82,7 @@ impl Wallet { #[instrument(skip(self))] pub async fn refresh_keysets(&self) -> Result { tracing::debug!("Refreshing keysets and ensuring we have keys"); - let _ = self.get_mint_info().await?; + let _ = self.fetch_mint_info().await?; // Fetch all current keysets from mint let keysets_response = self.client.get_mint_keysets().await?; diff --git a/crates/cdk/src/wallet/melt/melt_bolt11.rs b/crates/cdk/src/wallet/melt/melt_bolt11.rs index 87ed0f24..9f82c1e8 100644 --- a/crates/cdk/src/wallet/melt/melt_bolt11.rs +++ b/crates/cdk/src/wallet/melt/melt_bolt11.rs @@ -48,6 +48,8 @@ impl Wallet { request: String, options: Option, ) -> Result { + self.refresh_keysets().await?; + let invoice = Bolt11Invoice::from_str(&request)?; let quote_request = MeltQuoteBolt11Request { diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index 2099fa49..39147620 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -249,7 +249,7 @@ impl Wallet { /// Query mint for current mint information #[instrument(skip(self))] - pub async fn get_mint_info(&self) -> Result, Error> { + pub async fn fetch_mint_info(&self) -> Result, Error> { match self.client.get_mint_info().await { Ok(mint_info) => { // If mint provides time make sure it is accurate @@ -382,7 +382,7 @@ impl Wallet { .await? .is_none() { - self.get_mint_info().await?; + self.fetch_mint_info().await?; } let keysets = self.load_mint_keysets().await?; diff --git a/crates/cdk/src/wallet/multi_mint_wallet.rs b/crates/cdk/src/wallet/multi_mint_wallet.rs index f5c7d2ba..7a07aedc 100644 --- a/crates/cdk/src/wallet/multi_mint_wallet.rs +++ b/crates/cdk/src/wallet/multi_mint_wallet.rs @@ -78,7 +78,7 @@ impl MultiMintWallet { target_proof_count, )?; - wallet.get_mint_info().await?; + wallet.fetch_mint_info().await?; self.add_wallet(wallet.clone()).await; diff --git a/crates/cdk/src/wallet/receive.rs b/crates/cdk/src/wallet/receive.rs index 0772a764..607f6dbf 100644 --- a/crates/cdk/src/wallet/receive.rs +++ b/crates/cdk/src/wallet/receive.rs @@ -27,18 +27,8 @@ impl Wallet { memo: Option, ) -> Result { let mint_url = &self.mint_url; - // Add mint if it does not exist in the store - if self - .localstore - .get_mint(self.mint_url.clone()) - .await? - .is_none() - { - tracing::debug!("Mint not in localstore fetching info for: {mint_url}"); - self.get_mint_info().await?; - } - let _ = self.fetch_active_keyset().await?; + self.refresh_keysets().await?; let active_keyset_id = self.fetch_active_keyset().await?.id; diff --git a/crates/cdk/src/wallet/swap.rs b/crates/cdk/src/wallet/swap.rs index 6a5affb4..fc70dafa 100644 --- a/crates/cdk/src/wallet/swap.rs +++ b/crates/cdk/src/wallet/swap.rs @@ -21,6 +21,8 @@ impl Wallet { spending_conditions: Option, include_fees: bool, ) -> Result, Error> { + self.refresh_keysets().await?; + tracing::info!("Swapping"); let mint_url = &self.mint_url; let unit = &self.unit;