wasm

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const ClockType = "sf.substreams.v1.Clock"
View Source
const MaxLogByteCount = 128 * 1024 // 128 KiB

Variables

This section is empty.

Functions

func RegisterModuleFactory added in v1.1.5

func RegisterModuleFactory(name string, factory ModuleFactory)

func WithContext added in v1.1.5

func WithContext(ctx context.Context, call *Call) context.Context

Types

type Argument added in v0.0.21

type Argument interface {
	Name() string
}

type BaseArgument added in v0.0.21

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

func (*BaseArgument) Name added in v0.0.21

func (b *BaseArgument) Name() string

type BaseValueArgument added in v0.0.21

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

func (*BaseValueArgument) SetValue added in v0.0.21

func (b *BaseValueArgument) SetValue(data []byte)

func (*BaseValueArgument) Value added in v0.0.21

func (b *BaseValueArgument) Value() []byte

type Call added in v1.1.1

type Call struct {
	Clock      *pbsubstreams.Clock // Used by WASM extensions
	ModuleName string
	Entrypoint string

	Logs           []string
	LogsByteCount  uint64
	ExecutionStack []string
	// contains filtered or unexported fields
}

func FromContext added in v1.1.5

func FromContext(ctx context.Context) *Call

func NewCall added in v1.1.5

func NewCall(clock *pbsubstreams.Clock, moduleName string, entrypoint string, stats *metrics.Stats, arguments []Argument) *Call

func (*Call) AppendLog added in v1.1.5

func (c *Call) AppendLog(message string)

func (*Call) DoAddBigDecimal added in v1.1.5

func (c *Call) DoAddBigDecimal(ord uint64, key string, value string)

func (*Call) DoAddBigInt added in v1.1.5

func (c *Call) DoAddBigInt(ord uint64, key string, value string)

func (*Call) DoAddFloat64 added in v1.1.5

func (c *Call) DoAddFloat64(ord uint64, key string, value float64)

func (*Call) DoAddInt64 added in v1.1.5

func (c *Call) DoAddInt64(ord uint64, key string, value int64)

func (*Call) DoAppend added in v1.1.5

func (c *Call) DoAppend(ord uint64, key string, value []byte)

func (*Call) DoDeletePrefix added in v1.1.5

func (c *Call) DoDeletePrefix(ord uint64, prefix string)

func (*Call) DoGetAt added in v1.1.5

func (c *Call) DoGetAt(storeIndex int, ord uint64, key string) (value []byte, found bool)

func (*Call) DoGetFirst added in v1.1.5

func (c *Call) DoGetFirst(storeIndex int, key string) (value []byte, found bool)

func (*Call) DoGetLast added in v1.1.5

func (c *Call) DoGetLast(storeIndex int, key string) (value []byte, found bool)

func (*Call) DoHasAt added in v1.1.5

func (c *Call) DoHasAt(storeIndex int, ord uint64, key string) (found bool)

func (*Call) DoHasFirst added in v1.1.5

func (c *Call) DoHasFirst(storeIndex int, key string) (found bool)

func (*Call) DoHasLast added in v1.1.5

func (c *Call) DoHasLast(storeIndex int, key string) (found bool)

func (*Call) DoSet added in v1.1.5

func (c *Call) DoSet(ord uint64, key string, value []byte)

func (*Call) DoSetIfNotExists added in v1.1.5

func (c *Call) DoSetIfNotExists(ord uint64, key string, value []byte)

func (*Call) DoSetMaxBigDecimal added in v1.1.5

func (c *Call) DoSetMaxBigDecimal(ord uint64, key string, value string)

func (*Call) DoSetMaxBigInt added in v1.1.5

func (c *Call) DoSetMaxBigInt(ord uint64, key string, value string)

func (*Call) DoSetMaxFloat64 added in v1.1.5

func (c *Call) DoSetMaxFloat64(ord uint64, key string, value float64)

func (*Call) DoSetMaxInt64 added in v1.1.5

func (c *Call) DoSetMaxInt64(ord uint64, key string, value int64)

func (*Call) DoSetMinBigDecimal added in v1.1.5

func (c *Call) DoSetMinBigDecimal(ord uint64, key string, value string)

func (*Call) DoSetMinBigInt added in v1.1.5

func (c *Call) DoSetMinBigInt(ord uint64, key string, value string)

func (*Call) DoSetMinFloat64 added in v1.1.5

func (c *Call) DoSetMinFloat64(ord uint64, key string, value float64)

func (*Call) DoSetMinInt64 added in v1.1.5

func (c *Call) DoSetMinInt64(ord uint64, key string, value int64)

func (*Call) Err added in v1.1.1

func (c *Call) Err() error

func (*Call) Output added in v1.1.1

func (c *Call) Output() []byte

func (*Call) ReachedLogsMaxByteCount added in v1.1.1

func (c *Call) ReachedLogsMaxByteCount() bool

func (*Call) ReturnError added in v1.1.5

func (c *Call) ReturnError(err error)

func (*Call) SetOutputStore added in v1.1.1

func (c *Call) SetOutputStore(store store.Store)

func (*Call) SetPanicError added in v1.1.5

func (c *Call) SetPanicError(message string, filename string, lineNo int, colNo int)

func (*Call) SetReturnValue added in v1.1.5

func (c *Call) SetReturnValue(msg []byte)

type InputType

type InputType int

type Instance

type Instance interface {
	// Cleanup is called between each calls, for lightweight clean-up (remove allocation)
	// in case we're not using a fully deterministic execution strategy.
	Cleanup(ctx context.Context) error

	// Close is called once we know we won't be reusing this instance, and it can be
	// freed from memory.  When using cached instances, this won't be called between
	// each execution, but only at the end of a user's request.
	Close(ctx context.Context) error
}

An Instance lives for the duration of an execution (with instance caching disabled) // or a series of execution (when instance caching is enabled).

type MapInput added in v0.0.21

type MapInput struct {
	BaseArgument
	BaseValueArgument
}

func NewMapInput added in v0.0.21

func NewMapInput(name string) *MapInput

type Module

type Module interface {
	// NewInstance can be used to create up-front a new instance, which will be
	// cached and reused for the duration execution of ExecuteNewCall.
	NewInstance(ctx context.Context) (instance Instance, err error)

	// ExecuteNewCall is called once per module execution for each block.
	// If caching is enabled, the returned Instance will be saved and passed in
	// as the `cachedInstance` argument upon the next call. In which case, the runtime
	// would benefit from using it back. It is the runtime's responsibility to determine
	// whether this caching entails risks to determinism (leaking of global state for instance).
	ExecuteNewCall(ctx context.Context, call *Call, cachedInstance Instance, arguments []Argument) (instance Instance, err error)

	// Close gets called when the module can be unloaded at the end of a user's request.
	Close(ctx context.Context) error
}

A Module is a cached or pre-compiled version able to generate new isolated instances, and execute calls on them. It lives for the duration of a stream.

type ModuleFactory added in v1.1.5

type ModuleFactory interface {
	NewModule(ctx context.Context, code []byte, registry *Registry) (module Module, err error)
}

WASM VM specific implementation to create a new Module, which is an abstraction around a runtime and pre-compiled WASM modules.

type ModuleFactoryFunc added in v1.1.5

type ModuleFactoryFunc func(ctx context.Context, wasmCode []byte, registry *Registry) (module Module, err error)

func (ModuleFactoryFunc) NewModule added in v1.1.5

func (f ModuleFactoryFunc) NewModule(ctx context.Context, wasmCode []byte, registry *Registry) (module Module, err error)

type PanicError

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

func NewPanicError added in v1.1.5

func NewPanicError(message, filename string, lineNumber, columnNumber int) *PanicError

func (*PanicError) Error

func (e *PanicError) Error() string

type ParamsInput added in v1.0.0

type ParamsInput struct {
	BaseArgument
	BaseValueArgument
}

func NewParamsInput added in v1.0.0

func NewParamsInput(value string) *ParamsInput

type Registry added in v1.1.5

type Registry struct {
	Extensions map[string]map[string]WASMExtension
	// contains filtered or unexported fields
}

Registry from Substreams's perspective is a singleton that is reused across requests, from which we instantiate Modules (wasm code provided by the users) and from which we instantiate Instances (one for each executions within each blocks).

func NewRegistry added in v1.1.5

func NewRegistry(extensions []WASMExtensioner, maxFuel uint64) *Registry

func NewRegistryWithRuntime added in v1.1.9

func NewRegistryWithRuntime(runtimeName string, extensions []WASMExtensioner, maxFuel uint64) *Registry

func (*Registry) InstanceCacheEnabled added in v1.1.5

func (r *Registry) InstanceCacheEnabled() bool

func (*Registry) MaxFuel added in v1.1.5

func (r *Registry) MaxFuel() uint64

func (*Registry) NewModule added in v1.1.5

func (r *Registry) NewModule(ctx context.Context, wasmCode []byte) (Module, error)

type SourceInput added in v0.0.21

type SourceInput struct {
	BaseArgument
	BaseValueArgument
}

func NewSourceInput added in v0.0.21

func NewSourceInput(name string) *SourceInput

type StoreDeltaInput added in v0.0.21

type StoreDeltaInput struct {
	BaseArgument
	BaseValueArgument
}

func NewStoreDeltaInput added in v0.0.21

func NewStoreDeltaInput(name string) *StoreDeltaInput

type StoreReaderInput added in v0.0.21

type StoreReaderInput struct {
	BaseArgument
	Store store.Store
}

func NewStoreReaderInput added in v0.0.21

func NewStoreReaderInput(name string, store store.Store) *StoreReaderInput

type StoreWriterOutput added in v0.0.21

type StoreWriterOutput struct {
	BaseArgument
	Store        store.Store
	UpdatePolicy pbsubstreams.Module_KindStore_UpdatePolicy
	ValueType    string
}

func NewStoreWriterOutput added in v0.0.21

func NewStoreWriterOutput(name string, store store.Store, updatePolicy pbsubstreams.Module_KindStore_UpdatePolicy, valueType string) *StoreWriterOutput

type ValueArgument added in v0.0.21

type ValueArgument interface {
	Argument
	Value() []byte
	SetValue([]byte)
}

type WASMExtension

type WASMExtension func(ctx context.Context, requestID string, 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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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