Expand description

The environment-common crate contains three families of types:

  • The RawVal type, a 64-bit value type that is a union between several different types (numbers, booleans, symbols, object references), encoded via careful bit-packing.
  • Wrapper types (Object, Symbol, Status) that contain RawVal in a specific, known union state. These are also 64-bit values, but offer methods specific to the union state (eg. Symbol will interconvert with Rust strings).
  • The Env trait, which describes the interface between guest and host code. In other words, Env describes a set of host functions that must be implemented in a contract host, and can be called from a guest (or by the SDK). Methods on the Env trait can only pass 64-bit values, which are usually RawVal or one of the wrapper types.

The crate additionally contains functions for interconversion between the RawVal type and XDR types, and re-exports the XDR definitions from stellar_xdr under the module xdr.

Re-exports

Modules

  • 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.

Structs

  • Error type indicating a failure to convert some type to another; details of the failed conversion will typically be written to the debug log.
  • A 256-bit signed integer type.
  • Wrapper for a RawVal that is tagged with one of the object types, interpreting the RawVal’s body as containing a 32-bit object-code handle to a host object of the object-type.
  • ScValObject (and its reference-based type ScValObjRef) is a small wrapper type that does not have its own XDR definition, it just denotes (as a type) the subset of ScVal values that need to be represented in RawVal by one of the cases that can be an Object. In other words RawVal::try_from_val(&v, e).is_object() will be true iff ScValObject::classify(v) is Ok(ScValObject(v)).
  • Wrapper for a RawVal that is tagged with [Tag::Status], interpreting the RawVal’s body as a pair of a 28-bit status-type code and a 32-bit status code. The status-type codes correspond to the enumerated cases of ScStatusType, and the status codes correspond to the code values stored in each variant of the ScStatus union.
  • An iterator that decodes the individual bit-packed characters from a symbol and yields them as regular Rust char values.
  • An expanded form of a Symbol that stores its characters as ASCII-range bytes in a u8 array – up to the maximum size of a large symbol object – rather than as packed 6-bit codes within a u64. Useful for interoperation with standard Rust string types.
  • A 256-bit unsigned integer type.
  • A dummy implementation of the Env trait that fails with unimplemented!() in all functions. Useful for certain testing scenarios.
  • 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 VmCaller argument by &mut that may or may-not wrap a wasmi::Caller structure, depending on whether it was invoked from a wasmi host-function wrapper.

Enums

  • Errors related to operations on the SymbolObject and SymbolSmall types.
  • Code values for the 8 tag bits in the bit-packed representation of RawVal. 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

  • General trait representing the ability to compare two values of some type. Similar to core::cmp::Cmp but with two key differences: the comparison is fallible, and is provided by some external type implementing Compare rather than the compared type itself.
  • General trait representing a the ability of some object to perform a (possibly unsuccessful) conversion between two other types.
  • This trait represents the interface between Host and Guest, used by client contract code and implemented (via Env) by the host. It consists of functions that take or return only 64-bit values such as RawVal or u64.
  • Base trait extended by the Env trait, providing various special-case functions that do not simply call across cross the guest/host interface.
  • Trait abstracting over types that can be converted into RawVal, similar to TryFrom but with a different signature that enables generating slightly more efficient conversion code. An implementation of TryFrom<Val> is also provided for any type that implements ValConvertible.
  • This trait is a variant of the Env trait used to define the interface implemented by Host. The wasmi VM dispatch functions call methods on VmCallerEnv, passing a VmCaller that wraps the wasmi Caller context, and then convert any Result::Err(...) return value into a VM trap, halting VM execution.

Functions