Skip to main content

ic_query/ic/model/requests/
icrc_analytics.rs

1//! Module: ic::model::requests::icrc_analytics
2//!
3//! Responsibility: bounded official ICRC analytics request contracts.
4//! Does not own: native ledger queries, transport, source validation, or reports.
5//! Boundary: shares one ledger target while keeping series bounds operation-specific.
6
7use serde::Serialize;
8
9///
10/// IcIcrcAnalyticsRequest
11///
12/// Shared endpoint, collection time, and ledger target for official ICRC analytics.
13///
14
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct IcIcrcAnalyticsRequest {
17    /// Official ICRC analytics API base endpoint.
18    pub source_endpoint: String,
19    /// Collection time as Unix seconds.
20    pub now_unix_secs: u64,
21    /// ICRC ledger canister principal requested from the analytics service.
22    pub ledger_canister_id: String,
23}
24
25impl IcIcrcAnalyticsRequest {
26    /// Construct one official ICRC analytics target.
27    #[must_use]
28    pub fn new(
29        source_endpoint: impl Into<String>,
30        now_unix_secs: u64,
31        ledger_canister_id: impl Into<String>,
32    ) -> Self {
33        Self {
34            source_endpoint: source_endpoint.into(),
35            now_unix_secs,
36            ledger_canister_id: ledger_canister_id.into(),
37        }
38    }
39}
40
41///
42/// IcIcrcTotalSupplyQuery
43///
44/// One explicitly bounded total-supply series query for an ICRC ledger.
45///
46
47#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
48pub struct IcIcrcTotalSupplyQuery {
49    /// Inclusive query start as Unix seconds.
50    pub start_unix_secs: u64,
51    /// Inclusive query end as Unix seconds.
52    pub end_unix_secs: u64,
53    /// Requested observation interval in seconds.
54    pub step_secs: u32,
55}
56
57impl IcIcrcTotalSupplyQuery {
58    /// Construct one explicit total-supply query window.
59    #[must_use]
60    pub const fn new(start_unix_secs: u64, end_unix_secs: u64, step_secs: u32) -> Self {
61        Self {
62            start_unix_secs,
63            end_unix_secs,
64            step_secs,
65        }
66    }
67}
68
69///
70/// IcIcrcTotalSupplyRequest
71///
72/// Request accepted by the bounded official ICRC analytics report builder.
73///
74
75#[derive(Clone, Debug, Eq, PartialEq)]
76pub struct IcIcrcTotalSupplyRequest {
77    /// Shared analytics endpoint, collection time, and ledger identity.
78    pub analytics: IcIcrcAnalyticsRequest,
79    /// Explicitly bounded total-supply query.
80    pub query: IcIcrcTotalSupplyQuery,
81}
82
83impl IcIcrcTotalSupplyRequest {
84    /// Construct one bounded live ICRC total-supply analytics request.
85    #[must_use]
86    pub fn new(
87        source_endpoint: impl Into<String>,
88        now_unix_secs: u64,
89        ledger_canister_id: impl Into<String>,
90        query: IcIcrcTotalSupplyQuery,
91    ) -> Self {
92        Self {
93            analytics: IcIcrcAnalyticsRequest::new(
94                source_endpoint,
95                now_unix_secs,
96                ledger_canister_id,
97            ),
98            query,
99        }
100    }
101}