Documentation ¶
Overview ¶
- Copyright (C) 2018 The ontology Authors
- This file is part of The ontology library. *
- The ontology is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version. *
- The ontology is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details. *
- You should have received a copy of the GNU Lesser General Public License
- along with The ontology. If not, see <http://www.gnu.org/licenses/>.
Package exec provides functions for executing WebAssembly bytecode.
Index ¶
- Constants
- Variables
- type Args
- type EnvCall
- type ExecutionEngine
- func (e *ExecutionEngine) Call(caller common.Address, code []byte, actionName string, input []byte, ver byte) (returnbytes []byte, er error)
- func (e *ExecutionEngine) CallInf(caller common.Address, code []byte, input []interface{}, message []interface{}) ([]byte, error)
- func (e *ExecutionEngine) Create(caller common.Address, code []byte) ([]byte, error)
- func (e *ExecutionEngine) GetMemory() *memory.VMmemory
- func (e *ExecutionEngine) GetVM() *VM
- func (e *ExecutionEngine) InitCall(caller common.Address, code []byte, input []byte, ver byte) (returnbytes []byte, er error)
- func (e *ExecutionEngine) RestoreVM() error
- func (e *ExecutionEngine) SetNewVM(vm *VM) error
- type InteropService
- func (i *InteropService) Exists(name string) bool
- func (i *InteropService) GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)
- func (i *InteropService) Invoke(methodName string, engine *ExecutionEngine) (bool, error)
- func (i *InteropService) MergeMap(mMap map[string]func(*ExecutionEngine) (bool, error)) bool
- func (i *InteropService) Register(name string, handler func(*ExecutionEngine) (bool, error)) bool
- type InteropServiceInterface
- type InvalidFunctionIndexError
- type InvalidReturnTypeError
- type Param
- type Result
- type VM
- func (vm *VM) CallContract(caller common.Address, contractAddress common.Address, module *wasm.Module, ...) (uint64, error)
- func (vm *VM) ExecCode(insideCall bool, fnIndex int64, args ...uint64) (interface{}, error)
- func (vm *VM) GetEnvCall() *EnvCall
- func (vm *VM) GetMemory() *memory.VMmemory
- func (vm *VM) GetMessageBytes() ([]byte, error)
- func (vm *VM) GetPointerMemSize(addr uint64) int
- func (vm *VM) GetPointerMemory(addr uint64) ([]byte, error)
- func (vm *VM) Malloc(size int) (int, error)
- func (vm *VM) MallocPointer(size int, ptype memory.PType) (int, error)
- func (vm *VM) Memory() []byte
- func (vm *VM) PushResult(res uint64)
- func (vm *VM) RestoreCtx() bool
- func (vm *VM) SetMemory(val interface{}) (int, error)
- func (vm *VM) SetMessage(message []interface{})
- func (vm *VM) SetPointerMemory(val interface{}) (int, error)
- func (vm *VM) SetStructMemory(val interface{}) (int, error)
Constants ¶
const ( CONTRACT_METHOD_NAME = "invoke" CONTRACT_INIT_METHOD = "init" VM_STACK_DEPTH = 10 )
Variables ¶
var ( // ErrSignatureMismatch is the error value used while trapping the VM when // a signature mismatch between the table entry and the type entry is found // in a call_indirect operation. ErrSignatureMismatch = errors.New("exec: signature mismatch in call_indirect") // ErrUndefinedElementIndex is the error value used while trapping the VM when // an invalid index to the module's table space is used as an operand to // call_indirect ErrUndefinedElementIndex = errors.New("exec: undefined element index") )
var ( // ErrMultipleLinearMemories is returned by (*VM).NewVM when the module // has more then one entries in the linear memory space. ErrMultipleLinearMemories = errors.New("exec: more than one linear memories in module") // ErrInvalidArgumentCount is returned by (*VM).ExecCode when an invalid // number of arguments to the WebAssembly function are passed to it. ErrInvalidArgumentCount = errors.New("exec: invalid number of arguments to function") )
var ErrOutOfBoundsMemoryAccess = errors.New("exec: out of bounds memory access")
ErrOutOfBoundsMemoryAccess is the error value used while trapping the VM when it detects an out of bounds access to the linear memory.
var ErrUnreachable = errors.New("exec: reached unreachable")
ErrUnreachable is the error value used while trapping the VM when an unreachable operator is reached during execution.
Functions ¶
This section is empty.
Types ¶
type EnvCall ¶
type EnvCall struct { Message []interface{} //the 'Message' field is for the EOS contract like parameters // contains filtered or unexported fields }
store env call message
func (*EnvCall) GetReturns ¶
type ExecutionEngine ¶
type ExecutionEngine struct { CodeContainer interfaces.CodeContainer // contains filtered or unexported fields }
func NewExecutionEngine ¶
func NewExecutionEngine(container interfaces.CodeContainer, crypto interfaces.Crypto, service InteropServiceInterface) *ExecutionEngine
todo add parameters
func (*ExecutionEngine) Call ¶
func (e *ExecutionEngine) Call(caller common.Address, code []byte, actionName string, input []byte, ver byte) (returnbytes []byte, er error)
Call Main interface of wasm vm excution engine caller common.Address :call address code []byte :wasm smart contract code actionName string :action name of the contract input []byte :arguments ver byte :contract version require > 0 for production
func (*ExecutionEngine) CallInf ¶
func (e *ExecutionEngine) CallInf(caller common.Address, code []byte, input []interface{}, message []interface{}) ([]byte, error)
use this method just for test
func (*ExecutionEngine) GetMemory ¶
func (e *ExecutionEngine) GetMemory() *memory.VMmemory
func (*ExecutionEngine) InitCall ¶
func (e *ExecutionEngine) InitCall(caller common.Address, code []byte, input []byte, ver byte) (returnbytes []byte, er error)
Call init method on deployment caller common.Address :call address code []byte :wasm smart contract code input []byte :arguments ver byte :contract version require > 0 for production TODO TBD whether we need to call init method after deploy automatically
func (*ExecutionEngine) RestoreVM ¶
func (e *ExecutionEngine) RestoreVM() error
for call other contract, 1.pop stored vm 2.reset vm
func (*ExecutionEngine) SetNewVM ¶
func (e *ExecutionEngine) SetNewVM(vm *VM) error
for call other contract, 1.store current vm 2.load new vm
type InteropService ¶
type InteropService struct {
// contains filtered or unexported fields
}
func NewInteropService ¶
func NewInteropService() *InteropService
func (*InteropService) Exists ¶
func (i *InteropService) Exists(name string) bool
func (*InteropService) GetServiceMap ¶
func (i *InteropService) GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)
func (*InteropService) Invoke ¶
func (i *InteropService) Invoke(methodName string, engine *ExecutionEngine) (bool, error)
func (*InteropService) MergeMap ¶
func (i *InteropService) MergeMap(mMap map[string]func(*ExecutionEngine) (bool, error)) bool
func (*InteropService) Register ¶
func (i *InteropService) Register(name string, handler func(*ExecutionEngine) (bool, error)) bool
type InteropServiceInterface ¶
type InteropServiceInterface interface { Register(method string, handler func(*ExecutionEngine) (bool, error)) bool GetServiceMap() map[string]func(*ExecutionEngine) (bool, error) }
type InvalidFunctionIndexError ¶
type InvalidFunctionIndexError int64
InvalidFunctionIndexError is returned by (*VM).ExecCode when the function index provided is invalid.
func (InvalidFunctionIndexError) Error ¶
func (e InvalidFunctionIndexError) Error() string
type InvalidReturnTypeError ¶
type InvalidReturnTypeError int8
InvalidReturnTypeError is returned by (*VM).ExecCode when the module specifies an invalid return type value for the executed function.
func (InvalidReturnTypeError) Error ¶
func (e InvalidReturnTypeError) Error() string
type VM ¶
type VM struct { Services map[string]func(engine *ExecutionEngine) (bool, error) //store a engine pointer ContractAddress common.Address Caller common.Address Engine *ExecutionEngine VMCode []byte // contains filtered or unexported fields }
VM is the execution context for executing WebAssembly bytecode.
func NewVM ¶
NewVM creates a new VM from a given module. If the module defines a start function, it will be executed.
func (*VM) CallContract ¶
func (vm *VM) CallContract(caller common.Address, contractAddress common.Address, module *wasm.Module, actionName []byte, arg []byte) (uint64, error)
CallContract start a new vm this method is replaced with wasm_service :callContract
func (*VM) ExecCode ¶
ExecCode calls the function with the given index and arguments. fnIndex should be a valid index into the function index space of the VM's module. insideCall :true (call contract)
func (*VM) GetEnvCall ¶
func (*VM) GetMessageBytes ¶
GetMessageBytes for further extension
func (*VM) GetPointerMemSize ¶
func (*VM) GetPointerMemory ¶
when wasm returns a pointer, call this function to get the pointed memory
func (*VM) MallocPointer ¶
alloc memory for pointer and return the first index
func (*VM) PushResult ¶
func (*VM) RestoreCtx ¶
func (*VM) SetMessage ¶
func (vm *VM) SetMessage(message []interface{})
SetMessage for further extension support EOS like message
func (*VM) SetPointerMemory ¶
alloc memory for any pointer type
func (*VM) SetStructMemory ¶
alloc memory for struct todo move to the SetPointerMemory
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
compile
Package compile is used internally by wagon to convert standard structured WebAssembly bytecode into an unstructured form suitable for execution by it's VM.
|
Package compile is used internally by wagon to convert standard structured WebAssembly bytecode into an unstructured form suitable for execution by it's VM. |