use crate::error::Result;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use toml;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperatorConfig {
pub database_path: String,
pub benchmark_duration: u64,
pub benchmark_interval: u64,
pub keystore_path: PathBuf,
pub rpc_bind_address: String,
pub rpc_port: u16,
pub rpc_timeout: u64,
pub rpc_max_connections: u32,
pub quote_validity_duration_secs: u64,
}
impl Default for OperatorConfig {
fn default() -> Self {
OperatorConfig {
database_path: "./data/price_cache".to_string(),
benchmark_duration: 60,
benchmark_interval: 1,
keystore_path: PathBuf::from("./data/keystore"),
rpc_bind_address: String::from("127.0.0.1"),
rpc_port: 9000,
rpc_timeout: 30,
rpc_max_connections: 100,
quote_validity_duration_secs: 300, }
}
}
pub fn load_config_from_path<P: AsRef<Path>>(path: P) -> Result<OperatorConfig> {
let path = path.as_ref();
if !path.exists() {
return Ok(OperatorConfig::default());
}
let content = std::fs::read_to_string(path).map_err(|e| {
crate::error::PricingError::Config(format!("Failed to read config file: {e}"))
})?;
let config: OperatorConfig = toml::from_str(&content).map_err(|e| {
crate::error::PricingError::Config(format!("Failed to parse config file: {e}"))
})?;
Ok(config)
}