Expand description

This module supports a user-defined message handler based on WebAssembly (Wasm). The Rings network allows loading a Wasm or Wat file from a remote or local file and transforming it into a message handler. The Wasm module should satisfy the following requirements:

  1. It should have a function with the signature fn handler(param: ExternRef) -> ExternRef, and this function should be exported.

  2. The Wasm module should not have any external imports, except for the helper functions defined by the Rings network.

  3. Only the helper functions defined by the Rings network can be used, which include:

    "message_abi" => {
        "message_type"  => msg_type,
        "extra" => extra,
        "data" => data,
        "read_at" => read_at,
        "write_at" => write_at
    }

A basic wasm extension may looks like:

(module
 ;; Let's import message_type from message_abi
 (type $ty_message_type (func (param externref) (result i32)))
 (import "message_abi" "message_type" (func $message_type (type $ty_message_type)))
  ;; fn handler(param: ExternRef) -> ExternRef
 (func $handler  (param externref) (result externref)
     (return (local.get 0))
 )
 (export "handler" (func $handler))
)

You can see that this wat/wasm extension defines a handler function and
imports the message_type ABI.

Modules

  • Loader of wasm, including ABI generator

Structs

Enums

  • Path of a wasm extension

Traits