Skip to main content

xrpl_common_stdlib/objects/generated/
mptoken.rs

1// GENERATED -- do not hand-edit. Run scripts/generate-ledger-objects.sh to regenerate.
2
3use crate::host::Result;
4use crate::objects::traits::CurrentLedgerObjectCommonFields;
5use crate::objects::traits::LedgerObjectCommonFields;
6use crate::objects::{current_ledger_object, ledger_object};
7use crate::sfield;
8use crate::types::account_id::AccountID;
9use crate::types::blob::StandardBlob;
10use crate::types::uint::{Hash192, Hash256};
11
12/// Trait providing access to fields specific to MPToken objects in any ledger.
13pub trait MPTokenFields: LedgerObjectCommonFields {
14    /// The owner (holder) of these MPTs.
15    fn account(&self) -> Result<AccountID> {
16        ledger_object::get_field(self.get_slot_num(), sfield::Account)
17    }
18
19    /// The `MPTokenIssuance` identifier.
20    fn mptoken_issuance_id(&self) -> Result<Hash192> {
21        ledger_object::get_field(self.get_slot_num(), sfield::MPTokenIssuanceID)
22    }
23
24    /// The amount of tokens currently held by the owner. The minimum is 0 and the maximum is
25    /// 2^63-1.
26    fn mpt_amount(&self) -> Result<Option<u64>> {
27        ledger_object::get_field_optional(self.get_slot_num(), sfield::MPTAmount)
28    }
29
30    /// The amount of tokens currently locked up (for example, in escrow).
31    fn locked_amount(&self) -> Result<Option<u64>> {
32        ledger_object::get_field_optional(self.get_slot_num(), sfield::LockedAmount)
33    }
34
35    /// A hint indicating which page of the owner directory links to this entry, in case the
36    /// directory consists of multiple pages.
37    fn owner_node(&self) -> Result<u64> {
38        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
39    }
40
41    /// The identifying hash of the transaction that most recently modified this entry.
42    fn previous_txn_id(&self) -> Result<Hash256> {
43        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
44    }
45
46    /// The sequence of the ledger that contains the transaction that most recently modified this
47    /// object.
48    fn previous_txn_lgr_seq(&self) -> Result<u32> {
49        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
50    }
51
52    /// Encrypted inbox balance that receives incoming confidential transfers. Before it can be
53    /// spent, the holder must merge it into their spending balance using the
54    /// ConfidentialMPTMergeInbox transaction. Present when the holder has a confidential balance.
55    fn confidential_balance_inbox(&self) -> Result<Option<StandardBlob>> {
56        ledger_object::get_field_optional(self.get_slot_num(), sfield::ConfidentialBalanceInbox)
57    }
58
59    /// Encrypted spending balance used to generate proofs for outgoing transactions. Present when
60    /// the holder has a confidential balance.
61    fn confidential_balance_spending(&self) -> Result<Option<StandardBlob>> {
62        ledger_object::get_field_optional(self.get_slot_num(), sfield::ConfidentialBalanceSpending)
63    }
64
65    /// Version number that increments each time the spending balance changes. This version is
66    /// cryptographically bound to ZKPs in outgoing transactions to prevent replay attacks and
67    /// ensure proof validity. If the version changes between proof generation and submission, the
68    /// transaction will fail.
69    fn confidential_balance_version(&self) -> Result<Option<u32>> {
70        ledger_object::get_field_optional(self.get_slot_num(), sfield::ConfidentialBalanceVersion)
71    }
72
73    /// Copy of the holder's total confidential balance encrypted for the issuer to audit supply.
74    /// Present when the holder has a confidential balance.
75    fn issuer_encrypted_balance(&self) -> Result<Option<StandardBlob>> {
76        ledger_object::get_field_optional(self.get_slot_num(), sfield::IssuerEncryptedBalance)
77    }
78
79    /// The holder's total confidential balance encrypted under the auditor's key for independent
80    /// auditing. Only present if an auditor is configured.
81    fn auditor_encrypted_balance(&self) -> Result<Option<StandardBlob>> {
82        ledger_object::get_field_optional(self.get_slot_num(), sfield::AuditorEncryptedBalance)
83    }
84
85    /// The IssuerKeyMirrorEpoch field (Optional).
86    fn issuer_key_mirror_epoch(&self) -> Result<Option<u32>> {
87        ledger_object::get_field_optional(self.get_slot_num(), sfield::IssuerKeyMirrorEpoch)
88    }
89
90    /// The AuditorKeyMirrorEpoch field (Optional).
91    fn auditor_key_mirror_epoch(&self) -> Result<Option<u32>> {
92        ledger_object::get_field_optional(self.get_slot_num(), sfield::AuditorKeyMirrorEpoch)
93    }
94
95    /// The holder's ElGamal public key for confidential balances. Present when the holder has a
96    /// confidential balance.
97    fn holder_encryption_key(&self) -> Result<Option<StandardBlob>> {
98        ledger_object::get_field_optional(self.get_slot_num(), sfield::HolderEncryptionKey)
99    }
100}
101
102/// Trait providing access to fields specific to the current MPToken object.
103pub trait CurrentMPTokenFields: CurrentLedgerObjectCommonFields {
104    /// The owner (holder) of these MPTs.
105    fn account(&self) -> Result<AccountID> {
106        current_ledger_object::get_field(sfield::Account)
107    }
108
109    /// The `MPTokenIssuance` identifier.
110    fn mptoken_issuance_id(&self) -> Result<Hash192> {
111        current_ledger_object::get_field(sfield::MPTokenIssuanceID)
112    }
113
114    /// The amount of tokens currently held by the owner. The minimum is 0 and the maximum is
115    /// 2^63-1.
116    fn mpt_amount(&self) -> Result<Option<u64>> {
117        current_ledger_object::get_field_optional(sfield::MPTAmount)
118    }
119
120    /// The amount of tokens currently locked up (for example, in escrow).
121    fn locked_amount(&self) -> Result<Option<u64>> {
122        current_ledger_object::get_field_optional(sfield::LockedAmount)
123    }
124
125    /// A hint indicating which page of the owner directory links to this entry, in case the
126    /// directory consists of multiple pages.
127    fn owner_node(&self) -> Result<u64> {
128        current_ledger_object::get_field(sfield::OwnerNode)
129    }
130
131    /// The identifying hash of the transaction that most recently modified this entry.
132    fn previous_txn_id(&self) -> Result<Hash256> {
133        current_ledger_object::get_field(sfield::PreviousTxnID)
134    }
135
136    /// The sequence of the ledger that contains the transaction that most recently modified this
137    /// object.
138    fn previous_txn_lgr_seq(&self) -> Result<u32> {
139        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
140    }
141
142    /// Encrypted inbox balance that receives incoming confidential transfers. Before it can be
143    /// spent, the holder must merge it into their spending balance using the
144    /// ConfidentialMPTMergeInbox transaction. Present when the holder has a confidential balance.
145    fn confidential_balance_inbox(&self) -> Result<Option<StandardBlob>> {
146        current_ledger_object::get_field_optional(sfield::ConfidentialBalanceInbox)
147    }
148
149    /// Encrypted spending balance used to generate proofs for outgoing transactions. Present when
150    /// the holder has a confidential balance.
151    fn confidential_balance_spending(&self) -> Result<Option<StandardBlob>> {
152        current_ledger_object::get_field_optional(sfield::ConfidentialBalanceSpending)
153    }
154
155    /// Version number that increments each time the spending balance changes. This version is
156    /// cryptographically bound to ZKPs in outgoing transactions to prevent replay attacks and
157    /// ensure proof validity. If the version changes between proof generation and submission, the
158    /// transaction will fail.
159    fn confidential_balance_version(&self) -> Result<Option<u32>> {
160        current_ledger_object::get_field_optional(sfield::ConfidentialBalanceVersion)
161    }
162
163    /// Copy of the holder's total confidential balance encrypted for the issuer to audit supply.
164    /// Present when the holder has a confidential balance.
165    fn issuer_encrypted_balance(&self) -> Result<Option<StandardBlob>> {
166        current_ledger_object::get_field_optional(sfield::IssuerEncryptedBalance)
167    }
168
169    /// The holder's total confidential balance encrypted under the auditor's key for independent
170    /// auditing. Only present if an auditor is configured.
171    fn auditor_encrypted_balance(&self) -> Result<Option<StandardBlob>> {
172        current_ledger_object::get_field_optional(sfield::AuditorEncryptedBalance)
173    }
174
175    /// The IssuerKeyMirrorEpoch field (Optional).
176    fn issuer_key_mirror_epoch(&self) -> Result<Option<u32>> {
177        current_ledger_object::get_field_optional(sfield::IssuerKeyMirrorEpoch)
178    }
179
180    /// The AuditorKeyMirrorEpoch field (Optional).
181    fn auditor_key_mirror_epoch(&self) -> Result<Option<u32>> {
182        current_ledger_object::get_field_optional(sfield::AuditorKeyMirrorEpoch)
183    }
184
185    /// The holder's ElGamal public key for confidential balances. Present when the holder has a
186    /// confidential balance.
187    fn holder_encryption_key(&self) -> Result<Option<StandardBlob>> {
188        current_ledger_object::get_field_optional(sfield::HolderEncryptionKey)
189    }
190}
191
192#[derive(Debug, Clone, Copy, Eq, PartialEq)]
193pub struct MPToken {
194    pub(crate) slot_num: i32,
195}
196
197impl MPToken {
198    /// Binds this handle to a host-managed slot holding a MPToken ledger object.
199    pub fn new(slot_num: i32) -> Self {
200        Self { slot_num }
201    }
202}
203
204impl LedgerObjectCommonFields for MPToken {
205    fn get_slot_num(&self) -> i32 {
206        self.slot_num
207    }
208}
209
210impl MPTokenFields for MPToken {}
211
212#[cfg(test)]
213mod tests {
214    use super::*;
215    use crate::host::host_bindings_trait::MockHostBindings;
216    use crate::host::setup_mock;
217    use crate::objects::test_utils::*;
218
219    #[test]
220    fn read_all_fields() {
221        let mut mock = MockHostBindings::new();
222        mock_all_fields_present(&mut mock);
223        let _guard = setup_mock(mock);
224
225        let obj = MPToken::new(0);
226
227        assert!(obj.account().is_ok());
228        assert!(obj.mptoken_issuance_id().is_ok());
229        assert!(obj.owner_node().is_ok());
230        assert!(obj.previous_txn_id().is_ok());
231        assert!(obj.previous_txn_lgr_seq().is_ok());
232        assert!(obj.mpt_amount().is_ok());
233        assert!(obj.locked_amount().is_ok());
234        assert!(obj.confidential_balance_inbox().is_ok());
235        assert!(obj.confidential_balance_spending().is_ok());
236        assert!(obj.confidential_balance_version().is_ok());
237        assert!(obj.issuer_encrypted_balance().is_ok());
238        assert!(obj.auditor_encrypted_balance().is_ok());
239        assert!(obj.issuer_key_mirror_epoch().is_ok());
240        assert!(obj.auditor_key_mirror_epoch().is_ok());
241        assert!(obj.holder_encryption_key().is_ok());
242    }
243
244    #[test]
245    fn optional_fields_none() {
246        let mut mock = MockHostBindings::new();
247        mock_all_fields_not_found(&mut mock);
248        let _guard = setup_mock(mock);
249
250        let obj = MPToken::new(0);
251
252        assert!(obj.mpt_amount().unwrap().is_none());
253        assert!(obj.locked_amount().unwrap().is_none());
254        assert!(obj.confidential_balance_version().unwrap().is_none());
255        assert!(obj.issuer_key_mirror_epoch().unwrap().is_none());
256        assert!(obj.auditor_key_mirror_epoch().unwrap().is_none());
257    }
258}