ckb_app_config/configs/
indexer.rsuse super::rich_indexer::RichIndexerConfig;
use ckb_types::H256;
use serde::{Deserialize, Serialize};
use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct IndexerConfig {
#[serde(default)]
pub store: PathBuf,
#[serde(default)]
pub secondary_path: PathBuf,
#[serde(default = "default_poll_interval")]
pub poll_interval: u64,
#[serde(default)]
pub index_tx_pool: bool,
#[serde(default)]
pub block_filter: Option<String>,
#[serde(default)]
pub cell_filter: Option<String>,
#[serde(default)]
pub db_background_jobs: Option<NonZeroUsize>,
#[serde(default)]
pub db_keep_log_file_num: Option<NonZeroUsize>,
#[serde(default)]
pub init_tip_hash: Option<H256>,
#[serde(default)]
pub request_limit: Option<usize>,
#[serde(default)]
pub rich_indexer: RichIndexerConfig,
}
const fn default_poll_interval() -> u64 {
2
}
impl Default for IndexerConfig {
fn default() -> Self {
IndexerConfig {
poll_interval: 2,
index_tx_pool: false,
store: PathBuf::new(),
secondary_path: PathBuf::new(),
block_filter: None,
cell_filter: None,
db_background_jobs: None,
db_keep_log_file_num: None,
init_tip_hash: None,
request_limit: None,
rich_indexer: RichIndexerConfig::default(),
}
}
}
impl IndexerConfig {
pub fn adjust<P: AsRef<Path>>(&mut self, root_dir: &Path, indexer_dir: P) {
_adjust(root_dir, indexer_dir.as_ref(), &mut self.store, "store");
_adjust(
root_dir,
indexer_dir.as_ref(),
&mut self.secondary_path,
"secondary_path",
);
_adjust(
root_dir,
indexer_dir.as_ref(),
&mut self.rich_indexer.store,
"sqlite/sqlite.db",
);
}
}
fn _adjust(root_dir: &Path, indexer_dir: &Path, target: &mut PathBuf, sub: &str) {
if target.to_str().is_none() || target.to_str() == Some("") {
*target = indexer_dir.to_path_buf().join(sub);
} else if target.is_relative() {
*target = root_dir.to_path_buf().join(&target)
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct IndexerSyncConfig {
#[serde(default)]
pub secondary_path: PathBuf,
#[serde(default = "default_poll_interval")]
pub poll_interval: u64,
pub index_tx_pool: bool,
#[serde(default)]
pub db_keep_log_file_num: Option<NonZeroUsize>,
}
impl From<&IndexerConfig> for IndexerSyncConfig {
fn from(config: &IndexerConfig) -> IndexerSyncConfig {
IndexerSyncConfig {
secondary_path: config.secondary_path.clone(),
poll_interval: config.poll_interval,
index_tx_pool: config.index_tx_pool,
db_keep_log_file_num: config.db_keep_log_file_num,
}
}
}