pub trait CurrentTxFieldGetter: Sized {
// Required methods
fn get_from_current_tx(field_code: i32) -> Result<Self>;
fn get_from_current_tx_optional(field_code: i32) -> Result<Option<Self>>;
}Expand description
Trait for types that can be retrieved from current transaction fields.
This trait provides a unified interface for retrieving typed data from the current XRPL transaction being processed, replacing the previous collection of type-specific functions with a generic, type-safe approach.
§Supported Types
The following types implement this trait:
u32- 32-bit unsigned integers for sequence numbers, flags, timestampsAccountID- 20-byte account identifiers for transaction participantsAmount- XRP amounts and token amounts for transaction valuesHash256- 256-bit hashes for transaction IDs and referencesPublicKey- 33-byte compressed public keys for cryptographic operationsBlob- Variable-length binary data for signatures, memos, and other content
§Usage Patterns
use xrpl_wasm_stdlib::core::current_tx::{get_field, get_field_optional};
use xrpl_wasm_stdlib::core::types::account_id::AccountID;
use xrpl_wasm_stdlib::core::types::amount::Amount;
use xrpl_wasm_stdlib::core::types::blob::Blob;
use xrpl_wasm_stdlib::sfield;
// Get required fields from the current transaction
let account: AccountID = get_field(sfield::Account).unwrap();
let sequence: u32 = get_field(sfield::Sequence).unwrap();
let fee: Amount = get_field(sfield::Fee).unwrap();
// Get optional fields from the current transaction
let flags: Option<u32> = get_field_optional(sfield::Flags).unwrap();
let memo: Option<Blob> = get_field_optional(sfield::Memo).unwrap();§Error Handling
- Required field methods return
Result<T>and error if the field is missing - Optional field methods return
Result<Option<T>>and returnNoneif the field is missing - All methods return appropriate errors for buffer size mismatches or other retrieval failures
§Transaction Context
This trait operates on the “current transaction” - the transaction currently being processed in the XRPL Programmability environment. The transaction context is established by the XRPL host environment before calling into WASM code.
§Safety Considerations
- All implementations use appropriately sized buffers for their data types
- Buffer sizes are validated against expected field sizes where applicable
- Unsafe operations are contained within the host function calls
- Transaction field access is validated by the host environment
Required Methods§
Sourcefn get_from_current_tx(field_code: i32) -> Result<Self>
fn get_from_current_tx(field_code: i32) -> Result<Self>
Get a required field from the current transaction.
This method retrieves a field that must be present in the transaction. If the field is missing, an error is returned.
§Arguments
field_code- The field code identifying which field to retrieve
§Returns
Returns a Result<Self> where:
Ok(Self)- The field value for the specified fieldErr(Error::FieldNotFound)- If the field is not present in the transactionErr(Error)- If the field cannot be retrieved or has unexpected size
Sourcefn get_from_current_tx_optional(field_code: i32) -> Result<Option<Self>>
fn get_from_current_tx_optional(field_code: i32) -> Result<Option<Self>>
Get an optional field from the current transaction.
This method retrieves a field that may or may not be present in the transaction.
If the field is missing, None is returned rather than an error.
§Arguments
field_code- The field code identifying which field to retrieve
§Returns
Returns a Result<Option<Self>> where:
Ok(Some(Self))- The field value for the specified fieldOk(None)- If the field is not present in the transactionErr(Error)- If the field cannot be retrieved or has unexpected size
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl CurrentTxFieldGetter for u32
Implementation of CurrentTxFieldGetter for 32-bit unsigned integers.
impl CurrentTxFieldGetter for u32
Implementation of CurrentTxFieldGetter for 32-bit unsigned integers.
This implementation handles 4-byte integer fields in XRPL transactions. Common use cases include sequence numbers, flags, timestamps, ledger sequence numbers, and various counters and identifiers.
§Buffer Management
Uses a 4-byte buffer and validates that exactly 4 bytes are returned from the host function. The bytes are interpreted as little-endian.
Implementors§
impl CurrentTxFieldGetter for Amount
Implementation of CurrentTxFieldGetter for XRPL amount values.
This implementation handles amount fields in XRPL transactions, which can represent either XRP amounts (8 bytes) or token amounts (up to 48 bytes including currency code and issuer information). Common uses include transaction fees, payment amounts, offer amounts, and escrow amounts.
§Buffer Management
Uses a 48-byte buffer (AMOUNT_SIZE) to accommodate the largest possible amount representation. The Amount type handles the parsing of different amount formats internally. No strict byte count validation is performed since amounts can vary in size.
impl CurrentTxFieldGetter for TransactionType
Implementation of CurrentTxFieldGetter for XRPL TransactionType enums.
This implementation handles 2byte transaction type fields in XRPL transactions.
§Buffer Management
Uses a 2-byte buffer and validates that exactly 2 bytes are returned from the host function.
impl CurrentTxFieldGetter for AccountID
Implementation of CurrentTxFieldGetter for XRPL account identifiers.
This implementation handles 20-byte account ID fields in XRPL transactions. Account IDs identify transaction participants such as the sending account, destination account, and various other account references throughout the transaction.
§Buffer Management
Uses a 20-byte buffer (ACCOUNT_ID_SIZE) and validates that exactly 20 bytes
are returned from the host function. The buffer is converted to an AccountID
using the From<[u8; 20]> implementation.
impl CurrentTxFieldGetter for Blob
Implementation of CurrentTxFieldGetter for variable-length binary data.
This implementation handles blob fields in XRPL transactions, which can contain arbitrary binary data such as transaction signatures, memos, fulfillment data, and other variable-length content that doesn’t fit into fixed-size types.
§Buffer Management
Uses a 1024-byte buffer to accommodate most blob field sizes. The actual
length of the data is determined by the return value from the host function
and stored in the Blob’s len field. No strict byte count validation is
performed since blobs can vary significantly in size.
impl CurrentTxFieldGetter for PublicKey
Implementation of CurrentTxFieldGetter for XRPL public keys.
This implementation handles 33-byte compressed public key fields in XRPL transactions. Public keys are used for cryptographic signature verification and are commonly found in the SigningPubKey field and various other cryptographic contexts.
§Buffer Management
Uses a 33-byte buffer and validates that exactly 33 bytes are returned
from the host function. The buffer is converted to a PublicKey using
the From<[u8; 33]> implementation.
impl CurrentTxFieldGetter for Hash256
Implementation of CurrentTxFieldGetter for 256-bit cryptographic hashes.
This implementation handles 32-byte hash fields in XRPL transactions. Hash256 values are used for transaction IDs, account transaction IDs, references to other transactions, and various cryptographic identifiers.
§Buffer Management
Uses a 32-byte buffer (HASH256_SIZE) and validates that exactly 32 bytes are returned from the host function to ensure data integrity.