1use std::time::Duration;
2
3#[derive(Debug, Clone)]
5pub struct Config {
6 pub base_url: String,
8
9 pub timeout: Duration,
11
12 pub user_agent: String,
14
15 pub retry_enabled: bool,
17
18 pub max_retries: u32,
20}
21
22impl Default for Config {
23 fn default() -> Self {
24 Self::mainnet()
25 }
26}
27
28impl Config {
29 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 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 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 pub fn with_timeout(mut self, timeout: Duration) -> Self {
64 self.timeout = timeout;
65 self
66 }
67
68 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 pub fn with_retry(mut self, enabled: bool) -> Self {
76 self.retry_enabled = enabled;
77 self
78 }
79
80 pub fn with_max_retries(mut self, max_retries: u32) -> Self {
82 self.max_retries = max_retries;
83 self
84 }
85}