Skip to main content

LedgerPathBuilder

Struct LedgerPathBuilder 

Source
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

Source

pub fn field<T, const CODE: i32>(self, _field: SField<T, CODE>) -> Self

Append a field code to the path. See TxPathBuilder::field.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LedgerPathBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LedgerPathBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LedgerPathBuilder

Source§

impl PartialEq for LedgerPathBuilder

Source§

fn eq(&self, other: &LedgerPathBuilder) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LedgerPathBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.