From f506e6d8757857c687318f2e3fc557d1d18d4f75 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Sat, 16 Nov 2024 09:35:45 +0100 Subject: [PATCH] Embed mint_url as a field of HttpClient --- crates/cdk-cli/src/main.rs | 7 +- crates/cdk-cli/src/sub_commands/mint_info.rs | 11 +- crates/cdk-integration-tests/src/lib.rs | 14 +- .../tests/fake_wallet.rs | 6 +- crates/cdk-integration-tests/tests/regtest.rs | 12 +- crates/cdk/src/wallet/client.rs | 178 +++++++----------- crates/cdk/src/wallet/keysets.rs | 9 +- crates/cdk/src/wallet/melt.rs | 12 +- crates/cdk/src/wallet/mint.rs | 15 +- crates/cdk/src/wallet/mod.rs | 22 +-- crates/cdk/src/wallet/proofs.rs | 7 +- crates/cdk/src/wallet/receive.rs | 5 +- crates/cdk/src/wallet/swap.rs | 5 +- flake.nix | 2 +- 14 files changed, 114 insertions(+), 191 deletions(-) diff --git a/crates/cdk-cli/src/main.rs b/crates/cdk-cli/src/main.rs index 7ff70cda0..0377908d0 100644 --- a/crates/cdk-cli/src/main.rs +++ b/crates/cdk-cli/src/main.rs @@ -142,16 +142,17 @@ async fn main() -> Result<()> { let mints = localstore.get_mints().await?; - for (mint, _) in mints { + for (mint_url, _) in mints { let mut wallet = Wallet::new( - &mint.to_string(), + &mint_url.to_string(), cdk::nuts::CurrencyUnit::Sat, localstore.clone(), &mnemonic.to_seed_normalized(""), None, )?; if let Some(proxy_url) = args.proxy.as_ref() { - wallet.set_client(HttpClient::with_proxy(proxy_url.clone(), None, true)?); + let http_client = HttpClient::with_proxy(mint_url, proxy_url.clone(), None, true)?; + wallet.set_client(Arc::from(http_client)); } wallets.push(wallet); diff --git a/crates/cdk-cli/src/sub_commands/mint_info.rs b/crates/cdk-cli/src/sub_commands/mint_info.rs index 739d9934b..b2dc0b1cb 100644 --- a/crates/cdk-cli/src/sub_commands/mint_info.rs +++ b/crates/cdk-cli/src/sub_commands/mint_info.rs @@ -1,6 +1,6 @@ use anyhow::Result; use cdk::mint_url::MintUrl; -use cdk::wallet::client::HttpClientMethods; +use cdk::wallet::client::MintConnector; use cdk::HttpClient; use clap::Args; use url::Url; @@ -11,14 +11,13 @@ pub struct MintInfoSubcommand { } pub async fn mint_info(proxy: Option, sub_command_args: &MintInfoSubcommand) -> Result<()> { + let mint_url = sub_command_args.mint_url.clone(); let client = match proxy { - Some(proxy) => HttpClient::with_proxy(proxy, None, true)?, - None => HttpClient::new(), + Some(proxy) => HttpClient::with_proxy(mint_url, proxy, None, true)?, + None => HttpClient::new(mint_url), }; - let info = client - .get_mint_info(sub_command_args.mint_url.clone()) - .await?; + let info = client.get_mint_info().await?; println!("{:#?}", info); diff --git a/crates/cdk-integration-tests/src/lib.rs b/crates/cdk-integration-tests/src/lib.rs index 2e52b0345..b0026696c 100644 --- a/crates/cdk-integration-tests/src/lib.rs +++ b/crates/cdk-integration-tests/src/lib.rs @@ -1,4 +1,5 @@ use std::collections::{HashMap, HashSet}; +use std::str::FromStr; use std::sync::Arc; use std::time::Duration; @@ -10,12 +11,13 @@ use cdk::cdk_database::mint_memory::MintMemoryDatabase; use cdk::cdk_lightning::MintLightning; use cdk::dhke::construct_proofs; use cdk::mint::FeeReserve; +use cdk::mint_url::MintUrl; use cdk::nuts::{ CurrencyUnit, Id, KeySet, MintBolt11Request, MintInfo, MintQuoteBolt11Request, MintQuoteState, Nuts, PaymentMethod, PreMintSecrets, Proofs, State, }; use cdk::types::{LnKey, QuoteTTL}; -use cdk::wallet::client::{HttpClient, HttpClientMethods}; +use cdk::wallet::client::{HttpClient, MintConnector}; use cdk::{Mint, Wallet}; use cdk_fake_wallet::FakeWallet; use init_regtest::{get_mint_addr, get_mint_port, get_mint_url}; @@ -155,7 +157,7 @@ pub async fn mint_proofs( println!("Minting for ecash"); println!(); - let wallet_client = HttpClient::new(); + let wallet_client = HttpClient::new(MintUrl::from_str(mint_url)?); let request = MintQuoteBolt11Request { amount, @@ -163,15 +165,13 @@ pub async fn mint_proofs( description, }; - let mint_quote = wallet_client - .post_mint_quote(mint_url.parse()?, request) - .await?; + let mint_quote = wallet_client.post_mint_quote(request).await?; println!("Please pay: {}", mint_quote.request); loop { let status = wallet_client - .get_mint_quote_status(mint_url.parse()?, &mint_quote.quote) + .get_mint_quote_status(&mint_quote.quote) .await?; if status.state == MintQuoteState::Paid { @@ -189,7 +189,7 @@ pub async fn mint_proofs( outputs: premint_secrets.blinded_messages(), }; - let mint_response = wallet_client.post_mint(mint_url.parse()?, request).await?; + let mint_response = wallet_client.post_mint(request).await?; let pre_swap_proofs = construct_proofs( mint_response.signatures, diff --git a/crates/cdk-integration-tests/tests/fake_wallet.rs b/crates/cdk-integration-tests/tests/fake_wallet.rs index cf0ea1bef..cfea089c9 100644 --- a/crates/cdk-integration-tests/tests/fake_wallet.rs +++ b/crates/cdk-integration-tests/tests/fake_wallet.rs @@ -8,7 +8,7 @@ use cdk::cdk_database::WalletMemoryDatabase; use cdk::nuts::{ CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State, }; -use cdk::wallet::client::{HttpClient, HttpClientMethods}; +use cdk::wallet::client::{HttpClient, MintConnector}; use cdk::wallet::Wallet; use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription}; use cdk_integration_tests::attempt_to_swap_pending; @@ -354,7 +354,7 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { let premint_secrets = PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default())?; - let client = HttpClient::new(); + let client = HttpClient::new(MINT_URL.parse()?); let melt_request = MeltBolt11Request { quote: melt_quote.id.clone(), @@ -362,7 +362,7 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { outputs: Some(premint_secrets.blinded_messages()), }; - let melt_response = client.post_melt(MINT_URL.parse()?, melt_request).await?; + let melt_response = client.post_melt(melt_request).await?; assert!(melt_response.change.is_some()); diff --git a/crates/cdk-integration-tests/tests/regtest.rs b/crates/cdk-integration-tests/tests/regtest.rs index 107fa49eb..f829b4431 100644 --- a/crates/cdk-integration-tests/tests/regtest.rs +++ b/crates/cdk-integration-tests/tests/regtest.rs @@ -11,7 +11,7 @@ use cdk::nuts::{ CurrencyUnit, MeltQuoteState, MintBolt11Request, MintQuoteState, NotificationPayload, PreMintSecrets, State, }; -use cdk::wallet::client::{HttpClient, HttpClientMethods}; +use cdk::wallet::client::{HttpClient, MintConnector}; use cdk::wallet::Wallet; use cdk_integration_tests::init_regtest::{ get_mint_url, get_mint_ws_url, init_cln_client, init_lnd_client, @@ -374,7 +374,7 @@ async fn test_cached_mint() -> Result<()> { } let active_keyset_id = wallet.get_active_mint_keyset().await?.id; - let http_client = HttpClient::new(); + let http_client = HttpClient::new(get_mint_url().as_str().parse()?); let premint_secrets = PreMintSecrets::random(active_keyset_id, 31.into(), &SplitTarget::default()).unwrap(); @@ -383,12 +383,8 @@ async fn test_cached_mint() -> Result<()> { outputs: premint_secrets.blinded_messages(), }; - let response = http_client - .post_mint(get_mint_url().as_str().parse()?, request.clone()) - .await?; - let response1 = http_client - .post_mint(get_mint_url().as_str().parse()?, request) - .await?; + let response = http_client.post_mint(request.clone()).await?; + let response1 = http_client.post_mint(request).await?; assert!(response == response1); Ok(()) diff --git a/crates/cdk/src/wallet/client.rs b/crates/cdk/src/wallet/client.rs index 4296e6c23..08563257b 100644 --- a/crates/cdk/src/wallet/client.rs +++ b/crates/cdk/src/wallet/client.rs @@ -22,19 +22,15 @@ use crate::nuts::{ #[derive(Debug, Clone)] pub struct HttpClient { inner: Client, -} - -impl Default for HttpClient { - fn default() -> Self { - Self::new() - } + mint_url: MintUrl, } impl HttpClient { /// Create new [`HttpClient`] - pub fn new() -> Self { + pub fn new(mint_url: MintUrl) -> Self { Self { inner: Client::new(), + mint_url, } } @@ -43,6 +39,7 @@ impl HttpClient { /// Specifying `None` for `host_matcher` will use the proxy for all /// requests. pub fn with_proxy( + mint_url: MintUrl, proxy: Url, host_matcher: Option<&str>, accept_invalid_certs: bool, @@ -65,17 +62,20 @@ impl HttpClient { .danger_accept_invalid_certs(accept_invalid_certs) // Allow self-signed certs .build()?; - Ok(Self { inner: client }) + Ok(Self { + inner: client, + mint_url, + }) } } #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] -impl HttpClientMethods for HttpClient { +impl MintConnector for HttpClient { /// Get Active Mint Keys [NUT-01] - #[instrument(skip(self), fields(mint_url = %mint_url))] - async fn get_mint_keys(&self, mint_url: MintUrl) -> Result, Error> { - let url = mint_url.join_paths(&["v1", "keys"])?; + #[instrument(skip(self), fields(mint_url = %self.mint_url))] + async fn get_mint_keys(&self) -> Result, Error> { + let url = self.mint_url.join_paths(&["v1", "keys"])?; let keys = self.inner.get(url).send().await?.json::().await?; match serde_json::from_value::(keys.clone()) { @@ -85,9 +85,11 @@ impl HttpClientMethods for HttpClient { } /// Get Keyset Keys [NUT-01] - #[instrument(skip(self), fields(mint_url = %mint_url))] - async fn get_mint_keyset(&self, mint_url: MintUrl, keyset_id: Id) -> Result { - let url = mint_url.join_paths(&["v1", "keys", &keyset_id.to_string()])?; + #[instrument(skip(self), fields(mint_url = %self.mint_url))] + async fn get_mint_keyset(&self, keyset_id: Id) -> Result { + let url = self + .mint_url + .join_paths(&["v1", "keys", &keyset_id.to_string()])?; let keys = self.inner.get(url).send().await?.json::().await?; match serde_json::from_value::(keys.clone()) { @@ -97,9 +99,9 @@ impl HttpClientMethods for HttpClient { } /// Get Keysets [NUT-02] - #[instrument(skip(self), fields(mint_url = %mint_url))] - async fn get_mint_keysets(&self, mint_url: MintUrl) -> Result { - let url = mint_url.join_paths(&["v1", "keysets"])?; + #[instrument(skip(self), fields(mint_url = %self.mint_url))] + async fn get_mint_keysets(&self) -> Result { + let url = self.mint_url.join_paths(&["v1", "keysets"])?; let res = self.inner.get(url).send().await?.json::().await?; match serde_json::from_value::(res.clone()) { @@ -109,13 +111,14 @@ impl HttpClientMethods for HttpClient { } /// Mint Quote [NUT-04] - #[instrument(skip(self), fields(mint_url = %mint_url))] + #[instrument(skip(self), fields(mint_url = %self.mint_url))] async fn post_mint_quote( &self, - mint_url: MintUrl, request: MintQuoteBolt11Request, ) -> Result { - let url = mint_url.join_paths(&["v1", "mint", "quote", "bolt11"])?; + let url = self + .mint_url + .join_paths(&["v1", "mint", "quote", "bolt11"])?; let res = self .inner @@ -136,13 +139,14 @@ impl HttpClientMethods for HttpClient { } /// Mint Quote status - #[instrument(skip(self), fields(mint_url = %mint_url))] + #[instrument(skip(self), fields(mint_url = %self.mint_url))] async fn get_mint_quote_status( &self, - mint_url: MintUrl, quote_id: &str, ) -> Result { - let url = mint_url.join_paths(&["v1", "mint", "quote", "bolt11", quote_id])?; + let url = self + .mint_url + .join_paths(&["v1", "mint", "quote", "bolt11", quote_id])?; let res = self.inner.get(url).send().await?.json::().await?; @@ -156,13 +160,9 @@ impl HttpClientMethods for HttpClient { } /// Mint Tokens [NUT-04] - #[instrument(skip(self, request), fields(mint_url = %mint_url))] - async fn post_mint( - &self, - mint_url: MintUrl, - request: MintBolt11Request, - ) -> Result { - let url = mint_url.join_paths(&["v1", "mint", "bolt11"])?; + #[instrument(skip(self, request), fields(mint_url = %self.mint_url))] + async fn post_mint(&self, request: MintBolt11Request) -> Result { + let url = self.mint_url.join_paths(&["v1", "mint", "bolt11"])?; let res = self .inner @@ -180,13 +180,14 @@ impl HttpClientMethods for HttpClient { } /// Melt Quote [NUT-05] - #[instrument(skip(self, request), fields(mint_url = %mint_url))] + #[instrument(skip(self, request), fields(mint_url = %self.mint_url))] async fn post_melt_quote( &self, - mint_url: MintUrl, request: MeltQuoteBolt11Request, ) -> Result { - let url = mint_url.join_paths(&["v1", "melt", "quote", "bolt11"])?; + let url = self + .mint_url + .join_paths(&["v1", "melt", "quote", "bolt11"])?; let res = self .inner @@ -204,13 +205,14 @@ impl HttpClientMethods for HttpClient { } /// Melt Quote Status - #[instrument(skip(self), fields(mint_url = %mint_url))] + #[instrument(skip(self), fields(mint_url = %self.mint_url))] async fn get_melt_quote_status( &self, - mint_url: MintUrl, quote_id: &str, ) -> Result { - let url = mint_url.join_paths(&["v1", "melt", "quote", "bolt11", quote_id])?; + let url = self + .mint_url + .join_paths(&["v1", "melt", "quote", "bolt11", quote_id])?; let res = self.inner.get(url).send().await?.json::().await?; @@ -222,13 +224,12 @@ impl HttpClientMethods for HttpClient { /// Melt [NUT-05] /// [Nut-08] Lightning fee return if outputs defined - #[instrument(skip(self, request), fields(mint_url = %mint_url))] + #[instrument(skip(self, request), fields(mint_url = %self.mint_url))] async fn post_melt( &self, - mint_url: MintUrl, request: MeltBolt11Request, ) -> Result { - let url = mint_url.join_paths(&["v1", "melt", "bolt11"])?; + let url = self.mint_url.join_paths(&["v1", "melt", "bolt11"])?; let res = self .inner @@ -251,13 +252,9 @@ impl HttpClientMethods for HttpClient { } /// Swap Token [NUT-03] - #[instrument(skip(self, swap_request), fields(mint_url = %mint_url))] - async fn post_swap( - &self, - mint_url: MintUrl, - swap_request: SwapRequest, - ) -> Result { - let url = mint_url.join_paths(&["v1", "swap"])?; + #[instrument(skip(self, swap_request), fields(mint_url = %self.mint_url))] + async fn post_swap(&self, swap_request: SwapRequest) -> Result { + let url = self.mint_url.join_paths(&["v1", "swap"])?; let res = self .inner @@ -275,9 +272,9 @@ impl HttpClientMethods for HttpClient { } /// Get Mint Info [NUT-06] - #[instrument(skip(self), fields(mint_url = %mint_url))] - async fn get_mint_info(&self, mint_url: MintUrl) -> Result { - let url = mint_url.join_paths(&["v1", "info"])?; + #[instrument(skip(self), fields(mint_url = %self.mint_url))] + async fn get_mint_info(&self) -> Result { + let url = self.mint_url.join_paths(&["v1", "info"])?; let res = self.inner.get(url).send().await?.json::().await?; @@ -291,13 +288,12 @@ impl HttpClientMethods for HttpClient { } /// Spendable check [NUT-07] - #[instrument(skip(self, request), fields(mint_url = %mint_url))] + #[instrument(skip(self, request), fields(mint_url = %self.mint_url))] async fn post_check_state( &self, - mint_url: MintUrl, request: CheckStateRequest, ) -> Result { - let url = mint_url.join_paths(&["v1", "checkstate"])?; + let url = self.mint_url.join_paths(&["v1", "checkstate"])?; let res = self .inner @@ -315,13 +311,9 @@ impl HttpClientMethods for HttpClient { } /// Restore request [NUT-13] - #[instrument(skip(self, request), fields(mint_url = %mint_url))] - async fn post_restore( - &self, - mint_url: MintUrl, - request: RestoreRequest, - ) -> Result { - let url = mint_url.join_paths(&["v1", "restore"])?; + #[instrument(skip(self, request), fields(mint_url = %self.mint_url))] + async fn post_restore(&self, request: RestoreRequest) -> Result { + let url = self.mint_url.join_paths(&["v1", "restore"])?; let res = self .inner @@ -339,83 +331,47 @@ impl HttpClientMethods for HttpClient { } } -/// Http Client Methods +/// Interface that connects a wallet to a mint. Typically represents an [HttpClient]. #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] -pub trait HttpClientMethods: Debug { +pub trait MintConnector: Debug { /// Get Active Mint Keys [NUT-01] - async fn get_mint_keys(&self, mint_url: MintUrl) -> Result, Error>; - + async fn get_mint_keys(&self) -> Result, Error>; /// Get Keyset Keys [NUT-01] - async fn get_mint_keyset(&self, mint_url: MintUrl, keyset_id: Id) -> Result; - + async fn get_mint_keyset(&self, keyset_id: Id) -> Result; /// Get Keysets [NUT-02] - async fn get_mint_keysets(&self, mint_url: MintUrl) -> Result; - + async fn get_mint_keysets(&self) -> Result; /// Mint Quote [NUT-04] async fn post_mint_quote( &self, - mint_url: MintUrl, request: MintQuoteBolt11Request, ) -> Result; - /// Mint Quote status - async fn get_mint_quote_status( - &self, - mint_url: MintUrl, - quote_id: &str, - ) -> Result; - + async fn get_mint_quote_status(&self, quote_id: &str) + -> Result; /// Mint Tokens [NUT-04] - async fn post_mint( - &self, - mint_url: MintUrl, - request: MintBolt11Request, - ) -> Result; - + async fn post_mint(&self, request: MintBolt11Request) -> Result; /// Melt Quote [NUT-05] async fn post_melt_quote( &self, - mint_url: MintUrl, request: MeltQuoteBolt11Request, ) -> Result; - /// Melt Quote Status - async fn get_melt_quote_status( - &self, - mint_url: MintUrl, - quote_id: &str, - ) -> Result; - + async fn get_melt_quote_status(&self, quote_id: &str) + -> Result; /// Melt [NUT-05] /// [Nut-08] Lightning fee return if outputs defined - async fn post_melt( - &self, - mint_url: MintUrl, - request: MeltBolt11Request, - ) -> Result; - + async fn post_melt(&self, request: MeltBolt11Request) + -> Result; /// Split Token [NUT-06] - async fn post_swap( - &self, - mint_url: MintUrl, - request: SwapRequest, - ) -> Result; - + async fn post_swap(&self, request: SwapRequest) -> Result; /// Get Mint Info [NUT-06] - async fn get_mint_info(&self, mint_url: MintUrl) -> Result; - + async fn get_mint_info(&self) -> Result; /// Spendable check [NUT-07] async fn post_check_state( &self, - mint_url: MintUrl, request: CheckStateRequest, ) -> Result; - /// Restore request [NUT-13] - async fn post_restore( - &self, - mint_url: MintUrl, - request: RestoreRequest, - ) -> Result; + async fn post_restore(&self, request: RestoreRequest) -> Result; } diff --git a/crates/cdk/src/wallet/keysets.rs b/crates/cdk/src/wallet/keysets.rs index 03cfa51bc..a605a060c 100644 --- a/crates/cdk/src/wallet/keysets.rs +++ b/crates/cdk/src/wallet/keysets.rs @@ -13,10 +13,7 @@ impl Wallet { let keys = if let Some(keys) = self.localstore.get_keys(&keyset_id).await? { keys } else { - let keys = self - .client - .get_mint_keyset(self.mint_url.clone(), keyset_id) - .await?; + let keys = self.client.get_mint_keyset(keyset_id).await?; keys.verify_id()?; @@ -33,7 +30,7 @@ impl Wallet { /// Queries mint for all keysets #[instrument(skip(self))] pub async fn get_mint_keysets(&self) -> Result, Error> { - let keysets = self.client.get_mint_keysets(self.mint_url.clone()).await?; + let keysets = self.client.get_mint_keysets().await?; self.localstore .add_mint_keysets(self.mint_url.clone(), keysets.keysets.clone()) @@ -48,7 +45,7 @@ impl Wallet { /// keysets #[instrument(skip(self))] pub async fn get_active_mint_keysets(&self) -> Result, Error> { - let keysets = self.client.get_mint_keysets(self.mint_url.clone()).await?; + let keysets = self.client.get_mint_keysets().await?; let keysets = keysets.keysets; self.localstore diff --git a/crates/cdk/src/wallet/melt.rs b/crates/cdk/src/wallet/melt.rs index e8a0a0b51..766f1ea63 100644 --- a/crates/cdk/src/wallet/melt.rs +++ b/crates/cdk/src/wallet/melt.rs @@ -65,10 +65,7 @@ impl Wallet { options, }; - let quote_res = self - .client - .post_melt_quote(self.mint_url.clone(), quote_request) - .await?; + let quote_res = self.client.post_melt_quote(quote_request).await?; if quote_res.amount != amount { return Err(Error::IncorrectQuoteAmount); @@ -96,10 +93,7 @@ impl Wallet { &self, quote_id: &str, ) -> Result { - let response = self - .client - .get_melt_quote_status(self.mint_url.clone(), quote_id) - .await?; + let response = self.client.get_melt_quote_status(quote_id).await?; match self.localstore.get_melt_quote(quote_id).await? { Some(quote) => { @@ -160,7 +154,7 @@ impl Wallet { outputs: Some(premint_secrets.blinded_messages()), }; - let melt_response = self.client.post_melt(self.mint_url.clone(), request).await; + let melt_response = self.client.post_melt(request).await; let melt_response = match melt_response { Ok(melt_response) => melt_response, diff --git a/crates/cdk/src/wallet/mint.rs b/crates/cdk/src/wallet/mint.rs index 77b9bb706..c46ed3085 100644 --- a/crates/cdk/src/wallet/mint.rs +++ b/crates/cdk/src/wallet/mint.rs @@ -71,10 +71,7 @@ impl Wallet { description, }; - let quote_res = self - .client - .post_mint_quote(mint_url.clone(), request) - .await?; + let quote_res = self.client.post_mint_quote(request).await?; let quote = MintQuote { mint_url, @@ -94,10 +91,7 @@ impl Wallet { /// Check mint quote status #[instrument(skip(self, quote_id))] pub async fn mint_quote_state(&self, quote_id: &str) -> Result { - let response = self - .client - .get_mint_quote_status(self.mint_url.clone(), quote_id) - .await?; + let response = self.client.get_mint_quote_status(quote_id).await?; match self.localstore.get_mint_quote(quote_id).await? { Some(quote) => { @@ -224,10 +218,7 @@ impl Wallet { outputs: premint_secrets.blinded_messages(), }; - let mint_res = self - .client - .post_mint(self.mint_url.clone(), request) - .await?; + let mint_res = self.client.post_mint(request).await?; let keys = self.get_keyset_keys(active_keyset_id).await?; diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index bff6d4bfe..afcf8321b 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use bitcoin::bip32::Xpriv; use bitcoin::Network; -use client::HttpClientMethods; +use client::MintConnector; use tracing::instrument; use crate::amount::SplitTarget; @@ -57,7 +57,7 @@ pub struct Wallet { /// The targeted amount of proofs to have at each size pub target_proof_count: usize, xpriv: Xpriv, - client: Arc, + client: Arc, } impl Wallet { @@ -86,11 +86,12 @@ impl Wallet { target_proof_count: Option, ) -> Result { let xpriv = Xpriv::new_master(Network::Bitcoin, seed).expect("Could not create master key"); + let mint_url = MintUrl::from_str(mint_url)?; Ok(Self { - mint_url: MintUrl::from_str(mint_url)?, + mint_url: mint_url.clone(), unit, - client: Arc::new(HttpClient::new()), + client: Arc::new(HttpClient::new(mint_url)), localstore, xpriv, target_proof_count: target_proof_count.unwrap_or(3), @@ -98,8 +99,8 @@ impl Wallet { } /// Change HTTP client - pub fn set_client(&mut self, client: C) { - self.client = Arc::new(client); + pub fn set_client(&mut self, client: Arc) { + self.client = client; } /// Fee required for proof set @@ -160,10 +161,10 @@ impl Wallet { Ok(()) } - /// Qeury mint for current mint information + /// Query mint for current mint information #[instrument(skip(self))] pub async fn get_mint_info(&self) -> Result, Error> { - let mint_info = match self.client.get_mint_info(self.mint_url.clone()).await { + let mint_info = match self.client.get_mint_info().await { Ok(mint_info) => Some(mint_info), Err(err) => { tracing::warn!("Could not get mint info {}", err); @@ -277,10 +278,7 @@ impl Wallet { outputs: premint_secrets.blinded_messages(), }; - let response = self - .client - .post_restore(self.mint_url.clone(), restore_request) - .await?; + let response = self.client.post_restore(restore_request).await?; if response.signatures.is_empty() { empty_batch += 1; diff --git a/crates/cdk/src/wallet/proofs.rs b/crates/cdk/src/wallet/proofs.rs index c56956ce6..b6c0aba60 100644 --- a/crates/cdk/src/wallet/proofs.rs +++ b/crates/cdk/src/wallet/proofs.rs @@ -65,7 +65,7 @@ impl Wallet { let spendable = self .client - .post_check_state(self.mint_url.clone(), CheckStateRequest { ys: proof_ys }) + .post_check_state(CheckStateRequest { ys: proof_ys }) .await? .states; @@ -86,10 +86,7 @@ impl Wallet { pub async fn check_proofs_spent(&self, proofs: Proofs) -> Result, Error> { let spendable = self .client - .post_check_state( - self.mint_url.clone(), - CheckStateRequest { ys: proofs.ys()? }, - ) + .post_check_state(CheckStateRequest { ys: proofs.ys()? }) .await?; let spent_ys: Vec<_> = spendable .states diff --git a/crates/cdk/src/wallet/receive.rs b/crates/cdk/src/wallet/receive.rs index c98c3cc72..1a1cb75a4 100644 --- a/crates/cdk/src/wallet/receive.rs +++ b/crates/cdk/src/wallet/receive.rs @@ -128,10 +128,7 @@ impl Wallet { } } - let swap_response = self - .client - .post_swap(mint_url.clone(), pre_swap.swap_request) - .await?; + let swap_response = self.client.post_swap(pre_swap.swap_request).await?; // Proof to keep let recv_proofs = construct_proofs( diff --git a/crates/cdk/src/wallet/swap.rs b/crates/cdk/src/wallet/swap.rs index 784d180d2..e50c986d0 100644 --- a/crates/cdk/src/wallet/swap.rs +++ b/crates/cdk/src/wallet/swap.rs @@ -33,10 +33,7 @@ impl Wallet { ) .await?; - let swap_response = self - .client - .post_swap(mint_url.clone(), pre_swap.swap_request) - .await?; + let swap_response = self.client.post_swap(pre_swap.swap_request).await?; let active_keyset_id = pre_swap.pre_mint_secrets.keyset_id; diff --git a/flake.nix b/flake.nix index aebb30d00..f1931d2b1 100644 --- a/flake.nix +++ b/flake.nix @@ -53,7 +53,7 @@ targets = [ "wasm32-unknown-unknown" ]; # wasm }; - # Nighly for creating lock files + # Nightly for creating lock files nightly_toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { extensions = [ "rustfmt" "clippy" "rust-analyzer" ]; });