pub unsafe extern "C" fn tx_handler_execute(
args: &mut InternalArgs<'_>,
) -> ExitCodeExpand description
FFI interface into a method, called by the host.
NOTE: Calling this function directly shouldn’t be necessary except maybe in contract’s own tests.
Contents of #[input] and #[output] arguments are parsed, the exit code of
ContractError::BadInput is returned if they are not valid values of their
types.
§Safety
Caller must ensure the provided pointer corresponds to the expected ABI.
Sizes, capacities and alignment of inputs and outputs match the method’s
metadata, which the executor guarantees (the RISC-V VM checks them, the
native executor trusts callers and only catches mismatches with debug
assertions): pointers are aligned for the IoType::PointerType of their
types, and sizes and capacities are valid for their types, as
IoType::try_from_ptr() requires for inputs and IoType::try_from_mut_ptr()
for outputs. The pointer of an input is valid for reads of its size, with that
many bytes initialized and not written to during the call. The pointer of an
output is valid for writes of its capacity and for reads of its size, with that
many bytes initialized, and the memory is not accessed other than through this
pointer during the call.
The state, #[tmp] and #[slot] arguments are not parsed: their pointers
are aligned and point to valid values of their types with valid sizes and
capacities, accessed like inputs if they are read-only and like outputs
otherwise.
The Env behind #[env] (if present) is created as
Env::with_executor_context() requires for an Env given to code by reference,
or by the host in guest builds. The method gets it with a lifetime that only
covers the call. For that lifetime, it can borrow its #[output]s other than
the state and lend them to calls (see Env::lend_output()), which can leave
contents behind that are not valid values. Hence, after the call, the contents
of outputs must not be accessed as values of their types without being parsed
first, unless every bit pattern is a valid value. OutputArg ensures this for
callers of extension methods. The exception is the last #[output] of #[init]
without a return value, which is the initial state. The method can’t lend it
with Env::lend_output(), since #[contract] rejects a named lifetime on it,
so after a successful call it is either empty or holds a valid value of the
state.