wasm

package
v0.0.5-beta3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2022 License: Apache-2.0 Imports: 10 Imported by: 4

README

Simple WASM runtime for substreams

Install wasm-pack from:

Run tests with:

go generate && go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Params

func Params(kinds ...wasmer.ValueKind) []*wasmer.ValueType

func Returns

func Returns(kinds ...wasmer.ValueKind) []*wasmer.ValueType

Types

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

func NewHeap

func NewHeap(memory *wasmer.Memory, allocator wasmer.NativeFunction) *Heap

func (*Heap) PrintMem

func (h *Heap) PrintMem()

func (*Heap) ReadBytes

func (h *Heap) ReadBytes(offset int32, length int32) ([]byte, error)

func (*Heap) ReadString

func (h *Heap) ReadString(offset int32, length int32) (string, error)

func (*Heap) Write

func (h *Heap) Write(bytes []byte) (int32, error)

func (*Heap) WriteAtPtr

func (h *Heap) WriteAtPtr(bytes []byte, ptr int32) (int32, error)

type Input

type Input struct {
	Type InputType
	Name string

	// Transient data between calls
	StreamData []byte

	// InputType == InputStore || OutputStore
	Store  *state.Builder
	Deltas bool // whether we want to have the Deltas instead of an access to the store

	// If InputType == OutputStore
	UpdatePolicy pbsubstreams.Module_KindStore_UpdatePolicy
	ValueType    string
}

type InputType

type InputType int
const (
	InputSource InputType = iota
	InputStore
	OutputStore
)

type Instance

type Instance struct {
	Logs []string
	// contains filtered or unexported fields
}

func (*Instance) Err

func (i *Instance) Err() error

func (*Instance) Execute

func (i *Instance) Execute() (err error)

func (*Instance) ExecuteWithArgs

func (i *Instance) ExecuteWithArgs(args ...interface{}) (err error)

func (*Instance) Heap

func (i *Instance) Heap() *Heap

func (*Instance) Output

func (i *Instance) Output() []byte

func (*Instance) PrintStats

func (i *Instance) PrintStats()

func (*Instance) SetOutputStore

func (i *Instance) SetOutputStore(store *state.Builder)

func (*Instance) Store

func (i *Instance) Store() *wasmer.Store

func (*Instance) WriteOutputToHeap

func (i *Instance) WriteOutputToHeap(outputPtr int32, value []byte) error

type Module

type Module struct {
	CurrentInstance *Instance
	// contains filtered or unexported fields
}

func (*Module) NewInstance

func (m *Module) NewInstance(clock *pbsubstreams.Clock, functionName string, inputs []*Input) (*Instance, error)

type PanicError

type PanicError struct {
	// contains filtered or unexported fields
}

func (*PanicError) Error

func (e *PanicError) Error() string

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

func NewRuntime

func NewRuntime(extensions []WASMExtensioner) *Runtime

func (*Runtime) NewModule

func (r *Runtime) NewModule(ctx context.Context, request *pbsubstreams.Request, wasmCode []byte, name string) (*Module, error)

type WASMExtension

type WASMExtension func(ctx context.Context, request *pbsubstreams.Request, clock *pbsubstreams.Clock, in []byte) (out []byte, err error)

WASMExtension defines the implementation of a function that will be exposed as wasm imports; therefore, exposed to the host language like Rust.

For example, this can be an RPC call, taking a structured request in `in` and outputting a structured response in `out`, both serialized as protobuf messages.

Such a function needs to be registered through RegisterRuntime.

type WASMExtensioner

type WASMExtensioner interface {
	WASMExtensions() map[string]map[string]WASMExtension
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL