kobe_client/
config.rs

1use std::time::Duration;
2
3/// Configuration for the Jito API client
4#[derive(Debug, Clone)]
5pub struct Config {
6    /// Base URL for the API
7    pub base_url: String,
8
9    /// Request timeout in seconds
10    pub timeout: Duration,
11
12    /// User agent string
13    pub user_agent: String,
14
15    /// Enable retry on failure
16    pub retry_enabled: bool,
17
18    /// Maximum number of retries
19    pub max_retries: u32,
20}
21
22impl Default for Config {
23    fn default() -> Self {
24        Self::mainnet()
25    }
26}
27
28impl Config {
29    /// Create a new configuration with mainnet defaults
30    pub fn mainnet() -> Self {
31        Self {
32            base_url: crate::MAINNET_BASE_URL.to_string(),
33            timeout: Duration::from_secs(30),
34            user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
35            retry_enabled: true,
36            max_retries: 3,
37        }
38    }
39
40    /// Create a custom configuration
41    pub fn custom(base_url: impl Into<String>) -> Self {
42        Self {
43            base_url: base_url.into(),
44            timeout: Duration::from_secs(30),
45            user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
46            retry_enabled: true,
47            max_retries: 3,
48        }
49    }
50
51    /// Set request timeout
52    pub fn with_timeout(mut self, timeout: Duration) -> Self {
53        self.timeout = timeout;
54        self
55    }
56
57    /// Set user agent
58    pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
59        self.user_agent = user_agent.into();
60        self
61    }
62
63    /// Enable or disable retries
64    pub fn with_retry(mut self, enabled: bool) -> Self {
65        self.retry_enabled = enabled;
66        self
67    }
68
69    /// Set maximum number of retries
70    pub fn with_max_retries(mut self, max_retries: u32) -> Self {
71        self.max_retries = max_retries;
72        self
73    }
74}