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 Config {
23    /// Create a new configuration with mainnet defaults
24    pub fn mainnet() -> Self {
25        Self {
26            base_url: crate::MAINNET_BASE_URL.to_string(),
27            timeout: Duration::from_secs(30),
28            user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
29            retry_enabled: true,
30            max_retries: 3,
31        }
32    }
33
34    /// Create a custom configuration
35    pub fn custom(base_url: impl Into<String>) -> Self {
36        Self {
37            base_url: base_url.into(),
38            timeout: Duration::from_secs(30),
39            user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
40            retry_enabled: true,
41            max_retries: 3,
42        }
43    }
44
45    /// Set request timeout
46    pub fn with_timeout(mut self, timeout: Duration) -> Self {
47        self.timeout = timeout;
48        self
49    }
50
51    /// Set user agent
52    pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
53        self.user_agent = user_agent.into();
54        self
55    }
56
57    /// Enable or disable retries
58    pub fn with_retry(mut self, enabled: bool) -> Self {
59        self.retry_enabled = enabled;
60        self
61    }
62
63    /// Set maximum number of retries
64    pub fn with_max_retries(mut self, max_retries: u32) -> Self {
65        self.max_retries = max_retries;
66        self
67    }
68}
69
70impl Default for Config {
71    fn default() -> Self {
72        Self::mainnet()
73    }
74}