Module rings_node::backend::extension
source · 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:
-
It should have a function with the signature fn handler(param: ExternRef) -> ExternRef, and this function should be exported.
-
The Wasm module should not have any external imports, except for the helper functions defined by the Rings network.
-
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
- Manager of Extension
- Configure for Extension
- Wrapper for BackendMessage that can be converted from and to the native WebAssembly type.
Enums
- Path of a wasm extension
Traits
- Calls the extension handler with the given message and returns the response.