pub struct LedgerPathBuilder { /* private fields */ }Expand description
Fluent builder for reading an inner field from a ledger object — either the object the contract is attached to, or one cached into a slot.
Obtained from the context via
obj.path() for a slot-cached object
or ctx.escrow().path() for the
current one. Any object type works, including ones with no bespoke wrapper: reach for
LedgerObject::new(slot) to build a handle around a raw slot
from cache_le.
Mirrors TxPathBuilder — same Locator buffer, same overflow →
host::Error::LocatorMalformed guard — with two differences: terminal reads are bounded on
FromLedger instead of FromCurrentTx, and a [LedgerSource] picks which of the two
ledger-object host functions to call.
use xrpl_common_stdlib::host::Result;
use xrpl_common_stdlib::objects::traits::LedgerObjectCommonFields;
use xrpl_common_stdlib::sfield;
// Walk every entry of an array field.
if let Result::Ok(count) = obj.path().field(sfield::PriceDataSeries).array_len() {
for i in 0..count {
let price = obj
.path()
.field(sfield::PriceDataSeries)
.index(i)
.field(sfield::AssetPrice)
.get::<u64>();
}
}Implementations§
Source§impl LedgerPathBuilder
impl LedgerPathBuilder
Sourcepub fn field<T, const CODE: i32>(self, _field: SField<T, CODE>) -> Self
pub fn field<T, const CODE: i32>(self, _field: SField<T, CODE>) -> Self
Append a field code to the path. See TxPathBuilder::field.
Sourcepub fn index(self, index: u32) -> Self
pub fn index(self, index: u32) -> Self
Append an array slot index to the path (e.g. the 0 in SignerEntries[0]). See
TxPathBuilder::index.
Sourcepub fn get<T: FromLedger>(&self) -> Result<T>
pub fn get<T: FromLedger>(&self) -> Result<T>
Execute the ledger-object inner-field host call for the built path and decode as T.
T must be readable from a ledger object, hence the FromLedger bound. Returns
host::Error::LocatorMalformed without calling the host if the path is malformed.
Sourcepub fn get_optional<T: FromLedger>(&self) -> Result<Option<T>>
pub fn get_optional<T: FromLedger>(&self) -> Result<Option<T>>
Like get but treats an absent field as Ok(None) rather than an error —
the inner-path counterpart to
get_field_optional.
Only reports absence for fields the host signals with FieldNotFound. Variable-length
fields (the Blob<N> family) are instead reported as a zero-byte write, so an absent one
yields Ok(Some(blob)) with blob.len == 0 rather than Ok(None) — the same distinction
ledger_obj::get_blob_field_optional
exists to handle for flat fields.
Sourcepub fn array_len(&self) -> Result<u32>
pub fn array_len(&self) -> Result<u32>
Ask the host how many entries the array at this path holds, so it can be iterated. See
TxPathBuilder::array_len.
A single-segment path — one field and no index — is the
length of a top-level array such as SignerEntries, so top-level arrays need no separate
accessor.
Trait Implementations§
Source§impl Clone for LedgerPathBuilder
impl Clone for LedgerPathBuilder
Source§fn clone(&self) -> LedgerPathBuilder
fn clone(&self) -> LedgerPathBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more