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 pub const ALL: &'static [Self] = &[
56 Self::Id,
57 Self::IdDescending,
58 Self::Balance,
59 Self::BalanceDescending,
60 Self::TotalTransactions,
61 Self::TotalTransactionsDescending,
62 Self::CreatedTimestamp,
63 Self::CreatedTimestampDescending,
64 Self::Owner,
65 Self::OwnerDescending,
66 ];
67
68 #[must_use]
70 pub const fn as_api_value(self) -> &'static str {
71 match self {
72 Self::Id => "id",
73 Self::IdDescending => "-id",
74 Self::Balance => "balance",
75 Self::BalanceDescending => "-balance",
76 Self::TotalTransactions => "total_transactions",
77 Self::TotalTransactionsDescending => "-total_transactions",
78 Self::CreatedTimestamp => "created_timestamp",
79 Self::CreatedTimestampDescending => "-created_timestamp",
80 Self::Owner => "owner",
81 Self::OwnerDescending => "-owner",
82 }
83 }
84}
85
86impl fmt::Display for IcIcrcAccountSort {
87 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
88 formatter.write_str(self.as_api_value())
89 }
90}
91
92#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
99pub enum IcIcrcHolderSort {
100 #[serde(rename = "balance")]
102 Balance,
103 #[serde(rename = "-balance")]
105 BalanceDescending,
106 #[serde(rename = "total_transactions")]
108 TotalTransactions,
109 #[serde(rename = "-total_transactions")]
111 TotalTransactionsDescending,
112 #[serde(rename = "created_timestamp")]
114 CreatedTimestamp,
115 #[serde(rename = "-created_timestamp")]
117 CreatedTimestampDescending,
118 #[serde(rename = "principal")]
120 Principal,
121 #[serde(rename = "-principal")]
123 PrincipalDescending,
124}
125
126impl IcIcrcHolderSort {
127 pub const ALL: &'static [Self] = &[
129 Self::Balance,
130 Self::BalanceDescending,
131 Self::TotalTransactions,
132 Self::TotalTransactionsDescending,
133 Self::CreatedTimestamp,
134 Self::CreatedTimestampDescending,
135 Self::Principal,
136 Self::PrincipalDescending,
137 ];
138
139 #[must_use]
141 pub const fn as_api_value(self) -> &'static str {
142 match self {
143 Self::Balance => "balance",
144 Self::BalanceDescending => "-balance",
145 Self::TotalTransactions => "total_transactions",
146 Self::TotalTransactionsDescending => "-total_transactions",
147 Self::CreatedTimestamp => "created_timestamp",
148 Self::CreatedTimestampDescending => "-created_timestamp",
149 Self::Principal => "principal",
150 Self::PrincipalDescending => "-principal",
151 }
152 }
153}
154
155impl fmt::Display for IcIcrcHolderSort {
156 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
157 formatter.write_str(self.as_api_value())
158 }
159}
160
161#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
168pub struct IcIcrcAccountListQuery {
169 pub owner: Option<String>,
171 pub after: Option<String>,
173 pub before: Option<String>,
175 pub limit: u16,
177 pub sort_by: IcIcrcAccountSort,
179}
180
181impl IcIcrcAccountListQuery {
182 #[must_use]
184 pub const fn new(limit: u16, sort_by: IcIcrcAccountSort) -> Self {
185 Self {
186 owner: None,
187 after: None,
188 before: None,
189 limit,
190 sort_by,
191 }
192 }
193
194 #[must_use]
196 pub fn with_owner(mut self, owner: impl Into<String>) -> Self {
197 self.owner = Some(owner.into());
198 self
199 }
200
201 #[must_use]
203 pub fn with_after(mut self, after: impl Into<String>) -> Self {
204 self.after = Some(after.into());
205 self
206 }
207
208 #[must_use]
210 pub fn with_before(mut self, before: impl Into<String>) -> Self {
211 self.before = Some(before.into());
212 self
213 }
214}
215
216#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
223pub struct IcIcrcHolderListQuery {
224 pub after: Option<String>,
226 pub before: Option<String>,
228 pub limit: u16,
230 pub sort_by: IcIcrcHolderSort,
232}
233
234impl IcIcrcHolderListQuery {
235 #[must_use]
237 pub const fn new(limit: u16, sort_by: IcIcrcHolderSort) -> Self {
238 Self {
239 after: None,
240 before: None,
241 limit,
242 sort_by,
243 }
244 }
245
246 #[must_use]
248 pub fn with_after(mut self, after: impl Into<String>) -> Self {
249 self.after = Some(after.into());
250 self
251 }
252
253 #[must_use]
255 pub fn with_before(mut self, before: impl Into<String>) -> Self {
256 self.before = Some(before.into());
257 self
258 }
259}
260
261#[derive(Clone, Debug, Eq, PartialEq)]
268pub struct IcIcrcAccountListRequest {
269 pub analytics: IcIcrcAnalyticsRequest,
271 pub query: IcIcrcAccountListQuery,
273}
274
275impl IcIcrcAccountListRequest {
276 #[must_use]
278 pub fn new(
279 dashboard: IcDashboardRequest,
280 ledger_canister_id: impl Into<String>,
281 query: IcIcrcAccountListQuery,
282 ) -> Self {
283 Self {
284 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
285 query,
286 }
287 }
288}
289
290#[derive(Clone, Debug, Eq, PartialEq)]
297pub struct IcIcrcAccountInfoRequest {
298 pub analytics: IcIcrcAnalyticsRequest,
300 pub account_id: String,
302}
303
304impl IcIcrcAccountInfoRequest {
305 #[must_use]
307 pub fn new(
308 dashboard: IcDashboardRequest,
309 ledger_canister_id: impl Into<String>,
310 account_id: impl Into<String>,
311 ) -> Self {
312 Self {
313 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
314 account_id: account_id.into(),
315 }
316 }
317}
318
319#[derive(Clone, Debug, Eq, PartialEq)]
326pub struct IcIcrcHolderListRequest {
327 pub analytics: IcIcrcAnalyticsRequest,
329 pub query: IcIcrcHolderListQuery,
331}
332
333impl IcIcrcHolderListRequest {
334 #[must_use]
336 pub fn new(
337 dashboard: IcDashboardRequest,
338 ledger_canister_id: impl Into<String>,
339 query: IcIcrcHolderListQuery,
340 ) -> Self {
341 Self {
342 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
343 query,
344 }
345 }
346}