1use serde::{Deserialize as SerdeDeserialize, Serialize};
8use serde_json::Value as JsonValue;
9use std::path::PathBuf;
10
11#[derive(Clone, Debug, Eq, PartialEq)]
18pub struct IcrcLedgerRequest {
19 pub source_endpoint: String,
20 pub now_unix_secs: u64,
21 pub ledger_canister_id: String,
22}
23
24impl IcrcLedgerRequest {
25 #[must_use]
26 pub fn new(
27 source_endpoint: impl Into<String>,
28 now_unix_secs: u64,
29 ledger_canister_id: impl Into<String>,
30 ) -> Self {
31 Self {
32 source_endpoint: source_endpoint.into(),
33 now_unix_secs,
34 ledger_canister_id: ledger_canister_id.into(),
35 }
36 }
37}
38
39#[derive(Clone, Debug, Eq, PartialEq)]
46pub struct IcrcBalanceRequest {
47 pub source_endpoint: String,
48 pub now_unix_secs: u64,
49 pub ledger_canister_id: String,
50 pub account_owner: String,
51 pub subaccount_hex: Option<String>,
52}
53
54impl IcrcBalanceRequest {
55 #[must_use]
56 pub fn new(
57 source_endpoint: impl Into<String>,
58 now_unix_secs: u64,
59 ledger_canister_id: impl Into<String>,
60 account_owner: impl Into<String>,
61 ) -> Self {
62 Self {
63 source_endpoint: source_endpoint.into(),
64 now_unix_secs,
65 ledger_canister_id: ledger_canister_id.into(),
66 account_owner: account_owner.into(),
67 subaccount_hex: None,
68 }
69 }
70
71 #[must_use]
72 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
73 self.subaccount_hex = Some(subaccount_hex.into());
74 self
75 }
76}
77
78#[derive(Clone, Debug, Eq, PartialEq)]
85pub struct IcrcAllowanceRequest {
86 pub source_endpoint: String,
87 pub now_unix_secs: u64,
88 pub ledger_canister_id: String,
89 pub account_owner: String,
90 pub account_subaccount_hex: Option<String>,
91 pub spender_owner: String,
92 pub spender_subaccount_hex: Option<String>,
93}
94
95impl IcrcAllowanceRequest {
96 #[must_use]
97 pub fn new(
98 source_endpoint: impl Into<String>,
99 now_unix_secs: u64,
100 ledger_canister_id: impl Into<String>,
101 account_owner: impl Into<String>,
102 spender_owner: impl Into<String>,
103 ) -> Self {
104 Self {
105 source_endpoint: source_endpoint.into(),
106 now_unix_secs,
107 ledger_canister_id: ledger_canister_id.into(),
108 account_owner: account_owner.into(),
109 account_subaccount_hex: None,
110 spender_owner: spender_owner.into(),
111 spender_subaccount_hex: None,
112 }
113 }
114
115 #[must_use]
116 pub fn with_account_subaccount_hex(
117 mut self,
118 account_subaccount_hex: impl Into<String>,
119 ) -> Self {
120 self.account_subaccount_hex = Some(account_subaccount_hex.into());
121 self
122 }
123
124 #[must_use]
125 pub fn with_spender_subaccount_hex(
126 mut self,
127 spender_subaccount_hex: impl Into<String>,
128 ) -> Self {
129 self.spender_subaccount_hex = Some(spender_subaccount_hex.into());
130 self
131 }
132}
133
134#[derive(Clone, Debug, Eq, PartialEq)]
141pub struct IcrcAccountTransactionPageRequest {
142 pub source_endpoint: String,
144 pub now_unix_secs: u64,
146 pub ledger_canister_id: String,
148 pub index_canister_id: Option<String>,
150 pub account_owner: String,
152 pub subaccount_hex: Option<String>,
154 pub start: Option<String>,
156 pub limit: u32,
158}
159
160impl IcrcAccountTransactionPageRequest {
161 #[must_use]
163 pub fn new(
164 source_endpoint: impl Into<String>,
165 now_unix_secs: u64,
166 ledger_canister_id: impl Into<String>,
167 account_owner: impl Into<String>,
168 limit: u32,
169 ) -> Self {
170 Self {
171 source_endpoint: source_endpoint.into(),
172 now_unix_secs,
173 ledger_canister_id: ledger_canister_id.into(),
174 index_canister_id: None,
175 account_owner: account_owner.into(),
176 subaccount_hex: None,
177 start: None,
178 limit,
179 }
180 }
181
182 #[must_use]
184 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
185 self.index_canister_id = Some(index_canister_id.into());
186 self
187 }
188
189 #[must_use]
191 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
192 self.subaccount_hex = Some(subaccount_hex.into());
193 self
194 }
195
196 #[must_use]
198 pub fn with_start(mut self, start: impl Into<String>) -> Self {
199 self.start = Some(start.into());
200 self
201 }
202}
203
204#[derive(Clone, Debug, Eq, PartialEq)]
211pub struct IcrcAccountTransactionCacheRequest {
212 pub cache_root: PathBuf,
214 pub source_endpoint: String,
216 pub ledger_canister_id: String,
218 pub account_owner: String,
220 pub subaccount_hex: Option<String>,
222}
223
224impl IcrcAccountTransactionCacheRequest {
225 #[must_use]
227 pub fn new(
228 cache_root: impl Into<PathBuf>,
229 source_endpoint: impl Into<String>,
230 ledger_canister_id: impl Into<String>,
231 account_owner: impl Into<String>,
232 ) -> Self {
233 Self {
234 cache_root: cache_root.into(),
235 source_endpoint: source_endpoint.into(),
236 ledger_canister_id: ledger_canister_id.into(),
237 account_owner: account_owner.into(),
238 subaccount_hex: None,
239 }
240 }
241
242 #[must_use]
244 pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
245 self.subaccount_hex = Some(subaccount_hex.into());
246 self
247 }
248}
249
250#[derive(Clone, Debug, Eq, PartialEq)]
257pub struct IcrcAccountTransactionRefreshRequest {
258 pub cache: IcrcAccountTransactionCacheRequest,
260 pub now_unix_secs: u64,
262 pub index_canister_id: Option<String>,
264 pub page_size: u32,
266 pub max_pages: Option<u32>,
268 pub lock_stale_after_seconds: u64,
270}
271
272impl IcrcAccountTransactionRefreshRequest {
273 #[must_use]
275 pub const fn new(
276 cache: IcrcAccountTransactionCacheRequest,
277 now_unix_secs: u64,
278 page_size: u32,
279 lock_stale_after_seconds: u64,
280 ) -> Self {
281 Self {
282 cache,
283 now_unix_secs,
284 index_canister_id: None,
285 page_size,
286 max_pages: None,
287 lock_stale_after_seconds,
288 }
289 }
290
291 #[must_use]
293 pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
294 self.index_canister_id = Some(index_canister_id.into());
295 self
296 }
297
298 #[must_use]
300 pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
301 self.max_pages = max_pages;
302 self
303 }
304}
305
306#[derive(Clone, Copy, Debug, Eq, PartialEq)]
313pub enum IcrcAccountTransactionSort {
314 Newest,
316 Oldest,
318}
319
320impl IcrcAccountTransactionSort {
321 #[must_use]
323 pub const fn as_str(self) -> &'static str {
324 match self {
325 Self::Newest => "newest",
326 Self::Oldest => "oldest",
327 }
328 }
329}
330
331#[derive(Clone, Debug, Eq, PartialEq)]
338pub struct IcrcAccountTransactionListRequest {
339 pub cache: IcrcAccountTransactionCacheRequest,
341 pub limit: u32,
343 pub sort: IcrcAccountTransactionSort,
345}
346
347impl IcrcAccountTransactionListRequest {
348 #[must_use]
350 pub const fn new(cache: IcrcAccountTransactionCacheRequest, limit: u32) -> Self {
351 Self {
352 cache,
353 limit,
354 sort: IcrcAccountTransactionSort::Newest,
355 }
356 }
357
358 #[must_use]
360 pub const fn with_sort(mut self, sort: IcrcAccountTransactionSort) -> Self {
361 self.sort = sort;
362 self
363 }
364}
365
366#[derive(Clone, Debug, Eq, PartialEq)]
373pub struct IcrcTransactionsRequest {
374 pub source_endpoint: String,
375 pub now_unix_secs: u64,
376 pub ledger_canister_id: String,
377 pub start: u64,
378 pub limit: u32,
379 pub follow_archives: bool,
380}
381
382impl IcrcTransactionsRequest {
383 #[must_use]
384 pub fn new(
385 source_endpoint: impl Into<String>,
386 now_unix_secs: u64,
387 ledger_canister_id: impl Into<String>,
388 start: u64,
389 limit: u32,
390 ) -> Self {
391 Self {
392 source_endpoint: source_endpoint.into(),
393 now_unix_secs,
394 ledger_canister_id: ledger_canister_id.into(),
395 start,
396 limit,
397 follow_archives: false,
398 }
399 }
400
401 #[must_use]
402 pub const fn with_follow_archives(mut self, follow_archives: bool) -> Self {
403 self.follow_archives = follow_archives;
404 self
405 }
406}
407
408#[derive(Clone, Debug, Eq, PartialEq)]
415pub struct IcrcArchivesRequest {
416 pub source_endpoint: String,
417 pub now_unix_secs: u64,
418 pub ledger_canister_id: String,
419 pub from_canister_id: Option<String>,
420}
421
422impl IcrcArchivesRequest {
423 #[must_use]
424 pub fn new(
425 source_endpoint: impl Into<String>,
426 now_unix_secs: u64,
427 ledger_canister_id: impl Into<String>,
428 ) -> Self {
429 Self {
430 source_endpoint: source_endpoint.into(),
431 now_unix_secs,
432 ledger_canister_id: ledger_canister_id.into(),
433 from_canister_id: None,
434 }
435 }
436
437 #[must_use]
438 pub fn with_from_canister_id(mut self, from_canister_id: impl Into<String>) -> Self {
439 self.from_canister_id = Some(from_canister_id.into());
440 self
441 }
442}
443
444#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
451pub struct IcrcTokenReport {
452 pub schema_version: u32,
453 pub ledger_canister_id: String,
454 pub fetched_at: String,
455 pub source_endpoint: String,
456 pub fetched_by: String,
457 pub token_name: String,
458 pub token_symbol: String,
459 pub decimals: u8,
460 pub transfer_fee: String,
461 pub total_supply: String,
462 pub minting_account_owner: Option<String>,
463 pub minting_account_subaccount_hex: Option<String>,
464 pub supported_standards: Vec<IcrcTokenStandardRow>,
465 pub metadata: Vec<IcrcTokenMetadataRow>,
466}
467
468#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
475pub struct IcrcBalanceReport {
476 pub schema_version: u32,
477 pub ledger_canister_id: String,
478 pub account_owner: String,
479 pub subaccount_hex: Option<String>,
480 pub fetched_at: String,
481 pub source_endpoint: String,
482 pub fetched_by: String,
483 pub token_symbol: String,
484 pub decimals: u8,
485 pub balance: String,
486}
487
488#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
495pub struct IcrcAllowanceReport {
496 pub schema_version: u32,
497 pub ledger_canister_id: String,
498 pub account_owner: String,
499 pub account_subaccount_hex: Option<String>,
500 pub spender_owner: String,
501 pub spender_subaccount_hex: Option<String>,
502 pub fetched_at: String,
503 pub source_endpoint: String,
504 pub fetched_by: String,
505 pub token_symbol: String,
506 pub decimals: u8,
507 pub allowance: String,
508 pub expires_at_unix_nanos: Option<String>,
509}
510
511#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
518pub struct IcrcAccountTransactionPageReport {
519 pub schema_version: u32,
521 pub ledger_canister_id: String,
523 pub index_canister_id: String,
525 pub account_owner: String,
527 pub subaccount_hex: Option<String>,
529 pub requested_start: Option<String>,
531 pub requested_limit: u32,
533 pub next_start: Option<String>,
535 pub oldest_transaction_id: Option<String>,
537 pub balance: String,
539 pub token_symbol: String,
541 pub decimals: u8,
543 pub fetched_at: String,
545 pub source_endpoint: String,
547 pub fetched_by: String,
549 pub transactions: Vec<IcrcAccountTransactionRow>,
551}
552
553#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
560pub struct IcrcAccountTransactionCompleteness {
561 pub status: String,
563 pub page_size: u32,
565 pub page_count: u32,
567 pub row_count: usize,
569 pub point_in_time_guaranteed: bool,
571}
572
573#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
580pub struct IcrcAccountTransactionSnapshot {
581 pub schema_version: u32,
583 pub source_endpoint: String,
585 pub collection_started_at: String,
587 pub collection_completed_at: String,
589 pub fetched_by: String,
591 pub ledger_canister_id: String,
593 pub index_canister_id: String,
595 pub account_owner: String,
597 pub subaccount_hex: Option<String>,
599 pub balance: String,
601 pub token_symbol: String,
603 pub decimals: u8,
605 pub newest_transaction_id: Option<String>,
607 pub oldest_transaction_id: Option<String>,
609 pub completeness: IcrcAccountTransactionCompleteness,
611 pub transactions: Vec<IcrcAccountTransactionRow>,
613}
614
615#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
622pub struct IcrcAccountTransactionRefreshReport {
623 pub schema_version: u32,
625 pub ledger_canister_id: String,
627 pub index_canister_id: String,
629 pub account_owner: String,
631 pub subaccount_hex: Option<String>,
633 pub transaction_count: usize,
635 pub newest_transaction_id: Option<String>,
637 pub oldest_transaction_id: Option<String>,
639 pub page_size: u32,
641 pub page_count: u32,
643 pub point_in_time_guaranteed: bool,
645 pub replaced_existing_cache: bool,
647 pub attempt_finalization_error: Option<String>,
649 pub collection_started_at: String,
651 pub collection_completed_at: String,
653 pub source_endpoint: String,
655 pub fetched_by: String,
657 pub cache_path: String,
659 pub refresh_attempt_path: String,
661 pub refresh_lock_path: String,
663}
664
665#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
672pub struct IcrcAccountTransactionListReport {
673 pub schema_version: u32,
675 pub ledger_canister_id: String,
677 pub index_canister_id: String,
679 pub account_owner: String,
681 pub subaccount_hex: Option<String>,
683 pub requested_limit: u32,
685 pub sort: String,
687 pub total_transaction_count: usize,
689 pub returned_transaction_count: usize,
691 pub newest_transaction_id: Option<String>,
693 pub oldest_transaction_id: Option<String>,
695 pub balance: String,
697 pub token_symbol: String,
699 pub decimals: u8,
701 pub collection_started_at: String,
703 pub collection_completed_at: String,
705 pub source_endpoint: String,
707 pub fetched_by: String,
709 pub complete: bool,
711 pub point_in_time_guaranteed: bool,
713 pub page_size: u32,
715 pub page_count: u32,
717 pub cache_path: String,
719 pub transactions: Vec<IcrcAccountTransactionRow>,
721}
722
723#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
730pub struct IcrcAccountTransactionCacheStatusReport {
731 pub schema_version: u32,
733 pub ledger_canister_id: String,
735 pub account_owner: String,
737 pub subaccount_hex: Option<String>,
739 pub source_endpoint: String,
741 pub found: bool,
743 pub cache: Option<IcrcAccountTransactionCacheSummary>,
745 pub expected_cache_path: String,
747 pub refresh_attempt_path: String,
749 pub refresh_lock_path: String,
751 pub latest_attempt: Option<IcrcAccountTransactionRefreshAttemptStatus>,
753}
754
755#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
762pub struct IcrcAccountTransactionCacheSummary {
763 pub cache_status: String,
765 pub cache_error: Option<String>,
767 pub index_canister_id: Option<String>,
769 pub transaction_count: usize,
771 pub newest_transaction_id: Option<String>,
773 pub oldest_transaction_id: Option<String>,
775 pub page_size: u32,
777 pub page_count: u32,
779 pub complete: bool,
781 pub point_in_time_guaranteed: bool,
783 pub collection_started_at: String,
785 pub collection_completed_at: String,
787 pub cache_path: String,
789}
790
791#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
798pub struct IcrcAccountTransactionRefreshAttemptStatus {
799 pub status: String,
801 pub started_at: String,
803 pub updated_at: String,
805 pub index_canister_id: Option<String>,
807 pub page_size: u32,
809 pub pages_fetched: u32,
811 pub rows_fetched: usize,
813 pub last_cursor: Option<String>,
815 pub last_error: Option<String>,
817}
818
819#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
826pub struct IcrcIndexReport {
827 pub schema_version: u32,
828 pub ledger_canister_id: String,
829 pub fetched_at: String,
830 pub source_endpoint: String,
831 pub fetched_by: String,
832 pub index_canister_id: Option<String>,
833 pub index_error: Option<String>,
834}
835
836#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
843pub struct IcrcTransactionsReport {
844 pub schema_version: u32,
845 pub ledger_canister_id: String,
846 pub fetched_at: String,
847 pub source_endpoint: String,
848 pub fetched_by: String,
849 pub requested_start: String,
850 pub requested_limit: u32,
851 pub follow_archives: bool,
852 pub log_length: Option<String>,
853 pub blocks: Vec<IcrcTransactionBlockRow>,
854 pub archived_blocks: Vec<IcrcArchivedBlocksRow>,
855 pub followed_archive_blocks: Vec<IcrcFollowedArchiveBlockRow>,
856 pub archive_follow_errors: Vec<IcrcArchiveFollowErrorRow>,
857}
858
859#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
866pub struct IcrcBlockTypesReport {
867 pub schema_version: u32,
868 pub ledger_canister_id: String,
869 pub fetched_at: String,
870 pub source_endpoint: String,
871 pub fetched_by: String,
872 pub block_types: Vec<IcrcBlockTypeRow>,
873}
874
875#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
882pub struct IcrcArchivesReport {
883 pub schema_version: u32,
884 pub ledger_canister_id: String,
885 pub from_canister_id: Option<String>,
886 pub fetched_at: String,
887 pub source_endpoint: String,
888 pub fetched_by: String,
889 pub archives: Vec<IcrcArchiveRow>,
890}
891
892#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
899pub struct IcrcTipCertificateReport {
900 pub schema_version: u32,
901 pub ledger_canister_id: String,
902 pub fetched_at: String,
903 pub source_endpoint: String,
904 pub fetched_by: String,
905 pub certificate_present: bool,
906 pub certificate_hex: Option<String>,
907 pub certificate_bytes: Option<usize>,
908 pub hash_tree_hex: Option<String>,
909 pub hash_tree_bytes: Option<usize>,
910}
911
912#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
919pub struct IcrcCapabilitiesReport {
920 pub schema_version: u32,
921 pub ledger_canister_id: String,
922 pub fetched_at: String,
923 pub source_endpoint: String,
924 pub fetched_by: String,
925 pub supported_standards: Vec<IcrcTokenStandardRow>,
926 pub capabilities: Vec<IcrcCapabilityRow>,
927}
928
929#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
936pub struct IcrcCapabilityRow {
937 pub capability: String,
938 pub method: String,
939 pub status: String,
940 pub details: Option<String>,
941 pub error: Option<String>,
942}
943
944#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
951pub struct IcrcTokenStandardRow {
952 pub name: String,
953 pub url: String,
954}
955
956#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
963pub struct IcrcTokenMetadataRow {
964 pub key: String,
965 pub value_type: String,
966 pub value: JsonValue,
967}
968
969#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
976pub struct IcrcAccountRow {
977 pub owner: Option<String>,
979 pub subaccount_hex: Option<String>,
981 pub account_identifier: Option<String>,
983}
984
985#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
992pub struct IcrcAccountTransactionRow {
993 pub id: String,
995 pub kind: String,
997 pub timestamp_unix_nanos: Option<String>,
999 pub amount_base_units: Option<String>,
1001 pub fee_base_units: Option<String>,
1003 pub from: Option<IcrcAccountRow>,
1005 pub to: Option<IcrcAccountRow>,
1007 pub spender: Option<IcrcAccountRow>,
1009 pub memo_hex: Option<String>,
1011 pub created_at_time_unix_nanos: Option<String>,
1013 pub expires_at_unix_nanos: Option<String>,
1015 pub expected_allowance_base_units: Option<String>,
1017 pub raw_transaction: JsonValue,
1019}
1020
1021#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1028pub struct IcrcTransactionBlockRow {
1029 pub index: String,
1030 pub block_type: Option<String>,
1031 pub transaction_kind: Option<String>,
1032 pub timestamp_unix_nanos: Option<String>,
1033 pub amount_base_units: Option<String>,
1034 pub raw_block: JsonValue,
1035}
1036
1037#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1044pub struct IcrcArchivedBlocksRow {
1045 pub callback_canister_id: String,
1046 pub callback_method: String,
1047 pub ranges: Vec<IcrcArchivedRangeRow>,
1048}
1049
1050#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1057pub struct IcrcArchivedRangeRow {
1058 pub start: String,
1059 pub length: String,
1060}
1061
1062#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1069pub struct IcrcFollowedArchiveBlockRow {
1070 pub archive_canister_id: String,
1071 pub callback_method: String,
1072 pub index: String,
1073 pub block_type: Option<String>,
1074 pub transaction_kind: Option<String>,
1075 pub timestamp_unix_nanos: Option<String>,
1076 pub amount_base_units: Option<String>,
1077 pub raw_block: JsonValue,
1078}
1079
1080#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1087pub struct IcrcArchiveFollowErrorRow {
1088 pub callback_canister_id: String,
1089 pub callback_method: String,
1090 pub ranges: Vec<IcrcArchivedRangeRow>,
1091 pub error: String,
1092}
1093
1094#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1101pub struct IcrcBlockTypeRow {
1102 pub block_type: String,
1103 pub url: String,
1104}
1105
1106#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
1113pub struct IcrcArchiveRow {
1114 pub canister_id: String,
1115 pub start: String,
1116 pub end: String,
1117}