Expand description
This crate mainly exists to provide the Soroban Host type, which is the implementation of the Env interface between guest contract code and the host it runs within.
This crate also re-exports all of the content of the soroban_env_common crate for use by host (or contract local-testing) code. Most of the type and module definitions visible here are actually defined in the common crate.
When unit-testing contracts natively (not using wasm), developers may also
wish to enable the "testutils" feature, which enables an interface on
Host for registering other test contracts by ID.
The Host type provides some facilities above and beyond just the Env trait, including:
Re-exports§
pub use vm::Vm;pub use budget::DEFAULT_HOST_DEPTH_LIMIT;pub use budget::DEFAULT_XDR_RW_LIMITS;pub use ledger_info::LedgerInfo;
Modules§
- Auth conceptual overview
- This module contains version constants (and other metadata) that are embedded in binaries (especially WASM binaries) compiled against a particular version of this crate. Versioning at this level provides an early diagnostic check for compatibility between a loaded WASM binary and the Env interface provided by the host, rather than a cryptic failure due to a runtime host function signature mismatch.
Macros§
- Helper for building multi-argument errors. For example:
Structs§
- Error type indicating a failure to convert some type to another; details of the failed conversion may be written to the debug log, when possible.
- Wrapper for a Val that is tagged with [Tag::Error], interpreting the Val’s body as a pair of a 28-bit error-type code and a 32-bit error code. The error-type codes correspond to the enumerated cases of ScErrorType, and the error codes correspond to the code values stored in each variant of the ScError union.
- A 256-bit signed integer type.
ScValObject(and its reference-based typeScValObjRef) is a small wrapper type that does not have its own XDR definition, it just denotes (as a type) the subset ofScValvalues that need to be represented inValby one of the cases that can be anObject. In other wordsVal::try_from_val(&v, e).is_object()will be true iffScValObject::classify(v)isOk(ScValObject(v)).- An iterator that decodes the individual bit-packed characters from a symbol and yields them as regular Rust char values.
- A 256-bit unsigned integer type.
- The VmCallerEnv trait is similar to the Env trait – it provides all the same-named methods – but they have a form that takes an initial
VmCallerargument by&mutthat may or may-not wrap awasmi::Callerstructure, depending on whether it was invoked from a wasmi host-function wrapper.
Enums§
- This is just a distinct enum local to the env interface that is used as an argument to storage functions. It doesn’t correspond to any [
Val] types, and is passed by direct marshalling as a u64. - Errors related to operations on the SymbolObject and SymbolSmall types.
- Code values for the 8
tagbits in the bit-packed representation of Val. These don’t coincide with tag numbers in the SCVal XDR but cover all those cases as well as some optimized refinements for special cases (boolean true and false, small-value forms).
Constants§
Traits§
- This trait is used by macro-generated dispatch and forwarding functions to check arguments being passed to the Env. The default implementations call through to the Env integrity-checking functions.
- General trait representing the ability to compare two values of some type. Similar to
core::cmp::Cmpbut with two key differences: the comparison is fallible, and is provided by some external type implementingComparerather than the compared type itself. - General trait representing a the ability of some object to perform a (possibly unsuccessful) conversion between two other types.
- Base trait extended by the Env trait, providing various special-case functions that do not simply call across cross the guest/host interface.
- Trait for types that can be fallibly converted to another type
V, analogous to the standard Rust typeTryFrom, but making use of the providedEnvimplementationEin order to convert parts of the type that require it. Mainly this exists becauseValtypes that contain object handles need to delegate to the environment to look up and extract the content of those handles. - The opposite trait to
TryFromVal, analogous to the way thatTryIntoexists as an opposite toTryFrom. Exists only for convenience of doing conversions via.try_into_val(e)or specifying convertability with a bound likeTryIntoVal<E,Other>. - This trait is a variant of the Env trait used to define the interface implemented by Host. The wasmi VM dispatch functions (in soroban_env_host::dispatch) call methods on
VmCallerEnv, passing aVmCallerthat wraps the wasmi Caller context, and then convert anyResult::Err(...)return value into a VM trap, halting VM execution.