ic-query 0.95.0

Internet Computer query library for CloudEngine, NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
//! Module: nns::inventory_request
//!
//! Responsibility: define shared request contracts for Registry-derived NNS inventory reports.
//! Does not own: family-specific filters, source calls, cache IO, or report projection.
//! Boundary: keeps identical cache, list, info, and refresh provenance from drifting by family.

use std::path::PathBuf;

///
/// NnsInventoryCacheRequest
///
/// Shared cache identity for Registry-derived NNS inventory reports.
///

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsInventoryCacheRequest {
    pub cache_root: PathBuf,
    pub network: String,
}

impl NnsInventoryCacheRequest {
    #[must_use]
    pub fn new(cache_root: impl Into<PathBuf>, network: impl Into<String>) -> Self {
        Self {
            cache_root: cache_root.into(),
            network: network.into(),
        }
    }
}

///
/// NnsInventoryListRequest
///
/// Shared request for a complete Registry-derived NNS inventory report.
///

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsInventoryListRequest {
    pub cache: NnsInventoryCacheRequest,
    pub source_endpoint: String,
    pub now_unix_secs: u64,
}

impl NnsInventoryListRequest {
    #[must_use]
    pub fn new(
        cache: NnsInventoryCacheRequest,
        source_endpoint: impl Into<String>,
        now_unix_secs: u64,
    ) -> Self {
        Self {
            cache,
            source_endpoint: source_endpoint.into(),
            now_unix_secs,
        }
    }
}

#[cfg(feature = "nns-host")]
impl NnsInventoryListRequest {
    /// Derive live collection provenance; cached reports retain their stored provenance.
    #[must_use]
    pub fn source_request(&self) -> crate::report::CollectionSourceRequest {
        crate::report::CollectionSourceRequest::from_unix_secs(
            &self.cache.network,
            &self.source_endpoint,
            self.now_unix_secs,
            "ic-query",
        )
    }
}

///
/// NnsInventoryInfoRequest
///
/// Shared request for one Registry-derived NNS inventory row selected by id or prefix.
///

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsInventoryInfoRequest {
    pub cache: NnsInventoryCacheRequest,
    pub source_endpoint: String,
    pub input: String,
    pub now_unix_secs: u64,
}

impl NnsInventoryInfoRequest {
    #[cfg(feature = "nns-host")]
    pub(in crate::nns) fn to_list_request(&self) -> NnsInventoryListRequest {
        NnsInventoryListRequest {
            cache: self.cache.clone(),
            source_endpoint: self.source_endpoint.clone(),
            now_unix_secs: self.now_unix_secs,
        }
    }

    #[must_use]
    pub fn new(
        cache: NnsInventoryCacheRequest,
        source_endpoint: impl Into<String>,
        input: impl Into<String>,
        now_unix_secs: u64,
    ) -> Self {
        Self {
            cache,
            source_endpoint: source_endpoint.into(),
            input: input.into(),
            now_unix_secs,
        }
    }
}

///
/// NnsInventoryRefreshRequest
///
/// Shared host request for refreshing one Registry-derived NNS inventory cache.
///

#[cfg(feature = "nns-host")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NnsInventoryRefreshRequest {
    pub cache: NnsInventoryCacheRequest,
    pub source_endpoint: String,
    pub now_unix_secs: u64,

    pub dry_run: bool,
    pub output_path: Option<PathBuf>,
}

#[cfg(feature = "nns-host")]
impl NnsInventoryRefreshRequest {
    #[must_use]
    pub fn new(
        cache: NnsInventoryCacheRequest,
        source_endpoint: impl Into<String>,
        now_unix_secs: u64,
    ) -> Self {
        Self {
            cache,
            source_endpoint: source_endpoint.into(),
            now_unix_secs,

            dry_run: false,
            output_path: None,
        }
    }
}