Skip to main content

xrpl_common_stdlib/objects/generated/
mptoken_issuance.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::Hash256;
11
12/// Trait providing access to fields specific to MPTokenIssuance objects in any ledger.
13pub trait MPTokenIssuanceFields: LedgerObjectCommonFields {
14    /// The address of the account that controls both the issuance amounts and characteristics of a
15    /// particular fungible token.
16    fn issuer(&self) -> Result<AccountID> {
17        ledger_object::get_field(self.get_slot_num(), sfield::Issuer)
18    }
19
20    /// The `Sequence` (or `Ticket`) number of the transaction that created this issuance. This
21    /// helps to uniquely identify the issuance and distinguish it from any other later MPT
22    /// issuances created by this account.
23    fn sequence(&self) -> Result<u32> {
24        ledger_object::get_field(self.get_slot_num(), sfield::Sequence)
25    }
26
27    /// This value specifies the fee, in tenths of a basis point, charged by the issuer for
28    /// secondary sales of the token, if such sales are allowed at all. Valid values for this field
29    /// are between 0 and 50,000 inclusive. A value of 1 is equivalent to 1/10 of a basis point or
30    /// 0.001%, allowing transfer rates between 0% and 50%. A `TransferFee` of 50,000 corresponds to
31    /// 50%. The default value for this field is 0. Any decimals in the transfer fee are rounded
32    /// down. The fee can be rounded down to zero if the payment is small. Issuers should make sure
33    /// that their MPT's `AssetScale` is large enough. <br><br>This field is mutable by default, but
34    /// can be made immutable.
35    fn transfer_fee(&self) -> Result<Option<u16>> {
36        ledger_object::get_field_optional(self.get_slot_num(), sfield::TransferFee)
37    }
38
39    /// A hint indicating which page of the owner directory links to this entry, in case the
40    /// directory consists of multiple pages.
41    fn owner_node(&self) -> Result<u64> {
42        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
43    }
44
45    /// Where to put the decimal place when displaying amounts of this MPT. More formally, the asset
46    /// scale is a non-negative integer (0, 1, 2, …) such that one standard unit equals 10^(-scale)
47    /// of a corresponding fractional unit. For example, if a US Dollar Stablecoin has an asset
48    /// scale of _2_, then 1 unit of that MPT would equal 0.01 US Dollars. This indicates to how
49    /// many decimal places the MPT can be subdivided. The default is `0`, meaning that the MPT
50    /// cannot be divided into smaller than 1 unit.
51    fn asset_scale(&self) -> Result<Option<u8>> {
52        ledger_object::get_field_optional(self.get_slot_num(), sfield::AssetScale)
53    }
54
55    /// The maximum number of MPTs that can exist at one time. If omitted, the maximum is currently
56    /// limited to 2^63-1.
57    fn maximum_amount(&self) -> Result<Option<u64>> {
58        ledger_object::get_field_optional(self.get_slot_num(), sfield::MaximumAmount)
59    }
60
61    /// The total amount of MPTs of this issuance currently in circulation. This value increases
62    /// when the issuer sends MPTs to a non-issuer, and decreases whenever the issuer receives MPTs.
63    fn outstanding_amount(&self) -> Result<u64> {
64        ledger_object::get_field(self.get_slot_num(), sfield::OutstandingAmount)
65    }
66
67    /// The amount of tokens currently locked up (for example, in escrow). This amount is already
68    /// included in the `OutstandingAmount`.
69    fn locked_amount(&self) -> Result<Option<u64>> {
70        ledger_object::get_field_optional(self.get_slot_num(), sfield::LockedAmount)
71    }
72
73    /// Arbitrary metadata about this issuance, in hex format. The limit for this field is 1024
74    /// bytes. <br><br>This field is mutable by default, but can be made immutable.
75    fn mptoken_metadata(&self) -> Result<Option<StandardBlob>> {
76        ledger_object::get_field_optional(self.get_slot_num(), sfield::MPTokenMetadata)
77    }
78
79    /// The identifying hash of the transaction that most recently modified this entry.
80    fn previous_txn_id(&self) -> Result<Hash256> {
81        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
82    }
83
84    /// The index of the ledger that contains the transaction that most recently modified this
85    /// object.
86    fn previous_txn_lgr_seq(&self) -> Result<u32> {
87        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
88    }
89
90    /// The ledger entry ID of a permissioned domain that grants access to the MPT. This field is
91    /// _always_ mutable.
92    fn domain_id(&self) -> Result<Option<Hash256>> {
93        ledger_object::get_field_optional(self.get_slot_num(), sfield::DomainID)
94    }
95
96    /// Indicates which fields and flags are immutable for this MPT issuance. Any field or flag not
97    /// represented here remains mutable. See MPTokenIssuance Immutable Flags.
98    fn immutable_flags(&self) -> Result<Option<u32>> {
99        ledger_object::get_field_optional(self.get_slot_num(), sfield::ImmutableFlags)
100    }
101
102    /// The ReferenceHolding field (Optional).
103    fn reference_holding(&self) -> Result<Option<Hash256>> {
104        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReferenceHolding)
105    }
106
107    /// A 33-byte compressed ElGamal public key for the issuer.
108    fn issuer_encryption_key(&self) -> Result<Option<StandardBlob>> {
109        ledger_object::get_field_optional(self.get_slot_num(), sfield::IssuerEncryptionKey)
110    }
111
112    /// A 33-byte compressed ElGamal public key for an optional on-chain auditor.
113    fn auditor_encryption_key(&self) -> Result<Option<StandardBlob>> {
114        ledger_object::get_field_optional(self.get_slot_num(), sfield::AuditorEncryptionKey)
115    }
116
117    /// The IssuerKeyEpoch field (Optional).
118    fn issuer_key_epoch(&self) -> Result<Option<u32>> {
119        ledger_object::get_field_optional(self.get_slot_num(), sfield::IssuerKeyEpoch)
120    }
121
122    /// The AuditorKeyEpoch field (Optional).
123    fn auditor_key_epoch(&self) -> Result<Option<u32>> {
124        ledger_object::get_field_optional(self.get_slot_num(), sfield::AuditorKeyEpoch)
125    }
126
127    /// The total amount of this token that is currently held in confidential balances.
128    fn confidential_outstanding_amount(&self) -> Result<Option<u64>> {
129        ledger_object::get_field_optional(
130            self.get_slot_num(),
131            sfield::ConfidentialOutstandingAmount,
132        )
133    }
134}
135
136/// Trait providing access to fields specific to the current MPTokenIssuance object.
137pub trait CurrentMPTokenIssuanceFields: CurrentLedgerObjectCommonFields {
138    /// The address of the account that controls both the issuance amounts and characteristics of a
139    /// particular fungible token.
140    fn issuer(&self) -> Result<AccountID> {
141        current_ledger_object::get_field(sfield::Issuer)
142    }
143
144    /// The `Sequence` (or `Ticket`) number of the transaction that created this issuance. This
145    /// helps to uniquely identify the issuance and distinguish it from any other later MPT
146    /// issuances created by this account.
147    fn sequence(&self) -> Result<u32> {
148        current_ledger_object::get_field(sfield::Sequence)
149    }
150
151    /// This value specifies the fee, in tenths of a basis point, charged by the issuer for
152    /// secondary sales of the token, if such sales are allowed at all. Valid values for this field
153    /// are between 0 and 50,000 inclusive. A value of 1 is equivalent to 1/10 of a basis point or
154    /// 0.001%, allowing transfer rates between 0% and 50%. A `TransferFee` of 50,000 corresponds to
155    /// 50%. The default value for this field is 0. Any decimals in the transfer fee are rounded
156    /// down. The fee can be rounded down to zero if the payment is small. Issuers should make sure
157    /// that their MPT's `AssetScale` is large enough. <br><br>This field is mutable by default, but
158    /// can be made immutable.
159    fn transfer_fee(&self) -> Result<Option<u16>> {
160        current_ledger_object::get_field_optional(sfield::TransferFee)
161    }
162
163    /// A hint indicating which page of the owner directory links to this entry, in case the
164    /// directory consists of multiple pages.
165    fn owner_node(&self) -> Result<u64> {
166        current_ledger_object::get_field(sfield::OwnerNode)
167    }
168
169    /// Where to put the decimal place when displaying amounts of this MPT. More formally, the asset
170    /// scale is a non-negative integer (0, 1, 2, …) such that one standard unit equals 10^(-scale)
171    /// of a corresponding fractional unit. For example, if a US Dollar Stablecoin has an asset
172    /// scale of _2_, then 1 unit of that MPT would equal 0.01 US Dollars. This indicates to how
173    /// many decimal places the MPT can be subdivided. The default is `0`, meaning that the MPT
174    /// cannot be divided into smaller than 1 unit.
175    fn asset_scale(&self) -> Result<Option<u8>> {
176        current_ledger_object::get_field_optional(sfield::AssetScale)
177    }
178
179    /// The maximum number of MPTs that can exist at one time. If omitted, the maximum is currently
180    /// limited to 2^63-1.
181    fn maximum_amount(&self) -> Result<Option<u64>> {
182        current_ledger_object::get_field_optional(sfield::MaximumAmount)
183    }
184
185    /// The total amount of MPTs of this issuance currently in circulation. This value increases
186    /// when the issuer sends MPTs to a non-issuer, and decreases whenever the issuer receives MPTs.
187    fn outstanding_amount(&self) -> Result<u64> {
188        current_ledger_object::get_field(sfield::OutstandingAmount)
189    }
190
191    /// The amount of tokens currently locked up (for example, in escrow). This amount is already
192    /// included in the `OutstandingAmount`.
193    fn locked_amount(&self) -> Result<Option<u64>> {
194        current_ledger_object::get_field_optional(sfield::LockedAmount)
195    }
196
197    /// Arbitrary metadata about this issuance, in hex format. The limit for this field is 1024
198    /// bytes. <br><br>This field is mutable by default, but can be made immutable.
199    fn mptoken_metadata(&self) -> Result<Option<StandardBlob>> {
200        current_ledger_object::get_field_optional(sfield::MPTokenMetadata)
201    }
202
203    /// The identifying hash of the transaction that most recently modified this entry.
204    fn previous_txn_id(&self) -> Result<Hash256> {
205        current_ledger_object::get_field(sfield::PreviousTxnID)
206    }
207
208    /// The index of the ledger that contains the transaction that most recently modified this
209    /// object.
210    fn previous_txn_lgr_seq(&self) -> Result<u32> {
211        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
212    }
213
214    /// The ledger entry ID of a permissioned domain that grants access to the MPT. This field is
215    /// _always_ mutable.
216    fn domain_id(&self) -> Result<Option<Hash256>> {
217        current_ledger_object::get_field_optional(sfield::DomainID)
218    }
219
220    /// Indicates which fields and flags are immutable for this MPT issuance. Any field or flag not
221    /// represented here remains mutable. See MPTokenIssuance Immutable Flags.
222    fn immutable_flags(&self) -> Result<Option<u32>> {
223        current_ledger_object::get_field_optional(sfield::ImmutableFlags)
224    }
225
226    /// The ReferenceHolding field (Optional).
227    fn reference_holding(&self) -> Result<Option<Hash256>> {
228        current_ledger_object::get_field_optional(sfield::ReferenceHolding)
229    }
230
231    /// A 33-byte compressed ElGamal public key for the issuer.
232    fn issuer_encryption_key(&self) -> Result<Option<StandardBlob>> {
233        current_ledger_object::get_field_optional(sfield::IssuerEncryptionKey)
234    }
235
236    /// A 33-byte compressed ElGamal public key for an optional on-chain auditor.
237    fn auditor_encryption_key(&self) -> Result<Option<StandardBlob>> {
238        current_ledger_object::get_field_optional(sfield::AuditorEncryptionKey)
239    }
240
241    /// The IssuerKeyEpoch field (Optional).
242    fn issuer_key_epoch(&self) -> Result<Option<u32>> {
243        current_ledger_object::get_field_optional(sfield::IssuerKeyEpoch)
244    }
245
246    /// The AuditorKeyEpoch field (Optional).
247    fn auditor_key_epoch(&self) -> Result<Option<u32>> {
248        current_ledger_object::get_field_optional(sfield::AuditorKeyEpoch)
249    }
250
251    /// The total amount of this token that is currently held in confidential balances.
252    fn confidential_outstanding_amount(&self) -> Result<Option<u64>> {
253        current_ledger_object::get_field_optional(sfield::ConfidentialOutstandingAmount)
254    }
255}
256
257#[derive(Debug, Clone, Copy, Eq, PartialEq)]
258pub struct MPTokenIssuance {
259    pub(crate) slot_num: i32,
260}
261
262impl MPTokenIssuance {
263    /// Binds this handle to a host-managed slot holding a MPTokenIssuance ledger object.
264    pub fn new(slot_num: i32) -> Self {
265        Self { slot_num }
266    }
267}
268
269impl LedgerObjectCommonFields for MPTokenIssuance {
270    fn get_slot_num(&self) -> i32 {
271        self.slot_num
272    }
273}
274
275impl MPTokenIssuanceFields for MPTokenIssuance {}
276
277#[cfg(test)]
278mod tests {
279    use super::*;
280    use crate::host::host_bindings_trait::MockHostBindings;
281    use crate::host::setup_mock;
282    use crate::objects::test_utils::*;
283
284    #[test]
285    fn read_all_fields() {
286        let mut mock = MockHostBindings::new();
287        mock_all_fields_present(&mut mock);
288        let _guard = setup_mock(mock);
289
290        let obj = MPTokenIssuance::new(0);
291
292        assert!(obj.issuer().is_ok());
293        assert!(obj.sequence().is_ok());
294        assert!(obj.owner_node().is_ok());
295        assert!(obj.outstanding_amount().is_ok());
296        assert!(obj.previous_txn_id().is_ok());
297        assert!(obj.previous_txn_lgr_seq().is_ok());
298        assert!(obj.transfer_fee().is_ok());
299        assert!(obj.asset_scale().is_ok());
300        assert!(obj.maximum_amount().is_ok());
301        assert!(obj.locked_amount().is_ok());
302        assert!(obj.mptoken_metadata().is_ok());
303        assert!(obj.domain_id().is_ok());
304        assert!(obj.immutable_flags().is_ok());
305        assert!(obj.reference_holding().is_ok());
306        assert!(obj.issuer_encryption_key().is_ok());
307        assert!(obj.auditor_encryption_key().is_ok());
308        assert!(obj.issuer_key_epoch().is_ok());
309        assert!(obj.auditor_key_epoch().is_ok());
310        assert!(obj.confidential_outstanding_amount().is_ok());
311    }
312
313    #[test]
314    fn optional_fields_none() {
315        let mut mock = MockHostBindings::new();
316        mock_all_fields_not_found(&mut mock);
317        let _guard = setup_mock(mock);
318
319        let obj = MPTokenIssuance::new(0);
320
321        assert!(obj.transfer_fee().unwrap().is_none());
322        assert!(obj.asset_scale().unwrap().is_none());
323        assert!(obj.maximum_amount().unwrap().is_none());
324        assert!(obj.locked_amount().unwrap().is_none());
325        assert!(obj.domain_id().unwrap().is_none());
326        assert!(obj.immutable_flags().unwrap().is_none());
327        assert!(obj.reference_holding().unwrap().is_none());
328        assert!(obj.issuer_key_epoch().unwrap().is_none());
329        assert!(obj.auditor_key_epoch().unwrap().is_none());
330        assert!(obj.confidential_outstanding_amount().unwrap().is_none());
331    }
332}