wasmhost

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OBJTYPE_ARRAY    int32 = 0x20
	OBJTYPE_ARRAY16  int32 = 0x60
	OBJTYPE_CALL     int32 = 0x80
	OBJTYPE_TYPEMASK int32 = 0x1f

	OBJTYPE_ADDRESS    int32 = 1
	OBJTYPE_AGENT_ID   int32 = 2
	OBJTYPE_BOOL       int32 = 3
	OBJTYPE_BYTES      int32 = 4
	OBJTYPE_CHAIN_ID   int32 = 5
	OBJTYPE_COLOR      int32 = 6
	OBJTYPE_HASH       int32 = 7
	OBJTYPE_HNAME      int32 = 8
	OBJTYPE_INT8       int32 = 9
	OBJTYPE_INT16      int32 = 10
	OBJTYPE_INT32      int32 = 11
	OBJTYPE_INT64      int32 = 12
	OBJTYPE_MAP        int32 = 13
	OBJTYPE_REQUEST_ID int32 = 14
	OBJTYPE_STRING     int32 = 15

	OBJID_NULL    int32 = 0
	OBJID_ROOT    int32 = 1
	OBJID_STATE   int32 = 2
	OBJID_PARAMS  int32 = 3
	OBJID_RESULTS int32 = 4
)
View Source
const (
	KeyAccountID       = int32(-1)
	KeyAddress         = int32(-2)
	KeyBalances        = int32(-3)
	KeyBase58Decode    = int32(-4)
	KeyBase58Encode    = int32(-5)
	KeyBlsAddress      = int32(-6)
	KeyBlsAggregate    = int32(-7)
	KeyBlsValid        = int32(-8)
	KeyCall            = int32(-9)
	KeyCaller          = int32(-10)
	KeyChainID         = int32(-11)
	KeyChainOwnerID    = int32(-12)
	KeyColor           = int32(-13)
	KeyContract        = int32(-14)
	KeyContractCreator = int32(-15)
	KeyDeploy          = int32(-16)
	KeyEd25519Address  = int32(-17)
	KeyEd25519Valid    = int32(-18)
	KeyEvent           = int32(-19)
	KeyExports         = int32(-20)
	KeyHashBlake2b     = int32(-21)
	KeyHashSha3        = int32(-22)
	KeyHname           = int32(-23)
	KeyIncoming        = int32(-24)
	KeyLength          = int32(-25)
	KeyLog             = int32(-26)
	KeyMaps            = int32(-27)
	KeyMinted          = int32(-28)
	KeyPanic           = int32(-29)
	KeyParams          = int32(-30)
	KeyPost            = int32(-31)
	KeyRandom          = int32(-32)
	KeyRequestID       = int32(-33)
	KeyResults         = int32(-34)
	KeyReturn          = int32(-35)
	KeyState           = int32(-36)
	KeyTimestamp       = int32(-37)
	KeyTrace           = int32(-38)
	KeyTransfers       = int32(-39)
	KeyUtility         = int32(-40)

	// KeyZzzzzzz is treated like a version number.
	// When anything changes to the keys give this one a different value
	// and make sure that the client side is updated accordingly
	KeyZzzzzzz = int32(-41)
)
View Source
const (
	FuncAbort           = "abort"
	FuncFdWrite         = "fd_write"
	FuncHostGetBytes    = "hostGetBytes"
	FuncHostGetKeyID    = "hostGetKeyID"
	FuncHostGetObjectID = "hostGetObjectID"
	FuncHostSetBytes    = "hostSetBytes"
	ModuleEnv           = "env"
	ModuleWasi1         = "wasi_unstable"
	ModuleWasi2         = "wasi_snapshot_preview1"
	ModuleWasmLib       = "WasmLib"
)
View Source
const KeyFromBytes int32 = 0x4000

flag to indicate that this key id originally comes from a bytes key this allows us to display better readable tracing information

Variables

View Source
var (
	// DisableWasmTimeout can be used to disable the annoying timeout during debugging
	DisableWasmTimeout = false

	// HostTracing turns on debug tracing for ScHost calls
	HostTracing = false

	// HostTracingAll turns on *all* debug tracing for ScHost calls
	HostTracingAll = false

	// WasmTimeout set this to non-zero for a one-time override of the defaultTimeout
	WasmTimeout = 0 * time.Second
)
View Source
var TypeSizes = [...]int{0, 33, 37, 1, 0, 33, 32, 32, 4, 1, 2, 4, 8, 0, 34, 0}

Functions

func Connect added in v0.2.2

func Connect(h wasmlib.ScHost) wasmlib.ScHost

provide implementation for Wasm-only function

Types

type HostObject

type HostObject interface {
	CallFunc(keyID int32, params []byte) []byte
	DelKey(keyID, typeID int32)
	Exists(keyID, typeID int32) bool
	GetBytes(keyID, typeID int32) []byte
	GetObjectID(keyID, typeID int32) int32
	GetTypeID(keyID int32) int32
	SetBytes(keyID, typeID int32, bytes []byte)
}

type KvStoreHost

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

KvStoreHost implements WaspLib.client.ScHost interface it allows WasmGoVM to bypass Wasm and access the sandbox directly so that it is possible to debug into SC code that was written in Go

func (*KvStoreHost) CallFunc added in v0.2.0

func (h *KvStoreHost) CallFunc(objID, keyID int32, params []byte) []byte

func (*KvStoreHost) DelKey added in v0.2.3

func (h *KvStoreHost) DelKey(objID, keyID, typeID int32)

func (*KvStoreHost) Exists

func (h *KvStoreHost) Exists(objID, keyID, typeID int32) bool

func (*KvStoreHost) FindObject

func (h *KvStoreHost) FindObject(objID int32) HostObject

func (*KvStoreHost) GetBytes

func (h *KvStoreHost) GetBytes(objID, keyID, typeID int32) []byte

func (*KvStoreHost) GetKeyFromID added in v0.2.0

func (h *KvStoreHost) GetKeyFromID(keyID int32) []byte

func (*KvStoreHost) GetKeyIDFromBytes added in v0.2.0

func (h *KvStoreHost) GetKeyIDFromBytes(bytes []byte) int32

func (*KvStoreHost) GetKeyIDFromString added in v0.2.0

func (h *KvStoreHost) GetKeyIDFromString(key string) int32

func (*KvStoreHost) GetKeyStringFromID added in v0.2.0

func (h *KvStoreHost) GetKeyStringFromID(keyID int32) string

func (*KvStoreHost) GetObjectID added in v0.2.0

func (h *KvStoreHost) GetObjectID(objID, keyID, typeID int32) int32

func (*KvStoreHost) Init

func (h *KvStoreHost) Init(scKeys *KvStoreHost)

func (*KvStoreHost) Panicf added in v0.2.3

func (h *KvStoreHost) Panicf(format string, args ...interface{})

func (*KvStoreHost) SetBytes

func (h *KvStoreHost) SetBytes(objID, keyID, typeID int32, bytes []byte)

func (*KvStoreHost) TraceAllf added in v0.2.0

func (h *KvStoreHost) TraceAllf(format string, a ...interface{})

func (*KvStoreHost) Tracef added in v0.2.0

func (h *KvStoreHost) Tracef(format string, a ...interface{})

func (*KvStoreHost) TrackObject

func (h *KvStoreHost) TrackObject(obj HostObject) int32

func (*KvStoreHost) TypeCheck added in v0.2.3

func (h *KvStoreHost) TypeCheck(typeID int32, bytes []byte)

type WasmGoVM added in v0.2.0

type WasmGoVM struct {
	WasmVMBase
	// contains filtered or unexported fields
}

func (*WasmGoVM) Instantiate added in v0.2.3

func (vm *WasmGoVM) Instantiate() error

func (*WasmGoVM) Interrupt added in v0.2.0

func (vm *WasmGoVM) Interrupt()

func (*WasmGoVM) LoadWasm added in v0.2.0

func (vm *WasmGoVM) LoadWasm(wasmData []byte) error

func (*WasmGoVM) NewInstance added in v0.2.3

func (vm *WasmGoVM) NewInstance() WasmVM

func (*WasmGoVM) RunFunction added in v0.2.0

func (vm *WasmGoVM) RunFunction(functionName string, args ...interface{}) error

func (*WasmGoVM) RunScFunction added in v0.2.0

func (vm *WasmGoVM) RunScFunction(index int32) error

func (*WasmGoVM) UnsafeMemory added in v0.2.0

func (vm *WasmGoVM) UnsafeMemory() []byte

type WasmHost

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

func (*WasmHost) AddFunc added in v0.2.0

func (*WasmHost) AddView added in v0.2.0

func (*WasmHost) FunctionFromCode

func (host *WasmHost) FunctionFromCode(code uint32) string

func (*WasmHost) Init

func (host *WasmHost) Init()

func (*WasmHost) InitVM

func (host *WasmHost) InitVM(vm WasmVM, store WasmStore) error

func (*WasmHost) Instantiate added in v0.2.3

func (host *WasmHost) Instantiate() error

func (*WasmHost) IsView

func (host *WasmHost) IsView(function string) bool

func (*WasmHost) LoadWasm

func (host *WasmHost) LoadWasm(wasmData []byte) error

func (*WasmHost) NewInstance added in v0.2.3

func (host *WasmHost) NewInstance() WasmVM

func (*WasmHost) RunFunction

func (host *WasmHost) RunFunction(functionName string, args ...interface{}) (err error)

func (*WasmHost) RunScFunction

func (host *WasmHost) RunScFunction(functionName string) (err error)

func (*WasmHost) SetExport

func (host *WasmHost) SetExport(index int32, functionName string)

type WasmStore added in v0.2.0

type WasmStore interface {
	GetKvStore(id int32) *KvStoreHost
}

type WasmTimeVM

type WasmTimeVM struct {
	WasmVMBase
	// contains filtered or unexported fields
}

func (*WasmTimeVM) Instantiate added in v0.2.3

func (vm *WasmTimeVM) Instantiate() (err error)

func (*WasmTimeVM) Interrupt added in v0.2.0

func (vm *WasmTimeVM) Interrupt()

func (*WasmTimeVM) LinkHost

func (vm *WasmTimeVM) LinkHost(impl WasmVM, host *WasmHost) (err error)

func (*WasmTimeVM) LoadWasm

func (vm *WasmTimeVM) LoadWasm(wasmData []byte) (err error)

func (*WasmTimeVM) NewInstance added in v0.2.3

func (vm *WasmTimeVM) NewInstance() 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 {
	Instantiate() error
	Interrupt()
	LinkHost(impl WasmVM, host *WasmHost) error
	LoadWasm(wasmData []byte) error
	NewInstance() 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 added in v0.2.0

func NewWasmGoVM(scName string, onLoad func()) WasmVM

func NewWasmTimeVM

func NewWasmTimeVM() WasmVM

type WasmVMBase added in v0.2.0

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

func (*WasmVMBase) HostAbort added in v0.2.3

func (vm *WasmVMBase) HostAbort(errMsg, fileName, line, col int32)

func (*WasmVMBase) HostFdWrite added in v0.2.0

func (vm *WasmVMBase) HostFdWrite(_fd, iovs, _size, written int32) int32

func (*WasmVMBase) HostGetBytes added in v0.2.0

func (vm *WasmVMBase) HostGetBytes(objID, keyID, typeID, stringRef, size int32) int32

func (*WasmVMBase) HostGetKeyID added in v0.2.0

func (vm *WasmVMBase) HostGetKeyID(keyRef, size int32) int32

func (*WasmVMBase) HostGetObjectID added in v0.2.0

func (vm *WasmVMBase) HostGetObjectID(objID, keyID, typeID int32) int32

func (*WasmVMBase) HostSetBytes added in v0.2.0

func (vm *WasmVMBase) HostSetBytes(objID, keyID, typeID, stringRef, size int32)

func (*WasmVMBase) Instantiate added in v0.2.3

func (vm *WasmVMBase) Instantiate() error

func (*WasmVMBase) LinkHost added in v0.2.0

func (vm *WasmVMBase) LinkHost(impl WasmVM, host *WasmHost) error

func (*WasmVMBase) Run added in v0.2.0

func (vm *WasmVMBase) Run(runner func() error) (err error)

func (*WasmVMBase) VMGetBytes added in v0.2.0

func (vm *WasmVMBase) VMGetBytes(offset, size int32) []byte

func (*WasmVMBase) VMGetSize added in v0.2.3

func (vm *WasmVMBase) VMGetSize() int32

func (*WasmVMBase) VMSetBytes added in v0.2.0

func (vm *WasmVMBase) VMSetBytes(offset, size int32, bytes []byte) int32

Jump to

Keyboard shortcuts

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