diff options
author | jm <jm.huang@cobinhood.com> | 2019-01-16 17:32:29 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-04-11 10:39:57 +0800 |
commit | 034d4756e7c95af12f88f89fb8bfa72bfa319e2d (patch) | |
tree | 82cfd6871655f53330aa8820fc6509355124bff7 /core/vm/sqlvm | |
parent | 892743b3c09559c62109c2d0e9fe90b31ef8f049 (diff) | |
download | dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar.gz dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar.bz2 dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar.lz dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar.xz dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.tar.zst dexon-034d4756e7c95af12f88f89fb8bfa72bfa319e2d.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 +} |