wvm

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABTypesFactory

type ABTypesFactory struct{}

AB "common types", ie not tx system specific stuff

type Encoder

type Encoder interface {
	Encode(obj any, ver uint32, getHandle func(obj any) uint64) ([]byte, error)
	TxAttributes(txo *types.TransactionOrder, ver uint32) ([]byte, error)
	UnitData(unit *state.Unit, ver uint32) ([]byte, error)
}

translates AB types to WASM consumable representation

type EvalEnvironment

type EvalEnvironment interface {
	GetUnit(id types.UnitID, committed bool) (*state.Unit, error)
	CurrentRound() uint64
	TrustBase(epoch uint64) (types.RootTrustBase, error)
	GasAvailable() uint64
	SpendGas(gas uint64) error
	CalculateCost() uint64
	TransactionOrder() (*types.TransactionOrder, error)
}

type EvalResult

type EvalResult int
const (
	EvalResultTrue  EvalResult = 1
	EvalResultFalse EvalResult = 2
	EvalResultError EvalResult = 3
)

func PredicateEvalResult

func PredicateEvalResult(code uint64) (EvalResult, uint64)

type Observability

type Observability interface {
	//Tracer(name string, options ...trace.TracerOption) trace.Tracer
	//Meter(name string, opts ...metric.MeterOption) metric.Meter
	Logger() *slog.Logger
}

type Option

type Option func(*Options)

func WithRuntimeConfig

func WithRuntimeConfig(cfg wazero.RuntimeConfig) Option

func WithStorage

func WithStorage(db keyvaluedb.KeyValueDB) Option

type Options

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

type WasmVM

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

func New

func New(ctx context.Context, enc Encoder, engines predicates.PredicateExecutor, observe Observability, opts ...Option) (*WasmVM, error)

New - creates new wazero based wasm vm

func (*WasmVM) Close

func (vm *WasmVM) Close(ctx context.Context) error

func (*WasmVM) Exec

func (vm *WasmVM) Exec(ctx context.Context, predicate, args []byte, conf wasm.PredicateParams, sigBytesFn func() ([]byte, error), env EvalEnvironment) (uint64, error)

Exec loads the WASM module passed in as "predicate" argument and calls the "conf.Entrypoint" function in it.

  • The entrypoint function signature must be "no parameters and single i64 return value" where zero means "true" and non-zero is "false" (ie the returned number is error code);

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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