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 new configuration with testnet defaults
41    pub fn testnet() -> Self {
42        Self {
43            base_url: crate::TESTNET_BASE_URL.to_string(),
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    /// Create a custom configuration
52    pub fn custom(base_url: impl Into<String>) -> Self {
53        Self {
54            base_url: base_url.into(),
55            timeout: Duration::from_secs(30),
56            user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
57            retry_enabled: true,
58            max_retries: 3,
59        }
60    }
61
62    /// Set request timeout
63    pub fn with_timeout(mut self, timeout: Duration) -> Self {
64        self.timeout = timeout;
65        self
66    }
67
68    /// Set user agent
69    pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
70        self.user_agent = user_agent.into();
71        self
72    }
73
74    /// Enable or disable retries
75    pub fn with_retry(mut self, enabled: bool) -> Self {
76        self.retry_enabled = enabled;
77        self
78    }
79
80    /// Set maximum number of retries
81    pub fn with_max_retries(mut self, max_retries: u32) -> Self {
82        self.max_retries = max_retries;
83        self
84    }
85}