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
195#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
202pub struct IcIcrcHolderListQuery {
203 pub after: Option<String>,
205 pub before: Option<String>,
207 pub limit: u16,
209 pub sort_by: IcIcrcHolderSort,
211}
212
213impl IcIcrcHolderListQuery {
214 #[must_use]
216 pub const fn new(limit: u16, sort_by: IcIcrcHolderSort) -> Self {
217 Self {
218 after: None,
219 before: None,
220 limit,
221 sort_by,
222 }
223 }
224}
225
226#[derive(Clone, Debug, Eq, PartialEq)]
233pub struct IcIcrcAccountListRequest {
234 pub analytics: IcIcrcAnalyticsRequest,
236 pub query: IcIcrcAccountListQuery,
238}
239
240impl IcIcrcAccountListRequest {
241 #[must_use]
243 pub fn new(
244 dashboard: IcDashboardRequest,
245 ledger_canister_id: impl Into<String>,
246 query: IcIcrcAccountListQuery,
247 ) -> Self {
248 Self {
249 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
250 query,
251 }
252 }
253}
254
255#[derive(Clone, Debug, Eq, PartialEq)]
262pub struct IcIcrcAccountInfoRequest {
263 pub analytics: IcIcrcAnalyticsRequest,
265 pub account_id: String,
267}
268
269impl IcIcrcAccountInfoRequest {
270 #[must_use]
272 pub fn new(
273 dashboard: IcDashboardRequest,
274 ledger_canister_id: impl Into<String>,
275 account_id: impl Into<String>,
276 ) -> Self {
277 Self {
278 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
279 account_id: account_id.into(),
280 }
281 }
282}
283
284#[derive(Clone, Debug, Eq, PartialEq)]
291pub struct IcIcrcHolderListRequest {
292 pub analytics: IcIcrcAnalyticsRequest,
294 pub query: IcIcrcHolderListQuery,
296}
297
298impl IcIcrcHolderListRequest {
299 #[must_use]
301 pub fn new(
302 dashboard: IcDashboardRequest,
303 ledger_canister_id: impl Into<String>,
304 query: IcIcrcHolderListQuery,
305 ) -> Self {
306 Self {
307 analytics: IcIcrcAnalyticsRequest::new(dashboard, ledger_canister_id),
308 query,
309 }
310 }
311}