diff --git a/Cargo.lock b/Cargo.lock index 38fe350..3c43da1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3408,9 +3408,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ "ring", "rustls-pki-types", diff --git a/src/client.rs b/src/client.rs index 0de164a..483607b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -91,16 +91,21 @@ pub struct ClobClient { buffer_pool: std::sync::Arc, } +#[derive(Default)] +struct ClientAuthConfig { + signer: Option, + api_creds: Option, + builder_code: Option, + sig_type: Option, + funder: Option
, +} + impl ClobClient { fn build_client( host: &str, chain_id: u64, http_client: Client, - signer: Option, - api_creds: Option, - builder_code: Option, - sig_type: Option, - funder: Option
, + auth: ClientAuthConfig, ) -> Self { let dns_cache = tokio::runtime::Handle::try_current().ok().and_then(|_| { tokio::task::block_in_place(|| { @@ -132,17 +137,18 @@ impl ClobClient { }); } - let order_builder = signer + let order_builder = auth + .signer .clone() - .map(|signer| crate::orders::OrderBuilder::new(signer, sig_type, funder)); + .map(|signer| crate::orders::OrderBuilder::new(signer, auth.sig_type, auth.funder)); Self { http_client, base_url: host.to_string(), chain_id, - signer, - api_creds, - builder_code, + signer: auth.signer, + api_creds: auth.api_creds, + builder_code: auth.builder_code, order_builder, dns_cache, connection_manager, @@ -154,7 +160,7 @@ impl ClobClient { /// Now includes DNS caching, connection management, and buffer pooling pub fn new(host: &str) -> Self { let http_client = build_http_client(host, None, None); - Self::build_client(host, 137, http_client, None, None, None, None, None) + Self::build_client(host, 137, http_client, ClientAuthConfig::default()) } /// Create a V2-native client from config. @@ -195,11 +201,13 @@ impl ClobClient { &config.base_url, config.chain, http_client, - signer, - config.api_credentials, - config.builder_code, - sig_type, - funder, + ClientAuthConfig { + signer, + api_creds: config.api_credentials, + builder_code: config.builder_code, + sig_type, + funder, + }, )) } @@ -211,7 +219,7 @@ impl ClobClient { .build() .expect("Failed to build reqwest client") }); - Self::build_client(host, 137, http_client, None, None, None, None, None) + Self::build_client(host, 137, http_client, ClientAuthConfig::default()) } /// Create a client optimized for internet connections @@ -222,7 +230,7 @@ impl ClobClient { .build() .expect("Failed to build reqwest client") }); - Self::build_client(host, 137, http_client, None, None, None, None, None) + Self::build_client(host, 137, http_client, ClientAuthConfig::default()) } /// Create a client with L1 headers (for authentication)