use std::time::Duration;
#[derive(Debug, Clone)]
pub struct Config {
pub base_url: String,
pub timeout: Duration,
pub user_agent: String,
pub retry_enabled: bool,
pub max_retries: u32,
}
impl Default for Config {
fn default() -> Self {
Self::mainnet()
}
}
impl Config {
pub fn mainnet() -> Self {
Self {
base_url: crate::MAINNET_BASE_URL.to_string(),
timeout: Duration::from_secs(30),
user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
retry_enabled: true,
max_retries: 3,
}
}
pub fn testnet() -> Self {
Self {
base_url: crate::TESTNET_BASE_URL.to_string(),
timeout: Duration::from_secs(30),
user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
retry_enabled: true,
max_retries: 3,
}
}
pub fn custom(base_url: impl Into<String>) -> Self {
Self {
base_url: base_url.into(),
timeout: Duration::from_secs(30),
user_agent: format!("jito-api-client/{}", env!("CARGO_PKG_VERSION")),
retry_enabled: true,
max_retries: 3,
}
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.user_agent = user_agent.into();
self
}
pub fn with_retry(mut self, enabled: bool) -> Self {
self.retry_enabled = enabled;
self
}
pub fn with_max_retries(mut self, max_retries: u32) -> Self {
self.max_retries = max_retries;
self
}
}