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
7use super::IcrcLedgerRequest;
8
9///
10/// IcrcBalanceRequest
11///
12/// Request accepted by the generic ICRC account balance report builder.
13///
14
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct IcrcBalanceRequest {
17    /// Shared ledger identity, explicit endpoint and caller collection clock.
18    pub ledger: IcrcLedgerRequest,
19    pub account_owner: String,
20    pub subaccount_hex: Option<String>,
21}
22
23impl IcrcBalanceRequest {
24    #[must_use]
25    pub fn new(ledger: IcrcLedgerRequest, account_owner: impl Into<String>) -> Self {
26        Self {
27            ledger,
28            account_owner: account_owner.into(),
29            subaccount_hex: None,
30        }
31    }
32
33    #[must_use]
34    pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
35        self.subaccount_hex = Some(subaccount_hex.into());
36        self
37    }
38}
39
40///
41/// IcrcAllowanceRequest
42///
43/// Request accepted by the generic ICRC allowance report builder.
44///
45
46#[derive(Clone, Debug, Eq, PartialEq)]
47pub struct IcrcAllowanceRequest {
48    /// Shared ledger identity, explicit endpoint and caller collection clock.
49    pub ledger: IcrcLedgerRequest,
50    pub account_owner: String,
51    pub account_subaccount_hex: Option<String>,
52    pub spender_owner: String,
53    pub spender_subaccount_hex: Option<String>,
54}
55
56impl IcrcAllowanceRequest {
57    #[must_use]
58    pub fn new(
59        ledger: IcrcLedgerRequest,
60        account_owner: impl Into<String>,
61        spender_owner: impl Into<String>,
62    ) -> Self {
63        Self {
64            ledger,
65            account_owner: account_owner.into(),
66            account_subaccount_hex: None,
67            spender_owner: spender_owner.into(),
68            spender_subaccount_hex: None,
69        }
70    }
71
72    #[must_use]
73    pub fn with_account_subaccount_hex(
74        mut self,
75        account_subaccount_hex: impl Into<String>,
76    ) -> Self {
77        self.account_subaccount_hex = Some(account_subaccount_hex.into());
78        self
79    }
80
81    #[must_use]
82    pub fn with_spender_subaccount_hex(
83        mut self,
84        spender_subaccount_hex: impl Into<String>,
85    ) -> Self {
86        self.spender_subaccount_hex = Some(spender_subaccount_hex.into());
87        self
88    }
89}