lssa/indexer/core/src/config.rs

59 lines
1.7 KiB
Rust
Raw Normal View History

2026-01-30 12:51:18 +02:00
use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
time::Duration,
2026-01-30 12:51:18 +02:00
};
2026-01-23 10:39:34 +02:00
use anyhow::{Context as _, Result};
pub use bedrock_client::BackoffConfig;
2026-01-30 12:51:18 +02:00
use common::{
2026-02-04 14:57:38 +02:00
block::{AccountInitialData, CommitmentsInitialData},
config::BasicAuth,
};
use humantime_serde;
pub use logos_blockchain_core::mantle::ops::channel::ChannelId;
2026-01-13 15:11:51 +02:00
use serde::{Deserialize, Serialize};
2026-01-27 09:46:31 +02:00
use url::Url;
2026-01-12 15:51:24 +02:00
2026-01-22 14:44:48 +02:00
#[derive(Debug, Clone, Serialize, Deserialize)]
2026-02-03 11:36:07 +02:00
pub struct ClientConfig {
/// For individual RPC requests we use Fibonacci backoff retry strategy.
pub backoff: BackoffConfig,
2026-01-27 09:46:31 +02:00
pub addr: Url,
#[serde(default, skip_serializing_if = "Option::is_none")]
2026-01-27 09:46:31 +02:00
pub auth: Option<BasicAuth>,
2026-01-22 14:44:48 +02:00
}
2026-01-13 15:11:51 +02:00
#[derive(Debug, Clone, Serialize, Deserialize)]
2026-01-12 15:51:24 +02:00
pub struct IndexerConfig {
2026-03-10 00:17:43 +03:00
/// Home dir of sequencer storage.
2026-01-30 12:51:18 +02:00
pub home: PathBuf,
2026-03-10 00:17:43 +03:00
/// List of initial accounts data.
2026-01-30 12:51:18 +02:00
pub initial_accounts: Vec<AccountInitialData>,
2026-03-10 00:17:43 +03:00
/// List of initial commitments.
2026-01-30 12:51:18 +02:00
pub initial_commitments: Vec<CommitmentsInitialData>,
2026-03-10 00:17:43 +03:00
/// Sequencers signing key.
2026-02-10 14:03:56 +02:00
pub signing_key: [u8; 32],
#[serde(with = "humantime_serde")]
pub consensus_info_polling_interval: Duration,
2026-02-03 11:36:07 +02:00
pub bedrock_client_config: ClientConfig,
2026-01-22 14:44:48 +02:00
pub channel_id: ChannelId,
2026-01-12 15:51:24 +02:00
}
2026-01-23 10:39:34 +02:00
impl IndexerConfig {
2026-03-09 18:27:56 +03:00
pub fn from_path(config_path: &Path) -> Result<Self> {
2026-03-03 23:21:08 +03:00
let file = File::open(config_path).with_context(|| {
format!("Failed to open indexer config at {}", config_path.display())
})?;
2026-01-23 10:39:34 +02:00
let reader = BufReader::new(file);
2026-03-03 23:21:08 +03:00
serde_json::from_reader(reader).with_context(|| {
format!(
"Failed to parse indexer config at {}",
config_path.display()
)
})
2026-01-23 10:39:34 +02:00
}
}