Skip to main content

xrpl_common_stdlib/objects/
mod.rs

1//! Ledger-object field access.
2//!
3//! Reading a field from a ledger object is the same two steps as reading one from the current
4//! transaction: call a host function into a buffer, then decode the bytes into a typed value.
5//! That decode step is captured once per type by [`crate::fields::decoder::FieldDecoder`], and a
6//! type opts into being *readable from a ledger object* via the
7//! [`crate::fields::decoder::FromLedger`] marker.
8//!
9//! Two entry points, mirroring the transaction side:
10//!
11//! - [`ledger_object`] — read from a ledger object cached into a slot (via [`cache_le`]).
12//! - [`current_ledger_object`] — read from the current ledger object, without a slot.
13//!
14//! Both are the generic `FieldDecoder`-based accessors re-exported from [`crate::fields`]; see
15//! that module for the decode machinery and the `Blob<N>` zero-copy accessors.
16//!
17//! ```rust,no_run
18//! use xrpl_common_stdlib::objects::{ledger_object, current_ledger_object};
19//! use xrpl_common_stdlib::sfield;
20//!
21//! fn example() {
22//!   let slot = 0;
23//!   // Get a required field from a specific (slot-cached) ledger object
24//!   let balance = ledger_object::get_field(slot, sfield::Balance).unwrap();
25//!   let account = ledger_object::get_field(slot, sfield::Account).unwrap();
26//!
27//!   // Get an optional field from the current ledger object
28//!   let flags = current_ledger_object::get_field_optional(sfield::Flags).unwrap();
29//! }
30//! ```
31
32pub mod any_object;
33pub mod array_object;
34pub mod cache;
35// Crate-internal: the flat `pub use generated::{...}` below is the public path
36// to each type (`objects::AccountRoot`), not `objects::generated::...`.
37pub(crate) mod generated;
38#[cfg(all(any(test, feature = "test-host-bindings"), not(target_arch = "wasm32")))]
39pub mod test_utils;
40pub mod traits;
41
42/// Typed field accessors for the current ledger object (no slot). See
43/// [`crate::fields::current_ledger_obj`].
44pub use crate::fields::current_ledger_obj as current_ledger_object;
45/// Typed field accessors for a ledger object cached into a slot. See [`crate::fields::ledger_obj`].
46pub use crate::fields::ledger_obj as ledger_object;
47/// Untyped handle to a slot-cached ledger object, for object types with no typed wrapper.
48pub use any_object::LedgerObject;
49/// Load a ledger entry into a host cache slot. See [`crate::objects::cache`].
50pub use cache::cache_le;
51
52pub use generated::{
53    AMM, AMMFields, AccountRoot, AccountRootFields, Amendments, AmendmentsFields, Bridge,
54    BridgeFields, Check, CheckFields, Credential, CredentialFields, CurrentAMMFields,
55    CurrentAccountRootFields, CurrentAmendmentsFields, CurrentBridgeFields, CurrentCheckFields,
56    CurrentCredentialFields, CurrentDIDFields, CurrentDelegateFields, CurrentDepositPreauthFields,
57    CurrentDirectoryNodeFields, CurrentFeeSettingsFields, CurrentLedgerHashesFields,
58    CurrentLoanBrokerFields, CurrentLoanFields, CurrentMPTokenFields, CurrentMPTokenIssuanceFields,
59    CurrentNFTokenOfferFields, CurrentNFTokenPageFields, CurrentNegativeUNLFields,
60    CurrentOfferFields, CurrentOracleFields, CurrentPayChannelFields,
61    CurrentPermissionedDomainFields, CurrentRippleStateFields, CurrentSignerListFields,
62    CurrentSponsorshipFields, CurrentTicketFields, CurrentVaultFields,
63    CurrentXChainOwnedClaimIDFields, CurrentXChainOwnedCreateAccountClaimIDFields, DID, DIDFields,
64    Delegate, DelegateFields, DepositPreauth, DepositPreauthFields, DirectoryNode,
65    DirectoryNodeFields, Escrow, EscrowFields, FeeSettings, FeeSettingsFields, LedgerHashes,
66    LedgerHashesFields, Loan, LoanBroker, LoanBrokerFields, LoanFields, MPToken, MPTokenFields,
67    MPTokenIssuance, MPTokenIssuanceFields, NFTokenOffer, NFTokenOfferFields, NFTokenPage,
68    NFTokenPageFields, NegativeUNL, NegativeUNLFields, Offer, OfferFields, Oracle, OracleFields,
69    PayChannel, PayChannelFields, PermissionedDomain, PermissionedDomainFields, RippleState,
70    RippleStateFields, SignerList, SignerListFields, Sponsorship, SponsorshipFields, Ticket,
71    TicketFields, Vault, VaultFields, XChainOwnedClaimID, XChainOwnedClaimIDFields,
72    XChainOwnedCreateAccountClaimID, XChainOwnedCreateAccountClaimIDFields,
73};