diff options
author | jm <jm.huang@cobinhood.com> | 2019-01-16 17:32:29 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:03 +0800 |
commit | d3b485a5af768db59bd648175849f961e25bc630 (patch) | |
tree | ec43033c9aa438969cea45fb9de19e50a88a5cd8 /core/vm/sqlvm | |
parent | 266068a53cdf9e06acacf982d63653c03133a634 (diff) | |
download | dexon-d3b485a5af768db59bd648175849f961e25bc630.tar dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.gz dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.bz2 dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.lz dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.xz dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.zst dexon-d3b485a5af768db59bd648175849f961e25bc630.zip |
core: vm: extract stateDB and contract out
Extract stateDB and contract out from core/vm/evm to core/vm,
such that other vm type can use the common modules.
Diffstat (limited to 'core/vm/sqlvm')
-rw-r--r-- | core/vm/sqlvm/sqlvm.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/core/vm/sqlvm/sqlvm.go b/core/vm/sqlvm/sqlvm.go new file mode 100644 index 000000000..258a65d01 --- /dev/null +++ b/core/vm/sqlvm/sqlvm.go @@ -0,0 +1,50 @@ +package sqlvm + +import ( + "math/big" + + "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/core/vm" + "github.com/dexon-foundation/dexon/crypto" + "github.com/dexon-foundation/dexon/params" +) + +type SQLVM struct { + // Context provides auxiliary blockchain related information + vm.Context + // StateDB gives access to the underlying state + StateDB vm.StateDB + // Depth is the current call stack + depth int + + // chainConfig contains information about the current chain + chainConfig *params.ChainConfig + // chain rules contains the chain rules for the current epoch + chainRules params.Rules + // abort is used to abort the SQLVM calling operations + // NOTE: must be set atomically + abort int32 + // callGasTemp holds the gas available for the current call. This is needed because the + // available gas is calculated in gasCall* according to the 63/64 rule and later + // applied in opCall*. + callGasTemp uint64 +} + +func (sqlvm *SQLVM) Create(caller vm.ContractRef, code []byte, gas uint64, + value *big.Int) (ret []byte, contractAddr common.Address, + leftOverGas uint64, err error) { + + contractAddr = crypto.CreateAddress(caller.Address(), sqlvm.StateDB.GetNonce(caller.Address())) + return sqlvm.create(caller, &vm.CodeAndHash{Code: code}, gas, value, contractAddr) +} + +// create creates a new contract using code as deployment code. +func (sqlvm *SQLVM) create(caller vm.ContractRef, codeAndHash *vm.CodeAndHash, gas uint64, + value *big.Int, address common.Address) ([]byte, common.Address, uint64, error) { + // Depth check execution. Fail if we're trying to execute above the + if sqlvm.depth > int(params.CallCreateDepth) { + return nil, common.Address{}, gas, vm.ErrDepth + } + // TODO (JM) implement create database contract function + return nil, common.Address{}, gas, nil +} |