ic_query/ic/model/requests/
icrc_index.rs1use super::IcDashboardRequest;
8
9use super::IcIcrcAnalyticsRequest;
10use serde::Serialize;
11use std::fmt;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
20pub enum IcIcrcAccountSort {
21 #[serde(rename = "id")]
23 Id,
24 #[serde(rename = "-id")]
26 IdDescending,
27 #[serde(rename = "balance")]
29 Balance,
30 #[serde(rename = "-balance")]
32 BalanceDescending,
33 #[serde(rename = "total_transactions")]
35 TotalTransactions,
36 #[serde(rename = "-total_transactions")]
38 TotalTransactionsDescending,
39 #[serde(rename = "created_timestamp")]
41 CreatedTimestamp,
42 #[serde(rename = "-created_timestamp")]
44 CreatedTimestampDescending,
45 #[serde(rename = "owner")]
47 Owner,
48 #[serde(rename = "-owner")]
50 OwnerDescending,
51}
52
53impl IcIcrcAccountSort {
54 #[must_use]
56 pub const fn as_api_value(self) -> &'static str {
57 match self {
58 Self::Id => "id",
59 Self::IdDescending => "-id",
60 Self::Balance => "balance",
61 Self::BalanceDescending => "-balance",
62 Self::TotalTransactions => "total_transactions",
63 Self::TotalTransactionsDescending => "-total_transactions",
64 Self::CreatedTimestamp => "created_timestamp",
65 Self::CreatedTimestampDescending => "-created_timestamp",
66 Self::Owner => "owner",
67 Self::OwnerDescending => "-owner",
68 }
69 }
70}
71
72impl fmt::Display for IcIcrcAccountSort {
73 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
74 formatter.write_str(self.as_api_value())
75 }
76}
77
78#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
85pub enum IcIcrcHolderSort {
86 #[serde(rename = "balance")]
88 Balance,
89 #[serde(rename = "-balance")]
91 BalanceDescending,
92 #[serde(rename = "total_transactions")]
94 TotalTransactions,
95 #[serde(rename = "-total_transactions")]
97 TotalTransactionsDescending,
98 #[serde(rename = "created_timestamp")]
100 CreatedTimestamp,
101 #[serde(rename = "-created_timestamp")]
103 CreatedTimestampDescending,
104 #[serde(rename = "principal")]
106 Principal,
107 #[serde(rename = "-principal")]
109 PrincipalDescending,
110}
111
112impl IcIcrcHolderSort {
113 #[must_use]
115 pub const fn as_api_value(self) -> &'static str {
116 match self {
117 Self::Balance => "balance",
118 Self::BalanceDescending => "-balance",
119 Self::TotalTransactions => "total_transactions",
120 Self::TotalTransactionsDescending => "-total_transactions",
121 Self::CreatedTimestamp => "created_timestamp",
122 Self::CreatedTimestampDescending => "-created_timestamp",
123 Self::Principal => "principal",
124 Self::PrincipalDescending => "-principal",
125 }
126 }
127}
128
129impl fmt::Display for IcIcrcHolderSort {
130 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
131 formatter.write_str(self.as_api_value())
132 }
133}
134
135#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
142pub struct IcIcrcAccountListQuery {
143 pub owner: Option<String>,
145 pub after: Option<String>,
147 pub before: Option<String>,
149 pub limit: u16,
151 pub sort_by: IcIcrcAccountSort,
153}
154
155impl IcIcrcAccountListQuery {
156 #[must_use]
158 pub const fn new(limit: u16, sort_by: IcIcrcAccountSort) -> Self {
159 Self {
160 owner: None,
161 after: None,
162 before: None,
163 limit,
164 sort_by,
165 }
166 }
167
168 #[must_use]
170 pub fn with_owner(mut self, owner: impl Into<String>) -> Self {
171 self.owner = Some(owner.into());
172 self
173 }
174
175 #[must_use]
177 pub fn with_after(mut self, after: impl Into<String>) -> Self {
178 self.after = Some(after.into());
179 self
180 }
181
182 #[must_use]
184 pub fn with_before(mut self, before: impl Into<String>) -> Self {
185 self.before = Some(before.into());
186 self
187 }
188}
189
190#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
197pub struct IcIcrcHolderListQuery {
198 pub after: Option<String>,
200 pub before: Option<String>,
202 pub limit: u16,
204 pub sort_by: IcIcrcHolderSort,
206}
207
208impl IcIcrcHolderListQuery {
209 #[must_use]
211 pub const fn new(limit: u16, sort_by: IcIcrcHolderSort) -> Self {
212 Self {
213 after: None,
214 before: None,
215 limit,
216 sort_by,
217 }
218 }
219
220 #[must_use]
222 pub fn with_after(mut self, after: impl Into<String>) -> Self {
223 self.after = Some(after.into());
224 self
225 }
226
227 #[must_use]
229 pub fn with_before(mut self, before: impl Into<String>) -> Self {
230 self.before = Some(before.into());
231 self
232 }
233}
234
235#[derive(Clone, Debug, Eq, PartialEq)]
242pub struct IcIcrcAccountListRequest {
243 pub analytics: IcIcrcAnalyticsRequest,
245 pub query: IcIcrcAccountListQuery,
247}
248
249impl IcIcrcAccountListRequest {
250 #[must_use]
252 pub fn new(
253 dashboard: IcDashboardRequest,
254 ledger_canister_id: impl Into<String>,
255 query: IcIcrcAccountListQuery,
256 ) -> Self {
257 Self {
258 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
259 query,
260 }
261 }
262}
263
264#[derive(Clone, Debug, Eq, PartialEq)]
271pub struct IcIcrcAccountInfoRequest {
272 pub analytics: IcIcrcAnalyticsRequest,
274 pub account_id: String,
276}
277
278impl IcIcrcAccountInfoRequest {
279 #[must_use]
281 pub fn new(
282 dashboard: IcDashboardRequest,
283 ledger_canister_id: impl Into<String>,
284 account_id: impl Into<String>,
285 ) -> Self {
286 Self {
287 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
288 account_id: account_id.into(),
289 }
290 }
291}
292
293#[derive(Clone, Debug, Eq, PartialEq)]
300pub struct IcIcrcHolderListRequest {
301 pub analytics: IcIcrcAnalyticsRequest,
303 pub query: IcIcrcHolderListQuery,
305}
306
307impl IcIcrcHolderListRequest {
308 #[must_use]
310 pub fn new(
311 dashboard: IcDashboardRequest,
312 ledger_canister_id: impl Into<String>,
313 query: IcIcrcHolderListQuery,
314 ) -> Self {
315 Self {
316 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
317 query,
318 }
319 }
320}