ic_query/ic/model/requests/
icrc_analytics.rs1use serde::Serialize;
8use std::fmt;
9
10#[derive(Clone, Debug, Eq, PartialEq)]
17pub struct IcIcrcAnalyticsRequest {
18 pub source_endpoint: String,
20 pub now_unix_secs: u64,
22 pub ledger_canister_id: String,
24}
25
26impl IcIcrcAnalyticsRequest {
27 #[must_use]
29 pub fn new(
30 source_endpoint: impl Into<String>,
31 now_unix_secs: u64,
32 ledger_canister_id: impl Into<String>,
33 ) -> Self {
34 Self {
35 source_endpoint: source_endpoint.into(),
36 now_unix_secs,
37 ledger_canister_id: ledger_canister_id.into(),
38 }
39 }
40}
41
42#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
49#[serde(rename_all = "snake_case")]
50pub enum IcIcrcIndexedCountKind {
51 Account,
53 Holder,
55 Transaction,
57}
58
59impl IcIcrcIndexedCountKind {
60 #[must_use]
62 pub const fn as_str(self) -> &'static str {
63 match self {
64 Self::Account => "account",
65 Self::Holder => "holder",
66 Self::Transaction => "transaction",
67 }
68 }
69
70 #[cfg(feature = "host")]
71 pub(crate) const fn resource_path_segment(self) -> &'static str {
72 match self {
73 Self::Account => "accounts",
74 Self::Holder => "holders",
75 Self::Transaction => "transactions",
76 }
77 }
78}
79
80impl fmt::Display for IcIcrcIndexedCountKind {
81 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
82 formatter.write_str(self.as_str())
83 }
84}
85
86#[derive(Clone, Debug, Eq, PartialEq)]
93pub struct IcIcrcIndexedCountRequest {
94 pub analytics: IcIcrcAnalyticsRequest,
96 pub kind: IcIcrcIndexedCountKind,
98}
99
100impl IcIcrcIndexedCountRequest {
101 #[must_use]
103 pub fn new(
104 source_endpoint: impl Into<String>,
105 now_unix_secs: u64,
106 ledger_canister_id: impl Into<String>,
107 kind: IcIcrcIndexedCountKind,
108 ) -> Self {
109 Self {
110 analytics: IcIcrcAnalyticsRequest::new(
111 source_endpoint,
112 now_unix_secs,
113 ledger_canister_id,
114 ),
115 kind,
116 }
117 }
118}
119
120#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
127pub struct IcIcrcTotalSupplyQuery {
128 pub start_unix_secs: u64,
130 pub end_unix_secs: u64,
132 pub step_secs: u32,
134}
135
136impl IcIcrcTotalSupplyQuery {
137 #[must_use]
139 pub const fn new(start_unix_secs: u64, end_unix_secs: u64, step_secs: u32) -> Self {
140 Self {
141 start_unix_secs,
142 end_unix_secs,
143 step_secs,
144 }
145 }
146}
147
148#[derive(Clone, Debug, Eq, PartialEq)]
155pub struct IcIcrcTotalSupplyRequest {
156 pub analytics: IcIcrcAnalyticsRequest,
158 pub query: IcIcrcTotalSupplyQuery,
160}
161
162impl IcIcrcTotalSupplyRequest {
163 #[must_use]
165 pub fn new(
166 source_endpoint: impl Into<String>,
167 now_unix_secs: u64,
168 ledger_canister_id: impl Into<String>,
169 query: IcIcrcTotalSupplyQuery,
170 ) -> Self {
171 Self {
172 analytics: IcIcrcAnalyticsRequest::new(
173 source_endpoint,
174 now_unix_secs,
175 ledger_canister_id,
176 ),
177 query,
178 }
179 }
180}