ic_query/ic/model/requests/
icrc_index.rs1use super::IcIcrcAnalyticsRequest;
8use serde::Serialize;
9use std::fmt;
10
11#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
18pub enum IcIcrcAccountSort {
19 #[serde(rename = "id")]
21 Id,
22 #[serde(rename = "-id")]
24 IdDescending,
25 #[serde(rename = "balance")]
27 Balance,
28 #[serde(rename = "-balance")]
30 BalanceDescending,
31 #[serde(rename = "total_transactions")]
33 TotalTransactions,
34 #[serde(rename = "-total_transactions")]
36 TotalTransactionsDescending,
37 #[serde(rename = "created_timestamp")]
39 CreatedTimestamp,
40 #[serde(rename = "-created_timestamp")]
42 CreatedTimestampDescending,
43 #[serde(rename = "owner")]
45 Owner,
46 #[serde(rename = "-owner")]
48 OwnerDescending,
49}
50
51impl IcIcrcAccountSort {
52 #[must_use]
54 pub const fn as_api_value(self) -> &'static str {
55 match self {
56 Self::Id => "id",
57 Self::IdDescending => "-id",
58 Self::Balance => "balance",
59 Self::BalanceDescending => "-balance",
60 Self::TotalTransactions => "total_transactions",
61 Self::TotalTransactionsDescending => "-total_transactions",
62 Self::CreatedTimestamp => "created_timestamp",
63 Self::CreatedTimestampDescending => "-created_timestamp",
64 Self::Owner => "owner",
65 Self::OwnerDescending => "-owner",
66 }
67 }
68}
69
70impl fmt::Display for IcIcrcAccountSort {
71 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
72 formatter.write_str(self.as_api_value())
73 }
74}
75
76#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
83pub enum IcIcrcHolderSort {
84 #[serde(rename = "balance")]
86 Balance,
87 #[serde(rename = "-balance")]
89 BalanceDescending,
90 #[serde(rename = "total_transactions")]
92 TotalTransactions,
93 #[serde(rename = "-total_transactions")]
95 TotalTransactionsDescending,
96 #[serde(rename = "created_timestamp")]
98 CreatedTimestamp,
99 #[serde(rename = "-created_timestamp")]
101 CreatedTimestampDescending,
102 #[serde(rename = "principal")]
104 Principal,
105 #[serde(rename = "-principal")]
107 PrincipalDescending,
108}
109
110impl IcIcrcHolderSort {
111 #[must_use]
113 pub const fn as_api_value(self) -> &'static str {
114 match self {
115 Self::Balance => "balance",
116 Self::BalanceDescending => "-balance",
117 Self::TotalTransactions => "total_transactions",
118 Self::TotalTransactionsDescending => "-total_transactions",
119 Self::CreatedTimestamp => "created_timestamp",
120 Self::CreatedTimestampDescending => "-created_timestamp",
121 Self::Principal => "principal",
122 Self::PrincipalDescending => "-principal",
123 }
124 }
125}
126
127impl fmt::Display for IcIcrcHolderSort {
128 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
129 formatter.write_str(self.as_api_value())
130 }
131}
132
133#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
140pub struct IcIcrcAccountListQuery {
141 pub owner: Option<String>,
143 pub after: Option<String>,
145 pub before: Option<String>,
147 pub limit: u16,
149 pub sort_by: IcIcrcAccountSort,
151}
152
153impl IcIcrcAccountListQuery {
154 #[must_use]
156 pub const fn new(limit: u16, sort_by: IcIcrcAccountSort) -> Self {
157 Self {
158 owner: None,
159 after: None,
160 before: None,
161 limit,
162 sort_by,
163 }
164 }
165
166 #[must_use]
168 pub fn with_owner(mut self, owner: impl Into<String>) -> Self {
169 self.owner = Some(owner.into());
170 self
171 }
172
173 #[must_use]
175 pub fn with_after(mut self, after: impl Into<String>) -> Self {
176 self.after = Some(after.into());
177 self
178 }
179
180 #[must_use]
182 pub fn with_before(mut self, before: impl Into<String>) -> Self {
183 self.before = Some(before.into());
184 self
185 }
186}
187
188#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
195pub struct IcIcrcHolderListQuery {
196 pub after: Option<String>,
198 pub before: Option<String>,
200 pub limit: u16,
202 pub sort_by: IcIcrcHolderSort,
204}
205
206impl IcIcrcHolderListQuery {
207 #[must_use]
209 pub const fn new(limit: u16, sort_by: IcIcrcHolderSort) -> Self {
210 Self {
211 after: None,
212 before: None,
213 limit,
214 sort_by,
215 }
216 }
217
218 #[must_use]
220 pub fn with_after(mut self, after: impl Into<String>) -> Self {
221 self.after = Some(after.into());
222 self
223 }
224
225 #[must_use]
227 pub fn with_before(mut self, before: impl Into<String>) -> Self {
228 self.before = Some(before.into());
229 self
230 }
231}
232
233#[derive(Clone, Debug, Eq, PartialEq)]
240pub struct IcIcrcAccountListRequest {
241 pub analytics: IcIcrcAnalyticsRequest,
243 pub query: IcIcrcAccountListQuery,
245}
246
247impl IcIcrcAccountListRequest {
248 #[must_use]
250 pub fn new(
251 source_endpoint: impl Into<String>,
252 now_unix_secs: u64,
253 ledger_canister_id: impl Into<String>,
254 query: IcIcrcAccountListQuery,
255 ) -> Self {
256 Self {
257 analytics: IcIcrcAnalyticsRequest::new(
258 source_endpoint,
259 now_unix_secs,
260 ledger_canister_id,
261 ),
262 query,
263 }
264 }
265}
266
267#[derive(Clone, Debug, Eq, PartialEq)]
274pub struct IcIcrcAccountInfoRequest {
275 pub analytics: IcIcrcAnalyticsRequest,
277 pub account_id: String,
279}
280
281impl IcIcrcAccountInfoRequest {
282 #[must_use]
284 pub fn new(
285 source_endpoint: impl Into<String>,
286 now_unix_secs: u64,
287 ledger_canister_id: impl Into<String>,
288 account_id: impl Into<String>,
289 ) -> Self {
290 Self {
291 analytics: IcIcrcAnalyticsRequest::new(
292 source_endpoint,
293 now_unix_secs,
294 ledger_canister_id,
295 ),
296 account_id: account_id.into(),
297 }
298 }
299}
300
301#[derive(Clone, Debug, Eq, PartialEq)]
308pub struct IcIcrcHolderListRequest {
309 pub analytics: IcIcrcAnalyticsRequest,
311 pub query: IcIcrcHolderListQuery,
313}
314
315impl IcIcrcHolderListRequest {
316 #[must_use]
318 pub fn new(
319 source_endpoint: impl Into<String>,
320 now_unix_secs: u64,
321 ledger_canister_id: impl Into<String>,
322 query: IcIcrcHolderListQuery,
323 ) -> Self {
324 Self {
325 analytics: IcIcrcAnalyticsRequest::new(
326 source_endpoint,
327 now_unix_secs,
328 ledger_canister_id,
329 ),
330 query,
331 }
332 }
333}