ic-query 0.27.1

Internet Computer query library for NNS, SNS, ICRC, system canisters, and public network metadata
Documentation
//! Module: ic::model::requests::icrc_analytics
//!
//! Responsibility: bounded official ICRC analytics request contracts.
//! Does not own: native ledger queries, transport, source validation, or reports.
//! Boundary: shares one ledger target while keeping series bounds operation-specific.

use serde::Serialize;

///
/// IcIcrcAnalyticsRequest
///
/// Shared endpoint, collection time, and ledger target for official ICRC analytics.
///

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcAnalyticsRequest {
    /// Official ICRC analytics API base endpoint.
    pub source_endpoint: String,
    /// Collection time as Unix seconds.
    pub now_unix_secs: u64,
    /// ICRC ledger canister principal requested from the analytics service.
    pub ledger_canister_id: String,
}

impl IcIcrcAnalyticsRequest {
    /// Construct one official ICRC analytics target.
    #[must_use]
    pub fn new(
        source_endpoint: impl Into<String>,
        now_unix_secs: u64,
        ledger_canister_id: impl Into<String>,
    ) -> Self {
        Self {
            source_endpoint: source_endpoint.into(),
            now_unix_secs,
            ledger_canister_id: ledger_canister_id.into(),
        }
    }
}

///
/// IcIcrcTotalSupplyQuery
///
/// One explicitly bounded total-supply series query for an ICRC ledger.
///

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcIcrcTotalSupplyQuery {
    /// Inclusive query start as Unix seconds.
    pub start_unix_secs: u64,
    /// Inclusive query end as Unix seconds.
    pub end_unix_secs: u64,
    /// Requested observation interval in seconds.
    pub step_secs: u32,
}

impl IcIcrcTotalSupplyQuery {
    /// Construct one explicit total-supply query window.
    #[must_use]
    pub const fn new(start_unix_secs: u64, end_unix_secs: u64, step_secs: u32) -> Self {
        Self {
            start_unix_secs,
            end_unix_secs,
            step_secs,
        }
    }
}

///
/// IcIcrcTotalSupplyRequest
///
/// Request accepted by the bounded official ICRC analytics report builder.
///

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcTotalSupplyRequest {
    /// Shared analytics endpoint, collection time, and ledger identity.
    pub analytics: IcIcrcAnalyticsRequest,
    /// Explicitly bounded total-supply query.
    pub query: IcIcrcTotalSupplyQuery,
}

impl IcIcrcTotalSupplyRequest {
    /// Construct one bounded live ICRC total-supply analytics request.
    #[must_use]
    pub fn new(
        source_endpoint: impl Into<String>,
        now_unix_secs: u64,
        ledger_canister_id: impl Into<String>,
        query: IcIcrcTotalSupplyQuery,
    ) -> Self {
        Self {
            analytics: IcIcrcAnalyticsRequest::new(
                source_endpoint,
                now_unix_secs,
                ledger_canister_id,
            ),
            query,
        }
    }
}