vm

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package vm the contract execute environment

Index

Constants

View Source
const (
	InvokeTypeRequest  = byte(1)
	InvokeTypeResponse = byte(2)
)

request, response type

Variables

This section is empty.

Functions

func CheckAddr

func CheckAddr(addr string) error

func CheckContractCode

func CheckContractCode(code string) error

func CheckStateKey

func CheckStateKey(key string) error

func CheckStateKeyValue

func CheckStateKeyValue(key string, value []byte) error

func CheckStateValue

func CheckStateValue(value []byte) error

func NewStateQueue

func NewStateQueue() *stateQueue

func NewTransferQueue

func NewTransferQueue() *transferQueue

func PreExecute

func PreExecute(tx *types.Transaction, cs *types.ContractSpec, handler contract.ISmartConstract) (bool, error)

PreExecute execute contract but not commit change(balances and state)

func Query

func Query(tx *types.Transaction, cs *types.ContractSpec, handler contract.ISmartConstract) ([]byte, error)

func RealExecute

func RealExecute(tx *types.Transaction, cs *types.ContractSpec, handler contract.ISmartConstract) (bool, error)

RealExecute execute contract and commit change(balances and state)

Types

type Config

type Config struct {
	LogFile                    string
	LogLevel                   string
	VMRegistrySize             int
	VMCallStackSize            int
	VMMaxMem                   int // vm maximum memory size (MB)
	ExecLimitStackDepth        int
	ExecLimitMaxOpcodeCount    int // maximum allow execute opcode count
	ExecLimitMaxRunTime        int // the contract maximum run time (millisecond)
	ExecLimitMaxScriptSize     int // contract script(lua source code) maximum size (byte)
	ExecLimitMaxStateValueSize int // the max state value size (byte)
	ExecLimitMaxStateItemCount int // the max state count in one contract
	ExecLimitMaxStateKeyLength int // max state key length
	LuaVMExeFilePath           string
	JSVMExeFilePath            string
}

Config vm config struct

var VMConf *Config

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig default vm config

type ContractCode

type ContractCode struct {
	Code []byte
	Type string
}

type ContractData

type ContractData struct {
	ContractCode   string
	ContractAddr   string
	ContractParams []string
	Transaction    *types.Transaction
}

func NewContractData

func NewContractData(tx *types.Transaction, cs *types.ContractSpec, contractCode string) *ContractData

type InvokeData

type InvokeData struct {
	Type      byte
	FuncName  string
	SessionID uint32
	Params    []byte
}

InvokeData request and response data

func (*InvokeData) DecodeParams

func (data *InvokeData) DecodeParams(dataObj ...interface{}) error

func (*InvokeData) SetParams

func (data *InvokeData) SetParams(params ...interface{})

type RequestHandleType

type RequestHandleType func(vmproc *VMProc, data *InvokeData) (interface{}, error)

type VMProc

type VMProc struct {
	Proc             *os.Process
	PeerProc         *os.Process
	PipeWriter       *os.File
	PipeReader       *os.File
	Files            []*os.File
	StartTime        time.Time
	Lang             string
	Running          bool
	RequestHandle    RequestHandleType
	ContractData     *ContractData
	L0Handler        contract.ISmartConstract
	RequestMap       map[uint32]chan *InvokeData
	StateChangeQueue *stateQueue
	TransferQueue    *transferQueue
	SessionID        uint32
	// contains filtered or unexported fields
}

VMProc the vm process struct

func FindVMProcess

func FindVMProcess() (*VMProc, error)

FindVMProcess find vm process from child proc

func NewVMProc

func NewVMProc(name string) (*VMProc, error)

NewVMProc create a vm process

func (*VMProc) CCallCommit

func (p *VMProc) CCallCommit() error

func (*VMProc) CCallCurrentBlockHeight

func (p *VMProc) CCallCurrentBlockHeight() (uint32, error)

func (*VMProc) CCallDelState

func (p *VMProc) CCallDelState(key string) error

func (*VMProc) CCallGetBalances

func (p *VMProc) CCallGetBalances(addr string) (int64, error)

func (*VMProc) CCallGetState

func (p *VMProc) CCallGetState(key string) ([]byte, error)

func (*VMProc) CCallPutState

func (p *VMProc) CCallPutState(key string, value []byte) error

func (*VMProc) CCallSmartContractCommitted

func (p *VMProc) CCallSmartContractCommitted() error

func (*VMProc) CCallSmartContractFailed

func (p *VMProc) CCallSmartContractFailed() error

func (*VMProc) CCallTransfer

func (p *VMProc) CCallTransfer(recipientAddr string, amount int64, txType uint32) error

func (*VMProc) Close

func (p *VMProc) Close()

Close close the vm process and release all resources

func (*VMProc) PCallPreExecute

func (p *VMProc) PCallPreExecute(cd *ContractData, handler contract.ISmartConstract) (bool, error)

func (*VMProc) PCallPreInitContract

func (p *VMProc) PCallPreInitContract(cd *ContractData, handler contract.ISmartConstract) (bool, error)

func (*VMProc) PCallQueryContract

func (p *VMProc) PCallQueryContract(cd *ContractData, handler contract.ISmartConstract) ([]byte, error)

func (*VMProc) PCallRealExecute

func (p *VMProc) PCallRealExecute(cd *ContractData, handler contract.ISmartConstract) (bool, error)

func (*VMProc) PCallRealInitContract

func (p *VMProc) PCallRealInitContract(cd *ContractData, handler contract.ISmartConstract) (bool, error)

func (*VMProc) Selector

func (p *VMProc) Selector()

func (*VMProc) SendRequest

func (p *VMProc) SendRequest(data *InvokeData) chan *InvokeData

func (*VMProc) SendResponse

func (p *VMProc) SendResponse(data *InvokeData) error

func (*VMProc) SetRequestHandle

func (p *VMProc) SetRequestHandle(handle RequestHandleType)

Directories

Path Synopsis
main command
main command

Jump to

Keyboard shortcuts

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