Skip to main content

ic_query/icrc/model/requests/
account.rs

1//! Module: icrc::model::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
34///
35/// IcrcAllowanceRequest
36///
37/// Request accepted by the generic ICRC allowance report builder.
38///
39
40#[derive(Clone, Debug, Eq, PartialEq)]
41pub struct IcrcAllowanceRequest {
42    /// Shared ledger identity, explicit endpoint and caller collection clock.
43    pub ledger: IcrcLedgerRequest,
44    pub account_owner: String,
45    pub account_subaccount_hex: Option<String>,
46    pub spender_owner: String,
47    pub spender_subaccount_hex: Option<String>,
48}
49
50impl IcrcAllowanceRequest {
51    #[must_use]
52    pub fn new(
53        ledger: IcrcLedgerRequest,
54        account_owner: impl Into<String>,
55        spender_owner: impl Into<String>,
56    ) -> Self {
57        Self {
58            ledger,
59            account_owner: account_owner.into(),
60            account_subaccount_hex: None,
61            spender_owner: spender_owner.into(),
62            spender_subaccount_hex: None,
63        }
64    }
65}