referrerpolicy=no-referrer-when-downgrade

Crate sp_runtime_interface

Source
Expand description

Substrate runtime interface

This crate provides types, traits and macros around runtime interfaces. A runtime interface is a fixed interface between a Substrate runtime (also called the “guest”) and a Substrate node (also called the “host”). For a native runtime the interface maps to direct function calls of the implementation. For a non-native runtime the interface maps to an external function call. These external functions are exported by the runtime and they map to the same implementation as the native calls, just with some extra code to marshal them through the FFI boundary.

§Using a type in a runtime interface

Every argument type and return type must be wrapped in a marker newtype specifying the marshalling strategy used to pass the value through the FFI boundary between the host and the runtime. The only exceptions to this rule are a couple of basic, primitive types which can be passed directly through the FFI boundary and which don’t require any special handling besides a straightforward, direct conversion.

You can find the strategy wrapper types in the crate::pass_by module.

The newtype wrappers are automatically stripped away when the function is called and applied when the function returns by the runtime_interface macro.

§Declaring a runtime interface

Declaring a runtime interface is similar to declaring a trait in Rust:


#[sp_runtime_interface::runtime_interface]
trait RuntimeInterface {
    fn some_function(value: PassFatPointerAndRead<&[u8]>) -> bool {
        value.iter().all(|v| *v > 125)
    }
}

For more information on declaring a runtime interface, see #[runtime_interface].

Re-exports§

Modules§

  • Traits required by the runtime interface from the host side.
  • Provides host <-> runtime FFI marshalling strategy newtype wrappers for defining runtime interfaces.
  • Traits required by the runtime interface from the wasm side.

Traits§

  • Something that can be used by the runtime interface as type to communicate between the runtime and the host.

Functions§

Type Aliases§

  • A raw pointer that can be used in a runtime interface function signature.

Attribute Macros§

  • Attribute macro for transforming a trait declaration into a runtime interface.