wasm

package
v1.6.5-rc3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultImportsHandler = struct {
	ImportsSystem
	ImportsResource
	ImportsKVStore
	ImportsSQL
	ImportsChainOperation
	ImportsMQTT
	ImportsMetrics
	ImportsAsyncCall
}{
	ImportsSystem:         &DefaultImportsSystem{},
	ImportsResource:       &DefaultImportsResource{},
	ImportsKVStore:        &DefaultImportsKVStore{},
	ImportsSQL:            &DefaultImportsSQL{},
	ImportsChainOperation: &DefaultImportsChainOperation{},
	ImportsMQTT:           &DefaultImportsMQTT{},
	ImportsMetrics:        &DefaultImportsMetrics{},
	ImportsAsyncCall:      &DefaultImportsAsyncCall{},
}
View Source
var ErrNotImplements = errors.New("not implements")

Functions

This section is empty.

Types

type Config

type Config struct {
	ProjectID  string
	AppletID   string
	InstanceID string
}

type Context

type Context interface {
	Name() string

	GetImports() ImportsHandler
	SetImports(ImportsHandler)

	GetExports() Exports

	GetInstance() Instance
	SetInstance(Instance)
}

type DefaultImportsAsyncCall

type DefaultImportsAsyncCall struct{}

func (*DefaultImportsAsyncCall) AsyncAPICall

func (*DefaultImportsAsyncCall) AsyncAPICall(req []byte) ([]byte, error)

type DefaultImportsChainOperation

type DefaultImportsChainOperation struct{}

func (*DefaultImportsChainOperation) CallContract

func (*DefaultImportsChainOperation) CallContract(chainID int32, data []byte) ([]byte, error)

func (*DefaultImportsChainOperation) SendTX

func (*DefaultImportsChainOperation) SendTX(chainID int32, data []byte) (string, error)

func (*DefaultImportsChainOperation) SendTXWithOperator

func (*DefaultImportsChainOperation) SendTXWithOperator(chainID int32, data []byte) (string, error)

type DefaultImportsKVStore

type DefaultImportsKVStore struct{}

func (*DefaultImportsKVStore) GetKVData

func (*DefaultImportsKVStore) GetKVData(string) ([]byte, error)

func (*DefaultImportsKVStore) SetKVData

func (*DefaultImportsKVStore) SetKVData(string, []byte) error

type DefaultImportsMQTT

type DefaultImportsMQTT struct{}

func (*DefaultImportsMQTT) PubMQTT

func (*DefaultImportsMQTT) PubMQTT(topic string, message []byte) error

type DefaultImportsMetrics

type DefaultImportsMetrics struct{}

func (*DefaultImportsMetrics) SubmitMetrics

func (*DefaultImportsMetrics) SubmitMetrics(data []byte) error

type DefaultImportsResource

type DefaultImportsResource struct{}

func (*DefaultImportsResource) GetResourceData

func (v *DefaultImportsResource) GetResourceData(uint32) ([]byte, bool)

func (*DefaultImportsResource) SetResourceData

func (v *DefaultImportsResource) SetResourceData(uint32, []byte) error

type DefaultImportsSQL

type DefaultImportsSQL struct{}

func (*DefaultImportsSQL) ExecSQL

func (*DefaultImportsSQL) ExecSQL(string) error

func (*DefaultImportsSQL) QuerySQL

func (*DefaultImportsSQL) QuerySQL(string) ([]byte, error)

type DefaultImportsSystem

type DefaultImportsSystem struct{}

func (*DefaultImportsSystem) Env

func (l *DefaultImportsSystem) Env(key string) (string, bool)

func (*DefaultImportsSystem) Log

func (l *DefaultImportsSystem) Log(level consts.LogLevel, msg string)

func (*DefaultImportsSystem) LogInternal

func (l *DefaultImportsSystem) LogInternal(level consts.LogLevel, msg string)

type Exports

type Exports interface {
}

type Function

type Function interface {
	Call(args ...any) (any, error)
}

type ImportsAsyncCall

type ImportsAsyncCall interface {
	// AsyncAPICall call async api
	AsyncAPICall(req []byte) ([]byte, error)
}

type ImportsChainOperation

type ImportsChainOperation interface {
	// SendTX send tx by chain id and data, returns tx hash and error
	SendTX(chainID int32, data []byte) (string, error)
	// SendTXWithOperator
	SendTXWithOperator(chainID int32, data []byte) (string, error)
	// CallContract call contract by chain id and data, returns call result
	CallContract(chainID int32, data []byte) ([]byte, error)
}

type ImportsKVStore

type ImportsKVStore interface {
	// GetKVData read value by key from kv store
	GetKVData(key string) ([]byte, error)
	// SetKVData set value by key to kv store
	SetKVData(key string, data []byte) error
}

type ImportsMQTT

type ImportsMQTT interface {
	// PubMQTT publish mqtt message
	PubMQTT(topic string, message []byte) error
}

type ImportsMetrics

type ImportsMetrics interface {
	// SubmitMetrics submit metrics
	SubmitMetrics(data []byte) error
}

type ImportsResource

type ImportsResource interface {
	// GetResourceData get resource data by resource id
	GetResourceData(rid uint32) ([]byte, bool)
	// SetResourceData set resource data by resource id
	SetResourceData(rid uint32, data []byte) error
}

type ImportsSQL

type ImportsSQL interface {
	// ExecSQL exec sql query
	ExecSQL(q string) error
	// QuerySQL query data
	QuerySQL(q string) ([]byte, error)
}

type ImportsSystem

type ImportsSystem interface {
	// Log host log
	Log(level consts.LogLevel, msg string)
	// LogInternal host functions log
	LogInternal(level consts.LogLevel, msg string)
	// Env get env var by key
	Env(key string) (string, bool)
}

type Instance

type Instance interface {
	// RegisterImports
	RegisterImports(name string) error

	// Start starts wasm instance
	Start() error
	// Stop stops wasm instance
	Stop()

	// GetModule get current wasm module
	GetModule() Module
	// GetExportsFunc returns the exported func of the wasm instance by name
	GetExportsFunc(name string) (Function, error)
	// GetExportsMem returns the exported memory of the wasm instance
	GetExportsMem(name string) ([]byte, error)

	// GetByte returns the wasm byte from the specified addr
	GetByte(addr uint64) (byte, error)
	// PutByte set a wasm byte to specified addr
	PutByte(addr uint64, v byte) error
	// GetUint32 returns the u32 value from the specified addr
	GetUint32(addr uint64) (uint32, error)
	// PutUint32 sets u32 value to the specified addr
	PutUint32(addr uint64, v uint32) error
	// GetMemory returns wasm memory
	GetMemory(addr uint64, size uint64) ([]byte, error)
	// PutMemory
	PutMemory(addr uint64, size uint64, data []byte) error
	// Malloc allocates size of memory from wasm default memory
	Malloc(size int32) (uint64, error)

	// GetUserdata get user-defined data
	GetUserdata() any
	// SetUserdata set user-define data into wasm instance
	SetUserdata(any)
	// Lock gets the exclusive ownership of the wasm instance and sets userdata
	Lock(any)
	// Unlock releases the exclusive ownership of the wasm instance and unref userdata
	Unlock()

	// Acquire increases the refer count of wasm instance
	Acquire() bool
	// Release decreases the refer count of wasm instance
	Release()

	HandleError(error)
}

Instance defines the wasm instance

type Module

type Module interface {
	// Init was invoked when creating a wasm module
	Init()
	// NewInstance instantiates a wasm vm instance
	NewInstance() Instance
	// GetABINameList returns the abi name list exported from wasm module
	GetABINameList() []string
}

Module defines interface of the wasm module

type VM

type VM interface {
	// Name the name of the wasm vm
	Name() string
	// Init was invoked when creating a new wasm vm
	Init()
	// NewModule compile user code into a wasm module
	NewModule(code []byte) (Module, error)
	// Close to prevent from memory leaking
	Close() error
}

VM defines interface of the wasm virtual machine(engine)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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