ic_query/icrc/model/contracts/requests/
account_history.rs1use super::IcrcLedgerRequest;
8
9use std::path::PathBuf;
10
11#[derive(Clone, Debug, Eq, PartialEq)]
18pub struct IcrcAccountTransactionPageRequest {
19 pub ledger: IcrcLedgerRequest,
21 pub index_canister_id: Option<String>,
23 pub account_owner: String,
25 pub subaccount_hex: Option<String>,
27 pub start: Option<String>,
29 pub limit: u32,
31}
32
33impl IcrcAccountTransactionPageRequest {
34 #[must_use]
36 pub fn new(ledger: IcrcLedgerRequest, account_owner: impl Into<String>, limit: u32) -> Self {
37 Self {
38 ledger,
39 index_canister_id: None,
40 account_owner: account_owner.into(),
41 subaccount_hex: None,
42 start: None,
43 limit,
44 }
45 }
46
47 #[must_use]
49 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
50 self.index_canister_id = Some(index_canister_id.into());
51 self
52 }
53
54 #[must_use]
56 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
57 self.subaccount_hex = Some(subaccount_hex.into());
58 self
59 }
60
61 #[must_use]
63 pub fn with_start(mut self, start: impl Into<String>) -> Self {
64 self.start = Some(start.into());
65 self
66 }
67}
68
69#[derive(Clone, Debug, Eq, PartialEq)]
76pub struct IcrcAccountTransactionCacheRequest {
77 pub cache_root: PathBuf,
79 pub source_endpoint: String,
81 pub ledger_canister_id: String,
83 pub account_owner: String,
85 pub subaccount_hex: Option<String>,
87}
88
89impl IcrcAccountTransactionCacheRequest {
90 #[must_use]
92 pub fn new(
93 cache_root: impl Into<PathBuf>,
94 source_endpoint: impl Into<String>,
95 ledger_canister_id: impl Into<String>,
96 account_owner: impl Into<String>,
97 ) -> Self {
98 Self {
99 cache_root: cache_root.into(),
100 source_endpoint: source_endpoint.into(),
101 ledger_canister_id: ledger_canister_id.into(),
102 account_owner: account_owner.into(),
103 subaccount_hex: None,
104 }
105 }
106
107 #[must_use]
109 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
110 self.subaccount_hex = Some(subaccount_hex.into());
111 self
112 }
113}
114
115#[derive(Clone, Debug, Eq, PartialEq)]
122pub struct IcrcAccountTransactionRefreshRequest {
123 pub cache: IcrcAccountTransactionCacheRequest,
125 pub now_unix_secs: u64,
127 pub index_canister_id: Option<String>,
129 pub page_size: u32,
131 pub max_pages: Option<u32>,
133}
134
135impl IcrcAccountTransactionRefreshRequest {
136 #[must_use]
138 pub const fn new(
139 cache: IcrcAccountTransactionCacheRequest,
140 now_unix_secs: u64,
141 page_size: u32,
142 ) -> Self {
143 Self {
144 cache,
145 now_unix_secs,
146 index_canister_id: None,
147 page_size,
148 max_pages: None,
149 }
150 }
151
152 #[must_use]
154 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
155 self.index_canister_id = Some(index_canister_id.into());
156 self
157 }
158
159 #[must_use]
161 pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
162 self.max_pages = max_pages;
163 self
164 }
165}
166
167#[derive(Clone, Copy, Debug, Eq, PartialEq)]
174pub enum IcrcAccountTransactionSort {
175 Newest,
177 Oldest,
179}
180
181impl IcrcAccountTransactionSort {
182 #[must_use]
184 pub const fn as_str(self) -> &'static str {
185 match self {
186 Self::Newest => "newest",
187 Self::Oldest => "oldest",
188 }
189 }
190}
191
192#[derive(Clone, Debug, Eq, PartialEq)]
199pub struct IcrcAccountTransactionListRequest {
200 pub cache: IcrcAccountTransactionCacheRequest,
202 pub limit: u32,
204 pub sort: IcrcAccountTransactionSort,
206}
207
208impl IcrcAccountTransactionListRequest {
209 #[must_use]
211 pub const fn new(cache: IcrcAccountTransactionCacheRequest, limit: u32) -> Self {
212 Self {
213 cache,
214 limit,
215 sort: IcrcAccountTransactionSort::Newest,
216 }
217 }
218
219 #[must_use]
221 pub const fn with_sort(mut self, sort: IcrcAccountTransactionSort) -> Self {
222 self.sort = sort;
223 self
224 }
225}