Documentation ¶
Index ¶
- Constants
- Variables
- func Connect(h wasmlib.ScHost) wasmlib.ScHost
- func GetProcessor(wasmBytes []byte, log *logger.Logger) (isc.VMProcessor, error)
- type ISandbox
- type ScOnloadFunc
- type WasmContext
- func (wc *WasmContext) Call(ctx interface{}) dict.Dict
- func (wc *WasmContext) ExportName(index int32, name string)
- func (wc *WasmContext) FunctionFromCode(code uint32) string
- func (wc *WasmContext) GasBudget() uint64
- func (wc *WasmContext) GasBurned(burned uint64)
- func (wc *WasmContext) GasDisable(disable bool)
- func (wc *WasmContext) IsView() bool
- func (wc *WasmContext) RunScFunction(functionName string) (err error)
- func (wc *WasmContext) Sandbox(funcNr int32, params []byte) []byte
- func (wc *WasmContext) StateDelete(key []byte)
- func (wc *WasmContext) StateExists(key []byte) bool
- func (wc *WasmContext) StateGet(key []byte) []byte
- func (wc *WasmContext) StateSet(key, value []byte)
- type WasmContextSandbox
- type WasmConvertor
- func (cvt WasmConvertor) IscAddress(scAddress *wasmtypes.ScAddress) iotago.Address
- func (cvt WasmConvertor) IscAgentID(scAgentID *wasmtypes.ScAgentID) isc.AgentID
- func (cvt WasmConvertor) IscAllowance(assets *wasmlib.ScAssets) *isc.Assets
- func (cvt WasmConvertor) IscBigInt(amount wasmtypes.ScBigInt) *big.Int
- func (cvt WasmConvertor) IscChainID(chainID *wasmtypes.ScChainID) isc.ChainID
- func (cvt WasmConvertor) IscHash(hash *wasmtypes.ScHash) *hashing.HashValue
- func (cvt WasmConvertor) IscHname(hname wasmtypes.ScHname) isc.Hname
- func (cvt WasmConvertor) IscNFTID(nftID *wasmtypes.ScNftID) *iotago.NFTID
- func (cvt WasmConvertor) IscRequestID(requestID *wasmtypes.ScRequestID) isc.RequestID
- func (cvt WasmConvertor) IscTokenID(tokenID *wasmtypes.ScTokenID) iotago.NativeTokenID
- func (cvt WasmConvertor) ScAddress(address iotago.Address) wasmtypes.ScAddress
- func (cvt WasmConvertor) ScAgentID(agentID isc.AgentID) wasmtypes.ScAgentID
- func (cvt WasmConvertor) ScBalances(allowance *isc.Assets) *wasmlib.ScBalances
- func (cvt WasmConvertor) ScBigInt(bigInt *big.Int) wasmtypes.ScBigInt
- func (cvt WasmConvertor) ScChainID(chainID isc.ChainID) wasmtypes.ScChainID
- func (cvt WasmConvertor) ScHash(hash hashing.HashValue) wasmtypes.ScHash
- func (cvt WasmConvertor) ScHname(hname isc.Hname) wasmtypes.ScHname
- func (cvt WasmConvertor) ScNftID(nftID *iotago.NFTID) wasmtypes.ScNftID
- func (cvt WasmConvertor) ScRequestID(requestID isc.RequestID) wasmtypes.ScRequestID
- func (cvt WasmConvertor) ScTokenID(nativeTokenID iotago.NativeTokenID) wasmtypes.ScTokenID
- func (cvt WasmConvertor) ToBigInt(amount interface{}) *big.Int
- type WasmFuncTable
- type WasmGoVM
- func (vm *WasmGoVM) Interrupt()
- func (vm *WasmGoVM) LoadWasm(wasmData []byte) error
- func (vm *WasmGoVM) NewInstance(wc *WasmContext) WasmVM
- func (vm *WasmGoVM) RunFunction(functionName string, args ...interface{}) error
- func (vm *WasmGoVM) RunScFunction(index int32) (err error)
- func (vm *WasmGoVM) UnsafeMemory() []byte
- type WasmProcessor
- func (proc *WasmProcessor) Entrypoints() map[isc.Hname]isc.ProcessorEntryPoint
- func (proc *WasmProcessor) GetCurrentContext() *WasmContext
- func (proc *WasmProcessor) GetDefaultEntryPoint() isc.VMProcessorEntryPoint
- func (proc *WasmProcessor) GetDescription() string
- func (proc *WasmProcessor) GetEntryPoint(code isc.Hname) (isc.VMProcessorEntryPoint, bool)
- func (proc *WasmProcessor) IsView(function string) bool
- func (proc *WasmProcessor) RegisterContext(wc *WasmContext)
- func (proc *WasmProcessor) UnregisterContext(wc *WasmContext)
- type WasmTimeVM
- func (vm *WasmTimeVM) GasBudget(budget uint64)
- func (vm *WasmTimeVM) GasBurned() uint64
- func (vm *WasmTimeVM) Interrupt()
- func (vm *WasmTimeVM) LinkHost() (err error)
- func (vm *WasmTimeVM) LoadWasm(wasmData []byte) (err error)
- func (vm *WasmTimeVM) NewInstance(wc *WasmContext) WasmVM
- func (vm *WasmTimeVM) RunFunction(functionName string, args ...interface{}) error
- func (vm *WasmTimeVM) RunScFunction(index int32) error
- func (vm *WasmTimeVM) UnsafeMemory() []byte
- type WasmVM
- type WasmVMBase
- func (vm *WasmVMBase) GasBudget(budget uint64)
- func (vm *WasmVMBase) GasBurned() uint64
- func (vm *WasmVMBase) HostAbort(errMsg, fileName, line, col int32)
- func (vm *WasmVMBase) HostFdWrite(fd, iovs, size, written int32) int32
- func (vm *WasmVMBase) HostStateGet(keyRef, keyLen, valRef, valLen int32) int32
- func (vm *WasmVMBase) HostStateSet(keyRef, keyLen, valRef, valLen int32)
- func (vm *WasmVMBase) Instantiate(proc *WasmProcessor) error
- func (vm *WasmVMBase) LinkHost() error
- func (vm *WasmVMBase) Run(runner func() error) (err error)
- func (vm *WasmVMBase) VMGetBytes(offset, size int32) []byte
- func (vm *WasmVMBase) VMGetSize() int32
- func (vm *WasmVMBase) VMSetBytes(offset, size int32, bytes []byte) int32
Constants ¶
const ( FuncAbort = "abort" FuncFdWrite = "fd_write" FuncHostStateGet = "hostStateGet" FuncHostStateSet = "hostStateSet" ModuleEnv = "env" ModuleWasi1 = "wasi_unstable" ModuleWasi2 = "wasi_snapshot_preview1" ModuleWasmLib = "WasmLib" )
const (
FuncDefault = "_default"
)
Variables ¶
var ( // DisableWasmTimeout can be used to disable the annoying timeout during debugging DisableWasmTimeout = true // HostTracing turns on debug tracing for ScHost calls HostTracing = false // WasmTimeout set this to non-zero for a one-time override of the defaultTimeout WasmTimeout = 0 * time.Second )
var (
EventSubscribers []func(topic string, timestamp uint64, payload []byte)
)
var GoWasmVM func() WasmVM
Functions ¶
func GetProcessor ¶
GetProcessor creates a new Wasm VM processor.
Types ¶
type ScOnloadFunc ¶
type ScOnloadFunc func(index int32) *wasmlib.ScExportMap
type WasmContext ¶
type WasmContext struct {
// contains filtered or unexported fields
}
func NewWasmContext ¶
func NewWasmContext(proc *WasmProcessor, function string) *WasmContext
func NewWasmContextForSoloContext ¶
func NewWasmContextForSoloContext(function string, sandbox ISandbox) *WasmContext
func (*WasmContext) Call ¶
func (wc *WasmContext) Call(ctx interface{}) dict.Dict
func (*WasmContext) ExportName ¶
func (wc *WasmContext) ExportName(index int32, name string)
func (*WasmContext) FunctionFromCode ¶
func (wc *WasmContext) FunctionFromCode(code uint32) string
func (*WasmContext) GasBudget ¶ added in v0.3.0
func (wc *WasmContext) GasBudget() uint64
GasBudget is a callback from the VM that asks for the remaining gas budget of the Wasp sandbox. The VM will update the gas budget for the Wasm code with this value just before returning to the Wasm code.
func (*WasmContext) GasBurned ¶ added in v0.3.0
func (wc *WasmContext) GasBurned(burned uint64)
GasBurned is a callback from the VM that sets the remaining gas budget. It will update the gas budget for the Wasp sandbox with the amount of gas burned by the Wasm code thus far just before calling sandbox.
func (*WasmContext) GasDisable ¶ added in v0.3.0
func (wc *WasmContext) GasDisable(disable bool)
func (*WasmContext) IsView ¶
func (wc *WasmContext) IsView() bool
func (*WasmContext) RunScFunction ¶ added in v0.3.0
func (wc *WasmContext) RunScFunction(functionName string) (err error)
func (*WasmContext) StateDelete ¶
func (wc *WasmContext) StateDelete(key []byte)
func (*WasmContext) StateExists ¶
func (wc *WasmContext) StateExists(key []byte) bool
func (*WasmContext) StateGet ¶
func (wc *WasmContext) StateGet(key []byte) []byte
func (*WasmContext) StateSet ¶
func (wc *WasmContext) StateSet(key, value []byte)
type WasmContextSandbox ¶
type WasmContextSandbox struct {
// contains filtered or unexported fields
}
WasmContextSandbox is the host side of the WasmLib Sandbox interface It acts as a change-resistant layer to wrap changes to the ISC sandbox, to limit bothering users of WasmLib as little as possible with those changes.
func NewWasmContextSandbox ¶
func NewWasmContextSandbox(wc *WasmContext, ctx interface{}) *WasmContextSandbox
func (*WasmContextSandbox) Call ¶
func (s *WasmContextSandbox) Call(funcNr int32, params []byte) []byte
func (*WasmContextSandbox) Logf ¶ added in v1.0.3
func (s *WasmContextSandbox) Logf(format string, args ...interface{})
func (*WasmContextSandbox) Panicf ¶
func (s *WasmContextSandbox) Panicf(format string, args ...interface{})
func (*WasmContextSandbox) Tracef ¶
func (s *WasmContextSandbox) Tracef(format string, args ...interface{})
type WasmConvertor ¶
type WasmConvertor struct{}
WasmConvertor converts ISC data types to WasmLib data types
func (WasmConvertor) IscAddress ¶ added in v0.3.0
func (cvt WasmConvertor) IscAddress(scAddress *wasmtypes.ScAddress) iotago.Address
func (WasmConvertor) IscAgentID ¶ added in v0.3.0
func (cvt WasmConvertor) IscAgentID(scAgentID *wasmtypes.ScAgentID) isc.AgentID
func (WasmConvertor) IscAllowance ¶ added in v0.3.0
func (cvt WasmConvertor) IscAllowance(assets *wasmlib.ScAssets) *isc.Assets
func (WasmConvertor) IscBigInt ¶ added in v0.3.0
func (cvt WasmConvertor) IscBigInt(amount wasmtypes.ScBigInt) *big.Int
func (WasmConvertor) IscChainID ¶ added in v0.3.0
func (cvt WasmConvertor) IscChainID(chainID *wasmtypes.ScChainID) isc.ChainID
func (WasmConvertor) IscHash ¶ added in v0.3.0
func (cvt WasmConvertor) IscHash(hash *wasmtypes.ScHash) *hashing.HashValue
func (WasmConvertor) IscHname ¶ added in v0.3.0
func (cvt WasmConvertor) IscHname(hname wasmtypes.ScHname) isc.Hname
func (WasmConvertor) IscNFTID ¶ added in v0.3.0
func (cvt WasmConvertor) IscNFTID(nftID *wasmtypes.ScNftID) *iotago.NFTID
func (WasmConvertor) IscRequestID ¶ added in v0.3.0
func (cvt WasmConvertor) IscRequestID(requestID *wasmtypes.ScRequestID) isc.RequestID
func (WasmConvertor) IscTokenID ¶ added in v0.3.0
func (cvt WasmConvertor) IscTokenID(tokenID *wasmtypes.ScTokenID) iotago.NativeTokenID
func (WasmConvertor) ScAddress ¶
func (cvt WasmConvertor) ScAddress(address iotago.Address) wasmtypes.ScAddress
func (WasmConvertor) ScAgentID ¶
func (cvt WasmConvertor) ScAgentID(agentID isc.AgentID) wasmtypes.ScAgentID
func (WasmConvertor) ScBalances ¶ added in v0.3.0
func (cvt WasmConvertor) ScBalances(allowance *isc.Assets) *wasmlib.ScBalances
func (WasmConvertor) ScBigInt ¶ added in v0.3.0
func (cvt WasmConvertor) ScBigInt(bigInt *big.Int) wasmtypes.ScBigInt
func (WasmConvertor) ScChainID ¶
func (cvt WasmConvertor) ScChainID(chainID isc.ChainID) wasmtypes.ScChainID
func (WasmConvertor) ScHash ¶
func (cvt WasmConvertor) ScHash(hash hashing.HashValue) wasmtypes.ScHash
func (WasmConvertor) ScNftID ¶ added in v0.3.0
func (cvt WasmConvertor) ScNftID(nftID *iotago.NFTID) wasmtypes.ScNftID
func (WasmConvertor) ScRequestID ¶
func (cvt WasmConvertor) ScRequestID(requestID isc.RequestID) wasmtypes.ScRequestID
func (WasmConvertor) ScTokenID ¶ added in v0.3.0
func (cvt WasmConvertor) ScTokenID(nativeTokenID iotago.NativeTokenID) wasmtypes.ScTokenID
func (WasmConvertor) ToBigInt ¶ added in v0.3.0
func (cvt WasmConvertor) ToBigInt(amount interface{}) *big.Int
type WasmFuncTable ¶
type WasmFuncTable struct {
// contains filtered or unexported fields
}
func NewWasmFuncTable ¶
func NewWasmFuncTable() *WasmFuncTable
func (*WasmFuncTable) FunctionFromCode ¶
func (t *WasmFuncTable) FunctionFromCode(code uint32) string
func (*WasmFuncTable) SetExport ¶
func (t *WasmFuncTable) SetExport(index int32, functionName string)
type WasmGoVM ¶
type WasmGoVM struct { WasmVMBase // contains filtered or unexported fields }
func (*WasmGoVM) NewInstance ¶
func (vm *WasmGoVM) NewInstance(wc *WasmContext) WasmVM
func (*WasmGoVM) RunFunction ¶
func (*WasmGoVM) RunScFunction ¶
func (*WasmGoVM) UnsafeMemory ¶
type WasmProcessor ¶
type WasmProcessor struct {
// contains filtered or unexported fields
}
func (*WasmProcessor) Entrypoints ¶ added in v1.0.3
func (proc *WasmProcessor) Entrypoints() map[isc.Hname]isc.ProcessorEntryPoint
func (*WasmProcessor) GetCurrentContext ¶ added in v0.3.0
func (proc *WasmProcessor) GetCurrentContext() *WasmContext
func (*WasmProcessor) GetDefaultEntryPoint ¶
func (proc *WasmProcessor) GetDefaultEntryPoint() isc.VMProcessorEntryPoint
func (*WasmProcessor) GetDescription ¶
func (proc *WasmProcessor) GetDescription() string
func (*WasmProcessor) GetEntryPoint ¶
func (proc *WasmProcessor) GetEntryPoint(code isc.Hname) (isc.VMProcessorEntryPoint, bool)
func (*WasmProcessor) IsView ¶
func (proc *WasmProcessor) IsView(function string) bool
func (*WasmProcessor) RegisterContext ¶ added in v0.3.0
func (proc *WasmProcessor) RegisterContext(wc *WasmContext)
func (*WasmProcessor) UnregisterContext ¶ added in v0.3.0
func (proc *WasmProcessor) UnregisterContext(wc *WasmContext)
type WasmTimeVM ¶
type WasmTimeVM struct { WasmVMBase // contains filtered or unexported fields }
func (*WasmTimeVM) GasBudget ¶
func (vm *WasmTimeVM) GasBudget(budget uint64)
GasBudget sets the gas budget for the VM.
func (*WasmTimeVM) GasBurned ¶
func (vm *WasmTimeVM) GasBurned() uint64
GasBurned will return the gas burned since the last time GasBudget() was called
func (*WasmTimeVM) Interrupt ¶
func (vm *WasmTimeVM) Interrupt()
func (*WasmTimeVM) LinkHost ¶
func (vm *WasmTimeVM) LinkHost() (err error)
func (*WasmTimeVM) LoadWasm ¶
func (vm *WasmTimeVM) LoadWasm(wasmData []byte) (err error)
func (*WasmTimeVM) NewInstance ¶
func (vm *WasmTimeVM) NewInstance(wc *WasmContext) WasmVM
func (*WasmTimeVM) RunFunction ¶
func (vm *WasmTimeVM) RunFunction(functionName string, args ...interface{}) error
func (*WasmTimeVM) RunScFunction ¶
func (vm *WasmTimeVM) RunScFunction(index int32) error
func (*WasmTimeVM) UnsafeMemory ¶
func (vm *WasmTimeVM) UnsafeMemory() []byte
type WasmVM ¶
type WasmVM interface { GasBudget(budget uint64) GasBurned() uint64 Interrupt() LinkHost() error LoadWasm(wasmData []byte) error NewInstance(wc *WasmContext) WasmVM RunFunction(functionName string, args ...interface{}) error RunScFunction(index int32) error UnsafeMemory() []byte VMGetBytes(offset int32, size int32) []byte VMGetSize() int32 VMSetBytes(offset int32, size int32, bytes []byte) int32 }
func NewWasmGoVM ¶
func NewWasmGoVM(scName string, onLoad ScOnloadFunc) WasmVM
func NewWasmTimeVM ¶
func NewWasmTimeVM() WasmVM
type WasmVMBase ¶
type WasmVMBase struct {
// contains filtered or unexported fields
}
func (*WasmVMBase) GasBudget ¶
func (vm *WasmVMBase) GasBudget(budget uint64)
func (*WasmVMBase) GasBurned ¶
func (vm *WasmVMBase) GasBurned() uint64
func (*WasmVMBase) HostAbort ¶
func (vm *WasmVMBase) HostAbort(errMsg, fileName, line, col int32)
func (*WasmVMBase) HostFdWrite ¶
func (vm *WasmVMBase) HostFdWrite(fd, iovs, size, written int32) int32
func (*WasmVMBase) HostStateGet ¶
func (vm *WasmVMBase) HostStateGet(keyRef, keyLen, valRef, valLen int32) int32
func (*WasmVMBase) HostStateSet ¶
func (vm *WasmVMBase) HostStateSet(keyRef, keyLen, valRef, valLen int32)
func (*WasmVMBase) Instantiate ¶
func (vm *WasmVMBase) Instantiate(proc *WasmProcessor) error
func (*WasmVMBase) LinkHost ¶
func (vm *WasmVMBase) LinkHost() error
func (*WasmVMBase) Run ¶
func (vm *WasmVMBase) Run(runner func() error) (err error)
func (*WasmVMBase) VMGetBytes ¶
func (vm *WasmVMBase) VMGetBytes(offset, size int32) []byte
func (*WasmVMBase) VMGetSize ¶
func (vm *WasmVMBase) VMGetSize() int32
func (*WasmVMBase) VMSetBytes ¶
func (vm *WasmVMBase) VMSetBytes(offset, size int32, bytes []byte) int32