Skip to main content

ic_query/icrc/model/contracts/requests/
ledger_history.rs

1//! Module: icrc::model::contracts::requests::ledger_history
2//!
3//! Responsibility: ICRC ledger-wide transaction and archive request contracts.
4//! Does not own: account-index history, live transport, archive following, or reports.
5//! Boundary: captures bounded ledger history and archive discovery intent.
6
7///
8/// IcrcTransactionsRequest
9///
10/// Request accepted by the generic ICRC transaction history report builder.
11///
12
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct IcrcTransactionsRequest {
15    pub source_endpoint: String,
16    pub now_unix_secs: u64,
17    pub ledger_canister_id: String,
18    pub start: u64,
19    pub limit: u32,
20    pub follow_archives: bool,
21}
22
23impl IcrcTransactionsRequest {
24    #[must_use]
25    pub fn new(
26        source_endpoint: impl Into<String>,
27        now_unix_secs: u64,
28        ledger_canister_id: impl Into<String>,
29        start: u64,
30        limit: u32,
31    ) -> Self {
32        Self {
33            source_endpoint: source_endpoint.into(),
34            now_unix_secs,
35            ledger_canister_id: ledger_canister_id.into(),
36            start,
37            limit,
38            follow_archives: false,
39        }
40    }
41
42    #[must_use]
43    pub const fn with_follow_archives(mut self, follow_archives: bool) -> Self {
44        self.follow_archives = follow_archives;
45        self
46    }
47}
48
49///
50/// IcrcArchivesRequest
51///
52/// Request accepted by the generic ICRC archives report builder.
53///
54
55#[derive(Clone, Debug, Eq, PartialEq)]
56pub struct IcrcArchivesRequest {
57    pub source_endpoint: String,
58    pub now_unix_secs: u64,
59    pub ledger_canister_id: String,
60    pub from_canister_id: Option<String>,
61}
62
63impl IcrcArchivesRequest {
64    #[must_use]
65    pub fn new(
66        source_endpoint: impl Into<String>,
67        now_unix_secs: u64,
68        ledger_canister_id: impl Into<String>,
69    ) -> Self {
70        Self {
71            source_endpoint: source_endpoint.into(),
72            now_unix_secs,
73            ledger_canister_id: ledger_canister_id.into(),
74            from_canister_id: None,
75        }
76    }
77
78    #[must_use]
79    pub fn with_from_canister_id(mut self, from_canister_id: impl Into<String>) -> Self {
80        self.from_canister_id = Some(from_canister_id.into());
81        self
82    }
83}