Expand description
ABI (Application Binary Interface) helpers for function dispatch and calldata parsing.
This module provides utilities for:
- Computing function selectors from names
- Extracting selectors from calldata
- Reading typed values from calldata at specific offsets
§Function Selectors
TruthLinked uses FNV-1a 32-bit hashing for function selectors (4 bytes). This is deterministic, no-std compatible, and provides good distribution.
§Example
ⓘ
use truthlinked_sdk::abi;
// Compute selector for "transfer" function
let sel = abi::selector_of("transfer");
// Parse selector from calldata
let calldata = context::calldata()?;
let selector = abi::selector(&calldata)?;
// Read arguments
let amount = abi::read_u64(&calldata, 4)?;
let recipient = abi::read_account(&calldata, 12)?;Constants§
- ERR_
BAD_ CALLDATA - Error code for malformed or insufficient calldata.
Functions§
- read_
account - Reads a 32-byte account ID from calldata at the specified byte offset.
- read_
u64 - Reads a
u64value from calldata at the specified byte offset. - read_
u128 - Reads a
u128value from calldata at the specified byte offset. - selector
- Extracts the 4-byte function selector from calldata.
- selector_
of - Computes a 4-byte function selector from a function name.