ic_query/icrc/model/contracts/requests/
account_history.rs1use std::path::PathBuf;
8
9#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct IcrcAccountTransactionPageRequest {
17 pub source_endpoint: String,
19 pub now_unix_secs: u64,
21 pub ledger_canister_id: String,
23 pub index_canister_id: Option<String>,
25 pub account_owner: String,
27 pub subaccount_hex: Option<String>,
29 pub start: Option<String>,
31 pub limit: u32,
33}
34
35impl IcrcAccountTransactionPageRequest {
36 #[must_use]
38 pub fn new(
39 source_endpoint: impl Into<String>,
40 now_unix_secs: u64,
41 ledger_canister_id: impl Into<String>,
42 account_owner: impl Into<String>,
43 limit: u32,
44 ) -> Self {
45 Self {
46 source_endpoint: source_endpoint.into(),
47 now_unix_secs,
48 ledger_canister_id: ledger_canister_id.into(),
49 index_canister_id: None,
50 account_owner: account_owner.into(),
51 subaccount_hex: None,
52 start: None,
53 limit,
54 }
55 }
56
57 #[must_use]
59 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
60 self.index_canister_id = Some(index_canister_id.into());
61 self
62 }
63
64 #[must_use]
66 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
67 self.subaccount_hex = Some(subaccount_hex.into());
68 self
69 }
70
71 #[must_use]
73 pub fn with_start(mut self, start: impl Into<String>) -> Self {
74 self.start = Some(start.into());
75 self
76 }
77}
78
79#[derive(Clone, Debug, Eq, PartialEq)]
86pub struct IcrcAccountTransactionCacheRequest {
87 pub cache_root: PathBuf,
89 pub source_endpoint: String,
91 pub ledger_canister_id: String,
93 pub account_owner: String,
95 pub subaccount_hex: Option<String>,
97}
98
99impl IcrcAccountTransactionCacheRequest {
100 #[must_use]
102 pub fn new(
103 cache_root: impl Into<PathBuf>,
104 source_endpoint: impl Into<String>,
105 ledger_canister_id: impl Into<String>,
106 account_owner: impl Into<String>,
107 ) -> Self {
108 Self {
109 cache_root: cache_root.into(),
110 source_endpoint: source_endpoint.into(),
111 ledger_canister_id: ledger_canister_id.into(),
112 account_owner: account_owner.into(),
113 subaccount_hex: None,
114 }
115 }
116
117 #[must_use]
119 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
120 self.subaccount_hex = Some(subaccount_hex.into());
121 self
122 }
123}
124
125#[derive(Clone, Debug, Eq, PartialEq)]
132pub struct IcrcAccountTransactionRefreshRequest {
133 pub cache: IcrcAccountTransactionCacheRequest,
135 pub now_unix_secs: u64,
137 pub index_canister_id: Option<String>,
139 pub page_size: u32,
141 pub max_pages: Option<u32>,
143 pub lock_stale_after_seconds: u64,
145}
146
147impl IcrcAccountTransactionRefreshRequest {
148 #[must_use]
150 pub const fn new(
151 cache: IcrcAccountTransactionCacheRequest,
152 now_unix_secs: u64,
153 page_size: u32,
154 lock_stale_after_seconds: u64,
155 ) -> Self {
156 Self {
157 cache,
158 now_unix_secs,
159 index_canister_id: None,
160 page_size,
161 max_pages: None,
162 lock_stale_after_seconds,
163 }
164 }
165
166 #[must_use]
168 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
169 self.index_canister_id = Some(index_canister_id.into());
170 self
171 }
172
173 #[must_use]
175 pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
176 self.max_pages = max_pages;
177 self
178 }
179}
180
181#[derive(Clone, Copy, Debug, Eq, PartialEq)]
188pub enum IcrcAccountTransactionSort {
189 Newest,
191 Oldest,
193}
194
195impl IcrcAccountTransactionSort {
196 #[must_use]
198 pub const fn as_str(self) -> &'static str {
199 match self {
200 Self::Newest => "newest",
201 Self::Oldest => "oldest",
202 }
203 }
204}
205
206#[derive(Clone, Debug, Eq, PartialEq)]
213pub struct IcrcAccountTransactionListRequest {
214 pub cache: IcrcAccountTransactionCacheRequest,
216 pub limit: u32,
218 pub sort: IcrcAccountTransactionSort,
220}
221
222impl IcrcAccountTransactionListRequest {
223 #[must_use]
225 pub const fn new(cache: IcrcAccountTransactionCacheRequest, limit: u32) -> Self {
226 Self {
227 cache,
228 limit,
229 sort: IcrcAccountTransactionSort::Newest,
230 }
231 }
232
233 #[must_use]
235 pub const fn with_sort(mut self, sort: IcrcAccountTransactionSort) -> Self {
236 self.sort = sort;
237 self
238 }
239}