wasm

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	WASM_BINDGEN_PLACEHOLDER_MODULE     = "__wbindgen_placeholder__"
	WASM_BINDGEN_EXTERNREF_XFORM_MODULE = "__wbindgen_externref_xform__"
)
View Source
const ClockType = "sf.substreams.v1.Clock"
View Source
const MaxLogByteCount = 128 * 1024 // 128 KiB

Variables

View Source
var ErrUnknownRuntimeExtension = errors.New("unknown wasm runtime extension")
View Source
var WASMBindgenModules = map[string]struct{}{
	WASM_BINDGEN_PLACEHOLDER_MODULE:     {},
	WASM_BINDGEN_EXTERNREF_XFORM_MODULE: {},
}

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) Active added in v1.6.0

func (b *BaseArgument) Active(blk uint64) bool

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) DoSetSumBigDecimal added in v1.7.0

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

func (*Call) DoSetSumBigInt added in v1.7.0

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

func (*Call) DoSetSumFloat64 added in v1.7.0

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

func (*Call) DoSetSumInt64 added in v1.7.0

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

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, initialBlock uint64) *MapInput

func (*MapInput) ProtoScopeValue added in v1.6.0

func (i *MapInput) ProtoScopeValue() string

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, wasmCode []byte, wasmCodeType string, 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, wasmCodeType string, registry *Registry) (module Module, err error)

func (ModuleFactoryFunc) NewModule added in v1.1.5

func (f ModuleFactoryFunc) NewModule(ctx context.Context, wasmCode []byte, wasmCodeType string, 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

func (*ParamsInput) ProtoScopeValue added in v1.6.0

func (i *ParamsInput) ProtoScopeValue() string

type ProtoScopeValueArgument added in v1.6.0

type ProtoScopeValueArgument interface {
	ProtoScopeValue() string
}

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 map[string]map[string]WASMExtension) *Registry

func NewRegistryWithRuntime added in v1.1.9

func NewRegistryWithRuntime(runtimeName string, extensions map[string]map[string]WASMExtension) *Registry

func (*Registry) InstanceCacheEnabled added in v1.1.5

func (r *Registry) InstanceCacheEnabled() bool

func (*Registry) NewModule added in v1.1.5

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

type RuntimeExtension added in v1.7.1

type RuntimeExtension struct {
	ID    RuntimeExtensionID
	Value *string
}

type RuntimeExtensionID added in v1.7.1

type RuntimeExtensionID string
const (
	RuntimeExtensionIDWASMBindgenShims RuntimeExtensionID = "wasm-bindgen-shims"
)

type RuntimeExtensions added in v1.7.1

type RuntimeExtensions []RuntimeExtension

func ParseRuntimeExtensions added in v1.7.1

func ParseRuntimeExtensions(expressions string) (extensions RuntimeExtensions, err error)

func ParseWASMCodeType added in v1.7.1

func ParseWASMCodeType(wasmCodeType string) (string, RuntimeExtensions, error)

func (RuntimeExtensions) Has added in v1.7.1

func (extensions RuntimeExtensions) Has(id RuntimeExtensionID) bool

type SourceInput added in v0.0.21

type SourceInput struct {
	BaseArgument
	BaseValueArgument
}

func NewSourceInput added in v0.0.21

func NewSourceInput(name string, initialBlock uint64) *SourceInput

func (*SourceInput) ProtoScopeValue added in v1.6.0

func (i *SourceInput) ProtoScopeValue() string

type StoreDeltaInput added in v0.0.21

type StoreDeltaInput struct {
	BaseArgument
	BaseValueArgument
}

func NewStoreDeltaInput added in v0.0.21

func NewStoreDeltaInput(name string, initialBlock uint64) *StoreDeltaInput

func (*StoreDeltaInput) ProtoScopeValue added in v1.6.0

func (i *StoreDeltaInput) ProtoScopeValue() string

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, initialBlock uint64) *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)
	Active(blk uint64) bool
}

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 {
	Params() map[string]string // tier1 gives me the params directly, tier2 would return nil
	WASMExtensions(map[string]string) (map[string]map[string]WASMExtension, error)
}

Directories

Path Synopsis
substreams_wasi_go/pb/google/protobuf
Package timestamppb contains generated types for google/protobuf/timestamp.proto.
Package timestamppb contains generated types for google/protobuf/timestamp.proto.
fs

Jump to

Keyboard shortcuts

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