Skip to main content

xrpl_common_stdlib/objects/generated/
account_root.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::amount::Amount;
10use crate::types::blob::{PublicKeyBlob, UriBlob};
11use crate::types::uint::{Hash128, Hash256};
12
13/// Trait providing access to fields specific to AccountRoot objects in any ledger.
14pub trait AccountRootFields: LedgerObjectCommonFields {
15    /// The identifying address of this account.
16    fn account(&self) -> Result<AccountID> {
17        ledger_object::get_field(self.get_slot_num(), sfield::Account)
18    }
19
20    /// The sequence number of the next valid transaction for this account.
21    fn sequence(&self) -> Result<u32> {
22        ledger_object::get_field(self.get_slot_num(), sfield::Sequence)
23    }
24
25    /// The account's current XRP balance in drops, represented as a string.
26    fn balance(&self) -> Result<Amount> {
27        ledger_object::get_field(self.get_slot_num(), sfield::Balance)
28    }
29
30    /// The number of objects this account owns in the ledger, which contributes to its owner
31    /// reserve.
32    fn owner_count(&self) -> Result<u32> {
33        ledger_object::get_field(self.get_slot_num(), sfield::OwnerCount)
34    }
35
36    /// The identifying hash of the transaction that most recently modified this object.
37    fn previous_txn_id(&self) -> Result<Hash256> {
38        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
39    }
40
41    /// The index of the ledger that contains the transaction that most recently modified this
42    /// object.
43    fn previous_txn_lgr_seq(&self) -> Result<u32> {
44        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
45    }
46
47    /// The identifying hash of the transaction most recently sent by this account. This field must
48    /// be enabled to use the `AccountTxnID` transaction field. To enable it, send an AccountSet
49    /// transaction with the `asfAccountTxnID` flag enabled.
50    fn account_txn_id(&self) -> Result<Option<Hash256>> {
51        ledger_object::get_field_optional(self.get_slot_num(), sfield::AccountTxnID)
52    }
53
54    /// The address of a key pair that can be used to sign transactions for this account instead of
55    /// the master key. Use a SetRegularKey transaction to change this value.
56    fn regular_key(&self) -> Result<Option<AccountID>> {
57        ledger_object::get_field_optional(self.get_slot_num(), sfield::RegularKey)
58    }
59
60    /// The md5 hash of an email address. Clients can use this to look up an avatar through services
61    /// such as Gravatar.
62    fn email_hash(&self) -> Result<Option<Hash128>> {
63        ledger_object::get_field_optional(self.get_slot_num(), sfield::EmailHash)
64    }
65
66    /// An arbitrary 256-bit value that users can set.
67    fn wallet_locator(&self) -> Result<Option<Hash256>> {
68        ledger_object::get_field_optional(self.get_slot_num(), sfield::WalletLocator)
69    }
70
71    /// Unused. (The code supports this field but there is no way to set it.)
72    fn wallet_size(&self) -> Result<Option<u32>> {
73        ledger_object::get_field_optional(self.get_slot_num(), sfield::WalletSize)
74    }
75
76    /// A public key that may be used to send encrypted messages to this account. In JSON, uses
77    /// hexadecimal. Must be exactly 33 bytes, with the first byte indicating the key type: `0x02`
78    /// or `0x03` for secp256k1 keys, `0xED` for Ed25519 keys.
79    fn message_key(&self) -> Result<Option<PublicKeyBlob>> {
80        ledger_object::get_field_optional(self.get_slot_num(), sfield::MessageKey)
81    }
82
83    /// A transfer fee to charge other users for sending currency issued by this account to each
84    /// other.
85    fn transfer_rate(&self) -> Result<Option<u32>> {
86        ledger_object::get_field_optional(self.get_slot_num(), sfield::TransferRate)
87    }
88
89    /// A domain associated with this account. In JSON, this is the hexadecimal for the ASCII
90    /// representation of the domain. Cannot be more than 256 bytes in length.
91    fn domain(&self) -> Result<Option<UriBlob>> {
92        ledger_object::get_field_optional(self.get_slot_num(), sfield::Domain)
93    }
94
95    /// How many significant digits to use for exchange rates of Offers involving currencies issued
96    /// by this address. Valid values are `3` to `15`, inclusive.
97    fn tick_size(&self) -> Result<Option<u8>> {
98        ledger_object::get_field_optional(self.get_slot_num(), sfield::TickSize)
99    }
100
101    /// How many Tickets this account owns in the ledger. This is updated automatically to ensure
102    /// that the account stays within the hard limit of 250 Tickets at a time. This field is omitted
103    /// if the account has zero Tickets.
104    fn ticket_count(&self) -> Result<Option<u32>> {
105        ledger_object::get_field_optional(self.get_slot_num(), sfield::TicketCount)
106    }
107
108    /// Another account that can mint non-fungible tokens on behalf of this account.
109    fn nftoken_minter(&self) -> Result<Option<AccountID>> {
110        ledger_object::get_field_optional(self.get_slot_num(), sfield::NFTokenMinter)
111    }
112
113    /// How many total non-fungible tokens have been minted by and on behalf of this account.
114    fn minted_nftokens(&self) -> Result<Option<u32>> {
115        ledger_object::get_field_optional(self.get_slot_num(), sfield::MintedNFTokens)
116    }
117
118    /// How many total of this account's issued non-fungible tokens have been burned. This number is
119    /// always equal or less than `MintedNFTokens`.
120    fn burned_nftokens(&self) -> Result<Option<u32>> {
121        ledger_object::get_field_optional(self.get_slot_num(), sfield::BurnedNFTokens)
122    }
123
124    /// The account's Sequence Number at the time it minted its first non-fungible-token.
125    fn first_nftoken_sequence(&self) -> Result<Option<u32>> {
126        ledger_object::get_field_optional(self.get_slot_num(), sfield::FirstNFTokenSequence)
127    }
128
129    /// The number of objects this account owns that are sponsored by another account.
130    fn sponsored_owner_count(&self) -> Result<Option<u32>> {
131        ledger_object::get_field_optional(self.get_slot_num(), sfield::SponsoredOwnerCount)
132    }
133
134    /// The number of objects this account is sponsoring the reserve for.
135    fn sponsoring_owner_count(&self) -> Result<Option<u32>> {
136        ledger_object::get_field_optional(self.get_slot_num(), sfield::SponsoringOwnerCount)
137    }
138
139    /// The number of accounts this account is sponsoring the account reserve for.
140    fn sponsoring_account_count(&self) -> Result<Option<u32>> {
141        ledger_object::get_field_optional(self.get_slot_num(), sfield::SponsoringAccountCount)
142    }
143
144    /// If present, indicates that this is a special AMM pseudo-account AccountRoot; always omitted
145    /// on non-AMM accounts. Contains the ledger entry ID of the corresponding AMM ledger entry. Set
146    /// during account creation; cannot be modified.
147    fn amm_id(&self) -> Result<Option<Hash256>> {
148        ledger_object::get_field_optional(self.get_slot_num(), sfield::AMMID)
149    }
150
151    /// The ID of the `Vault` entry associated with this account. Set during account creation;
152    /// cannot be modified. If present, indicates that this is a special Vault pseudo-account
153    /// AccountRoot; always omitted on non-Vault accounts.
154    fn vault_id(&self) -> Result<Option<Hash256>> {
155        ledger_object::get_field_optional(self.get_slot_num(), sfield::VaultID)
156    }
157
158    /// The LoanBrokerID field (Optional).
159    fn loan_broker_id(&self) -> Result<Option<Hash256>> {
160        ledger_object::get_field_optional(self.get_slot_num(), sfield::LoanBrokerID)
161    }
162}
163
164/// Trait providing access to fields specific to the current AccountRoot object.
165pub trait CurrentAccountRootFields: CurrentLedgerObjectCommonFields {
166    /// The identifying address of this account.
167    fn account(&self) -> Result<AccountID> {
168        current_ledger_object::get_field(sfield::Account)
169    }
170
171    /// The sequence number of the next valid transaction for this account.
172    fn sequence(&self) -> Result<u32> {
173        current_ledger_object::get_field(sfield::Sequence)
174    }
175
176    /// The account's current XRP balance in drops, represented as a string.
177    fn balance(&self) -> Result<Amount> {
178        current_ledger_object::get_field(sfield::Balance)
179    }
180
181    /// The number of objects this account owns in the ledger, which contributes to its owner
182    /// reserve.
183    fn owner_count(&self) -> Result<u32> {
184        current_ledger_object::get_field(sfield::OwnerCount)
185    }
186
187    /// The identifying hash of the transaction that most recently modified this object.
188    fn previous_txn_id(&self) -> Result<Hash256> {
189        current_ledger_object::get_field(sfield::PreviousTxnID)
190    }
191
192    /// The index of the ledger that contains the transaction that most recently modified this
193    /// object.
194    fn previous_txn_lgr_seq(&self) -> Result<u32> {
195        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
196    }
197
198    /// The identifying hash of the transaction most recently sent by this account. This field must
199    /// be enabled to use the `AccountTxnID` transaction field. To enable it, send an AccountSet
200    /// transaction with the `asfAccountTxnID` flag enabled.
201    fn account_txn_id(&self) -> Result<Option<Hash256>> {
202        current_ledger_object::get_field_optional(sfield::AccountTxnID)
203    }
204
205    /// The address of a key pair that can be used to sign transactions for this account instead of
206    /// the master key. Use a SetRegularKey transaction to change this value.
207    fn regular_key(&self) -> Result<Option<AccountID>> {
208        current_ledger_object::get_field_optional(sfield::RegularKey)
209    }
210
211    /// The md5 hash of an email address. Clients can use this to look up an avatar through services
212    /// such as Gravatar.
213    fn email_hash(&self) -> Result<Option<Hash128>> {
214        current_ledger_object::get_field_optional(sfield::EmailHash)
215    }
216
217    /// An arbitrary 256-bit value that users can set.
218    fn wallet_locator(&self) -> Result<Option<Hash256>> {
219        current_ledger_object::get_field_optional(sfield::WalletLocator)
220    }
221
222    /// Unused. (The code supports this field but there is no way to set it.)
223    fn wallet_size(&self) -> Result<Option<u32>> {
224        current_ledger_object::get_field_optional(sfield::WalletSize)
225    }
226
227    /// A public key that may be used to send encrypted messages to this account. In JSON, uses
228    /// hexadecimal. Must be exactly 33 bytes, with the first byte indicating the key type: `0x02`
229    /// or `0x03` for secp256k1 keys, `0xED` for Ed25519 keys.
230    fn message_key(&self) -> Result<Option<PublicKeyBlob>> {
231        current_ledger_object::get_field_optional(sfield::MessageKey)
232    }
233
234    /// A transfer fee to charge other users for sending currency issued by this account to each
235    /// other.
236    fn transfer_rate(&self) -> Result<Option<u32>> {
237        current_ledger_object::get_field_optional(sfield::TransferRate)
238    }
239
240    /// A domain associated with this account. In JSON, this is the hexadecimal for the ASCII
241    /// representation of the domain. Cannot be more than 256 bytes in length.
242    fn domain(&self) -> Result<Option<UriBlob>> {
243        current_ledger_object::get_field_optional(sfield::Domain)
244    }
245
246    /// How many significant digits to use for exchange rates of Offers involving currencies issued
247    /// by this address. Valid values are `3` to `15`, inclusive.
248    fn tick_size(&self) -> Result<Option<u8>> {
249        current_ledger_object::get_field_optional(sfield::TickSize)
250    }
251
252    /// How many Tickets this account owns in the ledger. This is updated automatically to ensure
253    /// that the account stays within the hard limit of 250 Tickets at a time. This field is omitted
254    /// if the account has zero Tickets.
255    fn ticket_count(&self) -> Result<Option<u32>> {
256        current_ledger_object::get_field_optional(sfield::TicketCount)
257    }
258
259    /// Another account that can mint non-fungible tokens on behalf of this account.
260    fn nftoken_minter(&self) -> Result<Option<AccountID>> {
261        current_ledger_object::get_field_optional(sfield::NFTokenMinter)
262    }
263
264    /// How many total non-fungible tokens have been minted by and on behalf of this account.
265    fn minted_nftokens(&self) -> Result<Option<u32>> {
266        current_ledger_object::get_field_optional(sfield::MintedNFTokens)
267    }
268
269    /// How many total of this account's issued non-fungible tokens have been burned. This number is
270    /// always equal or less than `MintedNFTokens`.
271    fn burned_nftokens(&self) -> Result<Option<u32>> {
272        current_ledger_object::get_field_optional(sfield::BurnedNFTokens)
273    }
274
275    /// The account's Sequence Number at the time it minted its first non-fungible-token.
276    fn first_nftoken_sequence(&self) -> Result<Option<u32>> {
277        current_ledger_object::get_field_optional(sfield::FirstNFTokenSequence)
278    }
279
280    /// The number of objects this account owns that are sponsored by another account.
281    fn sponsored_owner_count(&self) -> Result<Option<u32>> {
282        current_ledger_object::get_field_optional(sfield::SponsoredOwnerCount)
283    }
284
285    /// The number of objects this account is sponsoring the reserve for.
286    fn sponsoring_owner_count(&self) -> Result<Option<u32>> {
287        current_ledger_object::get_field_optional(sfield::SponsoringOwnerCount)
288    }
289
290    /// The number of accounts this account is sponsoring the account reserve for.
291    fn sponsoring_account_count(&self) -> Result<Option<u32>> {
292        current_ledger_object::get_field_optional(sfield::SponsoringAccountCount)
293    }
294
295    /// If present, indicates that this is a special AMM pseudo-account AccountRoot; always omitted
296    /// on non-AMM accounts. Contains the ledger entry ID of the corresponding AMM ledger entry. Set
297    /// during account creation; cannot be modified.
298    fn amm_id(&self) -> Result<Option<Hash256>> {
299        current_ledger_object::get_field_optional(sfield::AMMID)
300    }
301
302    /// The ID of the `Vault` entry associated with this account. Set during account creation;
303    /// cannot be modified. If present, indicates that this is a special Vault pseudo-account
304    /// AccountRoot; always omitted on non-Vault accounts.
305    fn vault_id(&self) -> Result<Option<Hash256>> {
306        current_ledger_object::get_field_optional(sfield::VaultID)
307    }
308
309    /// The LoanBrokerID field (Optional).
310    fn loan_broker_id(&self) -> Result<Option<Hash256>> {
311        current_ledger_object::get_field_optional(sfield::LoanBrokerID)
312    }
313}
314
315#[derive(Debug, Clone, Copy, Eq, PartialEq)]
316pub struct AccountRoot {
317    pub(crate) slot_num: i32,
318}
319
320impl AccountRoot {
321    /// Binds this handle to a host-managed slot holding an AccountRoot ledger object.
322    pub fn new(slot_num: i32) -> Self {
323        Self { slot_num }
324    }
325}
326
327impl LedgerObjectCommonFields for AccountRoot {
328    fn get_slot_num(&self) -> i32 {
329        self.slot_num
330    }
331}
332
333impl AccountRootFields for AccountRoot {}
334
335#[cfg(test)]
336mod tests {
337    use super::*;
338    use crate::host::host_bindings_trait::MockHostBindings;
339    use crate::host::setup_mock;
340    use crate::objects::test_utils::*;
341
342    #[test]
343    fn read_all_fields() {
344        let mut mock = MockHostBindings::new();
345        mock_all_fields_present(&mut mock);
346        let _guard = setup_mock(mock);
347
348        let obj = AccountRoot::new(0);
349
350        assert!(obj.account().is_ok());
351        assert!(obj.sequence().is_ok());
352        assert!(obj.balance().is_ok());
353        assert!(obj.owner_count().is_ok());
354        assert!(obj.previous_txn_id().is_ok());
355        assert!(obj.previous_txn_lgr_seq().is_ok());
356        assert!(obj.account_txn_id().is_ok());
357        assert!(obj.regular_key().is_ok());
358        assert!(obj.email_hash().is_ok());
359        assert!(obj.wallet_locator().is_ok());
360        assert!(obj.wallet_size().is_ok());
361        assert!(obj.message_key().is_ok());
362        assert!(obj.transfer_rate().is_ok());
363        assert!(obj.domain().is_ok());
364        assert!(obj.tick_size().is_ok());
365        assert!(obj.ticket_count().is_ok());
366        assert!(obj.nftoken_minter().is_ok());
367        assert!(obj.minted_nftokens().is_ok());
368        assert!(obj.burned_nftokens().is_ok());
369        assert!(obj.first_nftoken_sequence().is_ok());
370        assert!(obj.sponsored_owner_count().is_ok());
371        assert!(obj.sponsoring_owner_count().is_ok());
372        assert!(obj.sponsoring_account_count().is_ok());
373        assert!(obj.amm_id().is_ok());
374        assert!(obj.vault_id().is_ok());
375        assert!(obj.loan_broker_id().is_ok());
376    }
377
378    #[test]
379    fn optional_fields_none() {
380        let mut mock = MockHostBindings::new();
381        mock_all_fields_not_found(&mut mock);
382        let _guard = setup_mock(mock);
383
384        let obj = AccountRoot::new(0);
385
386        assert!(obj.account_txn_id().unwrap().is_none());
387        assert!(obj.regular_key().unwrap().is_none());
388        assert!(obj.email_hash().unwrap().is_none());
389        assert!(obj.wallet_locator().unwrap().is_none());
390        assert!(obj.wallet_size().unwrap().is_none());
391        assert!(obj.transfer_rate().unwrap().is_none());
392        assert!(obj.tick_size().unwrap().is_none());
393        assert!(obj.ticket_count().unwrap().is_none());
394        assert!(obj.nftoken_minter().unwrap().is_none());
395        assert!(obj.minted_nftokens().unwrap().is_none());
396        assert!(obj.burned_nftokens().unwrap().is_none());
397        assert!(obj.first_nftoken_sequence().unwrap().is_none());
398        assert!(obj.sponsored_owner_count().unwrap().is_none());
399        assert!(obj.sponsoring_owner_count().unwrap().is_none());
400        assert!(obj.sponsoring_account_count().unwrap().is_none());
401        assert!(obj.amm_id().unwrap().is_none());
402        assert!(obj.vault_id().unwrap().is_none());
403        assert!(obj.loan_broker_id().unwrap().is_none());
404    }
405}