lssa/lez/indexer/core/src/config.rs

65 lines
2.3 KiB
Rust
Raw Normal View History

use std::{fs::File, io::BufReader, path::Path, time::Duration};
2026-01-23 10:39:34 +02:00
use anyhow::{Context as _, Result};
2026-03-13 18:23:39 +02:00
use common::config::BasicAuth;
use cross_zone_inbox_core::CrossZoneConfig;
use humantime_serde;
use lee::AccountId;
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 {
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 {
#[serde(with = "humantime_serde")]
pub consensus_info_polling_interval: Duration,
2026-04-29 14:05:23 +02:00
pub bedrock_config: ClientConfig,
2026-01-22 14:44:48 +02:00
pub channel_id: ChannelId,
/// Cross-zone configuration. `None` disables the indexer's cross-zone handling.
#[serde(default)]
pub cross_zone: Option<CrossZoneConfig>,
/// Bridge-lock holdings to seed into genesis, mirroring the sequencer's
/// `SupplyBridgeLockHolding` actions. They are not produced by any
/// transaction, so the indexer must seed them to match the sequencer's state.
#[serde(default)]
pub bridge_lock_holdings: Vec<BridgeLockHolding>,
/// Whether to wipe the indexer store and re-index from scratch when the startup
/// chain-identity check finds the channel serving a different block than the one
/// stored at the same id.
///
/// Defaults to `false`: on mismatch the indexer refuses to start.
#[serde(default)]
pub allow_chain_reset: bool,
}
/// A genesis-funded bridge-lock holder balance, configured identically on the
/// sequencer (via `SupplyBridgeLockHolding`) and the indexer.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BridgeLockHolding {
pub holder: AccountId,
pub amount: u128,
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
}
}