#val #environment #env #object #host #interface #contract

no-std soroban-env-common

Soroban contract environment common types and functionality

26 releases (stable)

new 22.1.0 Nov 18, 2024
22.0.0-rc.3 Oct 22, 2024
21.2.2 Oct 24, 2024
21.2.0 Jul 16, 2024
0.0.3 Jul 29, 2022

#259 in Magic Beans

Download history 3983/week @ 2024-07-30 2184/week @ 2024-08-06 1804/week @ 2024-08-13 2880/week @ 2024-08-20 3457/week @ 2024-08-27 2089/week @ 2024-09-03 2433/week @ 2024-09-10 1948/week @ 2024-09-17 2515/week @ 2024-09-24 2735/week @ 2024-10-01 2589/week @ 2024-10-08 1687/week @ 2024-10-15 2358/week @ 2024-10-22 2961/week @ 2024-10-29 4031/week @ 2024-11-05 4145/week @ 2024-11-12

13,843 downloads per month
Used in 64 crates (4 directly)

Apache-2.0

195KB
4K SLoC

rs-soroban-env

Rust contract-environment interface and (optional) host implementation for Soroban.

The soroban-env-common crate contains elements of the shared environment-interface between smart contract guest and host: the Env trait that defines the set of available environment functions as well as the Val type that can pass back and forth through the WASM calling convention. Additionally small wrappers around subtypes of Val are included: Object, Symbol, Error, etc.

The soroban-env-guest crate contains the guest-side stub implementation of the environment interface called Guest dependent on extern fns provided by the host implementation. This can be used in a WASM runtime that provides the extern fns.

The soroban-env-host crate contains the host-side full implementation of the environment interface called Host. This can be used either in the real blockchain host, or for local testing in the SDK.


lib.rs:

The environment-common crate contains three families of types:

  • The [Val] 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], [Error]) that contain [Val] 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 string types).
  • 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 [Val] or one of the wrapper types.

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

Dependencies

~6–33MB
~522K SLoC