Skip to main content

get_field

Function get_field 

Source
pub fn get_field<T: LedgerObjectFieldGetter, const CODE: i32>(
    register_num: i32,
    _field: SField<T, CODE>,
) -> Result<T>
Expand description

Retrieves a field from a specified ledger object.

§Arguments

  • register_num - The register number holding the ledger object to look for data in
  • field - An SField constant that encodes both the field code and expected type

§Returns

Returns a Result<T> where:

  • Ok(T) - The field value for the specified field
  • Err(Error) - If the field cannot be retrieved or has unexpected size

§Example

use xrpl_wasm_stdlib::core::ledger_objects::ledger_object;
use xrpl_wasm_stdlib::sfield;

// Type is automatically inferred from the SField constant
let balance = ledger_object::get_field(0, sfield::Balance).unwrap();  // u64
let account = ledger_object::get_field(0, sfield::Account).unwrap();  // AccountID