Skip to main content

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

1//! Module: icrc::model::contracts::requests::account
2//!
3//! Responsibility: ICRC balance and allowance request contracts.
4//! Does not own: account-history pagination, ledger history, live transport, or reports.
5//! Boundary: keeps structured account and spender selection explicit.
6
7///
8/// IcrcBalanceRequest
9///
10/// Request accepted by the generic ICRC account balance report builder.
11///
12
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct IcrcBalanceRequest {
15    pub source_endpoint: String,
16    pub now_unix_secs: u64,
17    pub ledger_canister_id: String,
18    pub account_owner: String,
19    pub subaccount_hex: Option<String>,
20}
21
22impl IcrcBalanceRequest {
23    #[must_use]
24    pub fn new(
25        source_endpoint: impl Into<String>,
26        now_unix_secs: u64,
27        ledger_canister_id: impl Into<String>,
28        account_owner: impl Into<String>,
29    ) -> Self {
30        Self {
31            source_endpoint: source_endpoint.into(),
32            now_unix_secs,
33            ledger_canister_id: ledger_canister_id.into(),
34            account_owner: account_owner.into(),
35            subaccount_hex: None,
36        }
37    }
38
39    #[must_use]
40    pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
41        self.subaccount_hex = Some(subaccount_hex.into());
42        self
43    }
44}
45
46///
47/// IcrcAllowanceRequest
48///
49/// Request accepted by the generic ICRC allowance report builder.
50///
51
52#[derive(Clone, Debug, Eq, PartialEq)]
53pub struct IcrcAllowanceRequest {
54    pub source_endpoint: String,
55    pub now_unix_secs: u64,
56    pub ledger_canister_id: String,
57    pub account_owner: String,
58    pub account_subaccount_hex: Option<String>,
59    pub spender_owner: String,
60    pub spender_subaccount_hex: Option<String>,
61}
62
63impl IcrcAllowanceRequest {
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        account_owner: impl Into<String>,
70        spender_owner: impl Into<String>,
71    ) -> Self {
72        Self {
73            source_endpoint: source_endpoint.into(),
74            now_unix_secs,
75            ledger_canister_id: ledger_canister_id.into(),
76            account_owner: account_owner.into(),
77            account_subaccount_hex: None,
78            spender_owner: spender_owner.into(),
79            spender_subaccount_hex: None,
80        }
81    }
82
83    #[must_use]
84    pub fn with_account_subaccount_hex(
85        mut self,
86        account_subaccount_hex: impl Into<String>,
87    ) -> Self {
88        self.account_subaccount_hex = Some(account_subaccount_hex.into());
89        self
90    }
91
92    #[must_use]
93    pub fn with_spender_subaccount_hex(
94        mut self,
95        spender_subaccount_hex: impl Into<String>,
96    ) -> Self {
97        self.spender_subaccount_hex = Some(spender_subaccount_hex.into());
98        self
99    }
100}