use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use zakura_rpc::config::mining::{default_miner_address, MinerAddressType};
use crate::{components::With, BoxError};
mod loader;
const DENY_CONFIG_KEY_SUFFIX_LIST: [&str; 5] = [
"password",
"secret",
"token",
"cookie",
"private_key",
];
fn is_sensitive_leaf_key(leaf_key: &str) -> bool {
let key = leaf_key.to_ascii_lowercase();
DENY_CONFIG_KEY_SUFFIX_LIST
.iter()
.any(|deny_suffix| key.ends_with(deny_suffix))
}
#[derive(Clone, Default, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct ZakuradConfig {
pub consensus: zakura_consensus::config::Config,
pub metrics: crate::components::metrics::Config,
pub network: zakura_network::config::Config,
pub state: zakura_state::config::Config,
pub tracing: crate::components::tracing::Config,
pub sync: crate::components::sync::Config,
pub mempool: crate::components::mempool::Config,
pub rpc: zakura_rpc::config::rpc::Config,
pub mining: zakura_rpc::config::mining::Config,
pub health: crate::components::health::Config,
pub zcashd_compat: crate::components::zcashd_compat::Config,
}
impl ZakuradConfig {
pub fn mirrored_state_config(&self) -> zakura_state::Config {
let mut state_config = self.state.clone();
state_config.enable_zakura_header_seed_from_committed_blocks = self.network.v2_p2p();
state_config.checkpoint_sync = self.consensus.checkpoint_sync;
state_config.vct_fast_sync = self.consensus.vct_fast_sync_enabled();
state_config
}
pub fn load(config_path: Option<PathBuf>) -> Result<Self, BoxError> {
Self::load_with_env_prefixes(config_path, &["ZEBRA", "ZAKURA"])
}
pub(crate) fn load_with_env_prefixes(
config_path: Option<PathBuf>,
env_prefixes: &[&str],
) -> Result<Self, BoxError> {
loader::load(config_path, env_prefixes)
}
}
impl With<MinerAddressType> for ZakuradConfig {
fn with(mut self, miner_address_type: MinerAddressType) -> Self {
self.mining.miner_address = Some(
default_miner_address(self.network.network.kind(), &miner_address_type)
.parse()
.expect("valid hard-coded address"),
);
self
}
}