use crate::error::IndexerError;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct IndexerConfig {
pub tcp_active: bool,
pub listen_port: Option<u16>,
pub lightwalletd_port: u16,
pub zebrad_port: u16,
pub node_user: Option<String>,
pub node_password: Option<String>,
pub max_queue_size: u16,
pub max_worker_pool_size: u16,
pub idle_worker_pool_size: u16,
}
impl IndexerConfig {
pub fn check_config(&self) -> Result<(), IndexerError> {
if !self.tcp_active {
return Err(IndexerError::ConfigError(
"Cannot start server with no ingestors selected.".to_string(),
));
}
if self.tcp_active && self.listen_port.is_none() {
return Err(IndexerError::ConfigError(
"TCP is active but no address provided.".to_string(),
));
}
Ok(())
}
}
impl Default for IndexerConfig {
fn default() -> Self {
Self {
tcp_active: true,
listen_port: Some(8080),
lightwalletd_port: 9067,
zebrad_port: 18232,
node_user: Some("xxxxxx".to_string()),
node_password: Some("xxxxxx".to_string()),
max_queue_size: 1024,
max_worker_pool_size: 32,
idle_worker_pool_size: 4,
}
}
}
pub fn load_config(file_path: &std::path::PathBuf) -> IndexerConfig {
let mut config = IndexerConfig::default();
if let Ok(contents) = std::fs::read_to_string(file_path) {
if let Ok(parsed_config) = toml::from_str::<IndexerConfig>(&contents) {
config = IndexerConfig {
tcp_active: parsed_config.tcp_active,
listen_port: parsed_config.listen_port.or(config.listen_port),
lightwalletd_port: parsed_config.lightwalletd_port,
zebrad_port: parsed_config.zebrad_port,
node_user: parsed_config.node_user.or(config.node_user),
node_password: parsed_config.node_password.or(config.node_password),
max_queue_size: parsed_config.max_queue_size,
max_worker_pool_size: parsed_config.max_worker_pool_size,
idle_worker_pool_size: parsed_config.idle_worker_pool_size,
};
}
}
config
}