types

package
v1.6.5-rc48 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

This section is empty.

Types

type Context

type Context interface {
	Name() string

	GetImports() ImportsHandler
	SetImports(ImportsHandler)

	GetExports() Exports

	GetInstance() Instance
	SetInstance(Instance)

	OnCreated(Instance)
	OnDestroy(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 uint32, data []byte) ([]byte, error)

func (*DefaultImportsChainOperation) SendTX

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

func (*DefaultImportsChainOperation) SendTXWithOperator

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

type DefaultImportsContext

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

func NewDefaultImportsContext

func NewDefaultImportsContext() *DefaultImportsContext

func (*DefaultImportsContext) ContextID

func (c *DefaultImportsContext) ContextID() string

func (*DefaultImportsContext) Entry

func (c *DefaultImportsContext) Entry(cid string) bool

func (*DefaultImportsContext) Leave

func (c *DefaultImportsContext) Leave(cid string) bool

type DefaultImportsEventType

type DefaultImportsEventType struct {
}

func (*DefaultImportsEventType) GetEventType

func (v *DefaultImportsEventType) GetEventType(uint32) (string, bool)

func (*DefaultImportsEventType) RemoveEventType

func (v *DefaultImportsEventType) RemoveEventType(uint32)

func (*DefaultImportsEventType) SetEventType

func (v *DefaultImportsEventType) SetEventType(uint32, 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) RemoveResourceData

func (v *DefaultImportsResource) RemoveResourceData(uint32)

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 {
	// contains filtered or unexported fields
}

func (*DefaultImportsSystem) Abort

func (l *DefaultImportsSystem) Abort(msg, filename string, line, col int32)

func (*DefaultImportsSystem) Env

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

func (*DefaultImportsSystem) FlushLog

func (l *DefaultImportsSystem) FlushLog()

func (*DefaultImportsSystem) Log

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

func (*DefaultImportsSystem) LogInternal

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

func (*DefaultImportsSystem) Seed

func (l *DefaultImportsSystem) Seed() float64

func (*DefaultImportsSystem) Trace

func (l *DefaultImportsSystem) Trace(msg string, trace string)

type Exports

type Exports interface {
	// OnEventReceived pass data to wasm to handle event
	// entry wasm entry
	// typ event type
	// data payload
	OnEventReceived(entry string, typ string, data []byte) (interface{}, uint64, error)
}

type Function

type Function interface {
	Call(args ...any) (any, error)
	Params() []string
	Results() []string
}

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 uint32, data []byte) (string, error)
	// SendTXWithOperator
	SendTXWithOperator(chainID uint32, data []byte) (string, error)
	// CallContract call contract by chain id and data, returns call result
	CallContract(chainID uint32, data []byte) ([]byte, error)
}

type ImportsContext

type ImportsContext interface {
	Entry(contextID string) bool
	Leave(contextID string) bool
	ContextID() string
}

type ImportsEventType

type ImportsEventType interface {
	// GetEventType get event type by resource id
	GetEventType(rid uint32) (string, bool)
	// SetEventType set event type by resource id
	SetEventType(rid uint32, typ string) error
	// RemoveEventType remove event type by resource id
	RemoveEventType(rid uint32)
}

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
	// RemoveResourceData remove resource data by resource id
	RemoveResourceData(rid uint32)
}

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
	LogInternal(level consts.LogLevel, msg string, args ...any)
	// FlushLog
	FlushLog()
	// Env get env var by key
	Env(key string) (string, bool)
	// Abort
	Abort(msg, filename string, line, col int32)
	// Trace is reserved for imported func env.trace() which is auto-generated by assembly-script
	Trace(msg string, trace string)
	// Seed is reserved for imported func env.seed() which is auto-generated by assembly-script
	Seed() float64
}

type Instance

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

	// Start starts wasm instance
	Start() error
	// Stop stops wasm instance
	Stop()
	// Started returns if instance is started
	Started() bool

	// 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 int32) (byte, error)
	// PutByte set a wasm byte to specified addr
	PutByte(addr int32, v byte) error
	// GetUint32 returns the u32 value from the specified addr
	GetUint32(addr int32) (uint32, error)
	// PutUint32 sets u32 value to the specified addr
	PutUint32(addr int32, v uint32) error
	// GetMemory returns wasm memory
	GetMemory(addr int32, size int32) ([]byte, error)
	// PutMemory
	PutMemory(addr int32, size int32, data []byte) error
	// Malloc allocates size of memory from wasm default memory
	Malloc(size int32) (int32, 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()

	// Call wasm function with name and args, returns wasm return value, fuel consumed, and error
	Call(string, ...interface{}) (interface{}, uint64, error)

	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 {
	ID() string
	// 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)

Jump to

Keyboard shortcuts

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