Skip to main content

TxPathBuilder

Struct TxPathBuilder 

Source
pub struct TxPathBuilder { /* private fields */ }
Expand description

Fluent builder for reading an inner field from the current transaction.

Obtained from the context via ctx.tx().path(); rooting it there is what guarantees the terminal get reads through the current-transaction host function and never crosses into a ledger-object read. Each field / index call appends one 4-byte segment to the underlying Locator buffer.

A path longer than the 64-byte buffer (more than 16 segments) can hold is not silently truncated: the overflow is remembered and surfaced as host::Error::LocatorMalformed from get, rather than sending the host a shorter path than the author wrote.

use xrpl_common_stdlib::current_tx::traits::TransactionCommonFields;
use xrpl_common_stdlib::host::Result;
use xrpl_common_stdlib::sfield;
use xrpl_common_stdlib::types::blob::StandardBlob;
// Walk every entry of an array field.
if let Result::Ok(count) = tx.path().field(sfield::Memos).array_len() {
    for i in 0..count {
        let memo_type = tx
            .path()
            .field(sfield::Memos)
            .index(i)
            .field(sfield::Memo)
            .field(sfield::MemoType)
            .get::<StandardBlob>();
    }
}

Implementations§

Source§

impl TxPathBuilder

Source

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

Append a field code to the path.

Takes a typed SField<T, CODE> constant (e.g. sfield::Memos) so the field code is a compile-time constant; only the code is encoded — the field’s declared type T is irrelevant to the path and is chosen instead at get.

Source

pub fn index(self, index: u32) -> Self

Append an array slot index to the path (e.g. the 0 in Memos[0]).

Locator segments are i32, so an index above i32::MAX would pack as a negative value the host would read back as a field code. Rather than encode that, the path is marked malformed and the terminals report host::Error::LocatorMalformed. No array reachable through array_len can be that long — the host reports lengths as i32 — so this only rejects an index that did not come from walking the array.

Source

pub fn get<T: FromCurrentTx>(&self) -> Result<T>

Execute the tx_inner host call for the built path and decode the result as T.

T picks the terminal type (and therefore the read buffer size and decoder); it must be readable from a transaction, hence the FromCurrentTx bound.

Returns host::Error::LocatorMalformed without calling the host if the path overflowed the buffer while being built.

Source

pub fn get_optional<T: FromCurrentTx>(&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.

Returns host::Error::LocatorMalformed without calling the host if the path overflowed.

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.

Named array_len rather than len because Locator::len already means “bytes packed into the path”; this is the length of the array the path points at. Returns Ok(0) for a present-but-empty array, and host::Error::LocatorMalformed without calling the host if the path overflowed the buffer while being built.

A single-segment path — one field and no index — is the length of a top-level array such as Memos, so top-level arrays need no separate accessor.

Trait Implementations§

Source§

impl Clone for TxPathBuilder

Source§

fn clone(&self) -> TxPathBuilder

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 TxPathBuilder

Source§

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

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

impl Eq for TxPathBuilder

Source§

impl PartialEq for TxPathBuilder

Source§

fn eq(&self, other: &TxPathBuilder) -> 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 TxPathBuilder

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.