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 pub lock_stale_after_seconds: u64,
135}
136
137impl IcrcAccountTransactionRefreshRequest {
138 #[must_use]
140 pub const fn new(
141 cache: IcrcAccountTransactionCacheRequest,
142 now_unix_secs: u64,
143 page_size: u32,
144 lock_stale_after_seconds: u64,
145 ) -> Self {
146 Self {
147 cache,
148 now_unix_secs,
149 index_canister_id: None,
150 page_size,
151 max_pages: None,
152 lock_stale_after_seconds,
153 }
154 }
155
156 #[must_use]
158 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
159 self.index_canister_id = Some(index_canister_id.into());
160 self
161 }
162
163 #[must_use]
165 pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
166 self.max_pages = max_pages;
167 self
168 }
169}
170
171#[derive(Clone, Copy, Debug, Eq, PartialEq)]
178pub enum IcrcAccountTransactionSort {
179 Newest,
181 Oldest,
183}
184
185impl IcrcAccountTransactionSort {
186 #[must_use]
188 pub const fn as_str(self) -> &'static str {
189 match self {
190 Self::Newest => "newest",
191 Self::Oldest => "oldest",
192 }
193 }
194}
195
196#[derive(Clone, Debug, Eq, PartialEq)]
203pub struct IcrcAccountTransactionListRequest {
204 pub cache: IcrcAccountTransactionCacheRequest,
206 pub limit: u32,
208 pub sort: IcrcAccountTransactionSort,
210}
211
212impl IcrcAccountTransactionListRequest {
213 #[must_use]
215 pub const fn new(cache: IcrcAccountTransactionCacheRequest, limit: u32) -> Self {
216 Self {
217 cache,
218 limit,
219 sort: IcrcAccountTransactionSort::Newest,
220 }
221 }
222
223 #[must_use]
225 pub const fn with_sort(mut self, sort: IcrcAccountTransactionSort) -> Self {
226 self.sort = sort;
227 self
228 }
229}