mod cache;
pub(in crate::nns) use cache::{load_nns_leaf_json_cache, write_nns_leaf_json_refresh_cache};
use std::path::{Path, PathBuf};
pub(in crate::nns) trait NnsLeafCacheRequest: Clone {
fn from_root_network(icp_root: &Path, network: &str) -> Self;
fn icp_root(&self) -> &Path;
fn network(&self) -> &str;
}
pub(in crate::nns) trait NnsLeafRefreshRequest {
type Cache: NnsLeafCacheRequest;
fn cache(&self) -> &Self::Cache;
fn now_unix_secs(&self) -> u64;
fn lock_stale_after_seconds(&self) -> u64;
fn dry_run(&self) -> bool;
fn output_path(&self) -> Option<&Path>;
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::nns) struct NnsLeafCachePaths {
pub(in crate::nns) cache_path: PathBuf,
pub(in crate::nns) lock_path: PathBuf,
}
impl NnsLeafCachePaths {
#[must_use]
pub(in crate::nns) fn for_component(
icp_root: &Path,
component_dir: &str,
network: &str,
cache_file: &str,
) -> Self {
let cache_dir = icp_root.join(".icq").join(component_dir).join(network);
Self {
cache_path: cache_dir.join(cache_file),
lock_path: cache_dir.join("refresh.lock"),
}
}
}
#[cfg(all(test, feature = "host"))]
mod tests;