{"modulePath":"github.com/polynetwork/poly","version":"v1.5.3","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package exec\n\n  - Copyright (C) 2018 The ontology Authors\n  - This file is part of The ontology library. \\*\n  - The ontology is free software: you can redistribute it and/or modify\n  - it under the terms of the GNU Lesser General Public License as published by\n  - the Free Software Foundation, either version 3 of the License, or\n  - (at your option) any later version. \\*\n  - The ontology is distributed in the hope that it will be useful,\n  - but WITHOUT ANY WARRANTY; without even the implied warranty of\n  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n  - GNU Lesser General Public License for more details. \\*\n  - You should have received a copy of the GNU Lesser General Public License\n  - along with The ontology.  If not, see \\\u003c[http://www.gnu.org/licenses/](http://www.gnu.org/licenses/)\u003e.\n\nPackage exec provides functions for executing WebAssembly bytecode.\n\n## Constants\n\n```go\nconst (\n\tCONTRACT_METHOD_NAME = \"invoke\"\n\tCONTRACT_INIT_METHOD = \"init\"\n\tVM_STACK_DEPTH       = 10\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrSignatureMismatch is the error value used while trapping the VM when\n\t// a signature mismatch between the table entry and the type entry is found\n\t// in a call_indirect operation.\n\tErrSignatureMismatch = errors.New(\"exec: signature mismatch in call_indirect\")\n\t// ErrUndefinedElementIndex is the error value used while trapping the VM when\n\t// an invalid index to the module's table space is used as an operand to\n\t// call_indirect\n\tErrUndefinedElementIndex = errors.New(\"exec: undefined element index\")\n)\n```\n\n```go\nvar (\n\t// ErrMultipleLinearMemories is returned by (*VM).NewVM when the module\n\t// has more then one entries in the linear memory space.\n\tErrMultipleLinearMemories = errors.New(\"exec: more than one linear memories in module\")\n\t// ErrInvalidArgumentCount is returned by (*VM).ExecCode when an invalid\n\t// number of arguments to the WebAssembly function are passed to it.\n\tErrInvalidArgumentCount = errors.New(\"exec: invalid number of arguments to function\")\n)\n```\n\n```go\nvar ErrOutOfBoundsMemoryAccess = errors.New(\"exec: out of bounds memory access\")\n```\nErrOutOfBoundsMemoryAccess is the error value used while trapping the VM when it detects an out of bounds access to the linear memory.\n\n```go\nvar ErrUnreachable = errors.New(\"exec: reached unreachable\")\n```\nErrUnreachable is the error value used while trapping the VM when an unreachable operator is reached during execution.\n\n## Types\n\n```go\ntype Args struct {\n\tParams []Param `json:\"Params\"`\n}\n```\n\n```go\ntype EnvCall struct {\n\tMessage []interface{} //the 'Message' field is for the EOS contract like parameters\n\t// contains filtered or unexported fields\n}\n```\nstore env call message\n\n```go\nfunc (ec *EnvCall) GetParams() []uint64\n```\n\n```go\nfunc (ec *EnvCall) GetReturns() bool\n```\n\n```go\ntype ExecutionEngine struct {\n\tCodeContainer interfaces.CodeContainer\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewExecutionEngine(container interfaces.CodeContainer, crypto interfaces.Crypto, service InteropServiceInterface) *ExecutionEngine\n```\ntodo add parameters\n\n```go\nfunc (e *ExecutionEngine) Call(caller common.Address,\n\tcode []byte,\n\tactionName string,\n\tinput []byte,\n\tver byte) (returnbytes []byte, er error)\n```\nCall 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 \u003e 0 for production\n\n```go\nfunc (e *ExecutionEngine) CallInf(caller common.Address,\n\tcode []byte,\n\tinput []interface{},\n\tmessage []interface{}) ([]byte, error)\n```\nuse this method just for test\n\n```go\nfunc (e *ExecutionEngine) Create(caller common.Address, code []byte) ([]byte, error)\n```\n\n```go\nfunc (e *ExecutionEngine) GetMemory() *memory.VMmemory\n```\n\n```go\nfunc (e *ExecutionEngine) GetVM() *VM\n```\nGetVM return vm pointer\n\n```go\nfunc (e *ExecutionEngine) InitCall(caller common.Address,\n\tcode []byte,\n\tinput []byte,\n\tver byte) (returnbytes []byte, er error)\n```\nCall init method on deployment caller      common.Address :call address code        \\[]byte         :wasm smart contract code input       \\[]byte         :arguments ver         byte           :contract version  require \u003e 0 for production TODO TBD whether we need to call init method after deploy automatically\n\n```go\nfunc (e *ExecutionEngine) RestoreVM() error\n```\nfor call other contract, 1.pop stored vm 2.reset vm\n\n```go\nfunc (e *ExecutionEngine) SetNewVM(vm *VM) error\n```\nfor call other contract, 1.store current vm 2.load new vm\n\n```go\ntype InteropService struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewInteropService() *InteropService\n```\n\n```go\nfunc (i *InteropService) Exists(name string) bool\n```\n\n```go\nfunc (i *InteropService) GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)\n```\n\n```go\nfunc (i *InteropService) Invoke(methodName string, engine *ExecutionEngine) (bool, error)\n```\n\n```go\nfunc (i *InteropService) MergeMap(mMap map[string]func(*ExecutionEngine) (bool, error)) bool\n```\n\n```go\nfunc (i *InteropService) Register(name string, handler func(*ExecutionEngine) (bool, error)) bool\n```\n\n```go\ntype InteropServiceInterface interface {\n\tRegister(method string, handler func(*ExecutionEngine) (bool, error)) bool\n\tGetServiceMap() map[string]func(*ExecutionEngine) (bool, error)\n}\n```\n\n```go\ntype InvalidFunctionIndexError int64\n```\nInvalidFunctionIndexError is returned by (\\*VM).ExecCode when the function index provided is invalid.\n\n```go\nfunc (e InvalidFunctionIndexError) Error() string\n```\n\n```go\ntype InvalidReturnTypeError int8\n```\nInvalidReturnTypeError is returned by (\\*VM).ExecCode when the module specifies an invalid return type value for the executed function.\n\n```go\nfunc (e InvalidReturnTypeError) Error() string\n```\n\n```go\ntype Param struct {\n\tPtype string `json:\"type\"`\n\tPval  string `json:\"value\"`\n}\n```\n\n```go\ntype Result struct {\n\tPtype    string `json:\"type\"`\n\tPval     string `json:\"value\"`\n\tPsucceed int    `json:\"succeed\"`\n}\n```\n\n```go\ntype VM struct {\n\tServices map[string]func(engine *ExecutionEngine) (bool, error)\n\n\t//store a engine pointer\n\tContractAddress common.Address\n\tCaller          common.Address\n\tEngine          *ExecutionEngine\n\tVMCode          []byte\n\t// contains filtered or unexported fields\n}\n```\nVM is the execution context for executing WebAssembly bytecode.\n\n```go\nfunc NewVM(module *wasm.Module) (*VM, error)\n```\nNewVM creates a new VM from a given module. If the module defines a start function, it will be executed.\n\n```go\nfunc (vm *VM) CallContract(caller common.Address, contractAddress common.Address, module *wasm.Module, actionName []byte, arg []byte) (uint64, error)\n```\nCallContract start a new vm this method is replaced with wasm\\_service :callContract\n\n```go\nfunc (vm *VM) ExecCode(insideCall bool, fnIndex int64, args ...uint64) (interface{}, error)\n```\nExecCode 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)\n\n```go\nfunc (vm *VM) GetEnvCall() *EnvCall\n```\n\n```go\nfunc (vm *VM) GetMemory() *memory.VMmemory\n```\n\n```go\nfunc (vm *VM) GetMessageBytes() ([]byte, error)\n```\nGetMessageBytes for further extension\n\n```go\nfunc (vm *VM) GetPointerMemSize(addr uint64) int\n```\n\n```go\nfunc (vm *VM) GetPointerMemory(addr uint64) ([]byte, error)\n```\nwhen wasm returns a pointer, call this function to get the pointed memory\n\n```go\nfunc (vm *VM) Malloc(size int) (int, error)\n```\nalloc memory and return the first index\n\n```go\nfunc (vm *VM) MallocPointer(size int, ptype memory.PType) (int, error)\n```\nalloc memory for pointer and return the first index\n\n```go\nfunc (vm *VM) Memory() []byte\n```\nMemory returns the linear memory space for the VM.\n\n```go\nfunc (vm *VM) PushResult(res uint64)\n```\n\n```go\nfunc (vm *VM) RestoreCtx() bool\n```\n\n```go\nfunc (vm *VM) SetMemory(val interface{}) (int, error)\n```\n\n```go\nfunc (vm *VM) SetMessage(message []interface{})\n```\nSetMessage for further extension support EOS like message\n\n```go\nfunc (vm *VM) SetPointerMemory(val interface{}) (int, error)\n```\nalloc memory for any pointer type\n\n```go\nfunc (vm *VM) SetStructMemory(val interface{}) (int, error)\n```\nalloc memory for struct todo move to the SetPointerMemory\n\n","path":"github.com/polynetwork/poly/vm/wasmvm/exec","name":"exec","synopsis":"* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library.","isRedistributable":true}
