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/state_transition.go | |
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/state_transition.go')
-rw-r--r-- | core/state_transition.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/core/state_transition.go b/core/state_transition.go index fddb187af..a9a700c2b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm/sqlvm" "github.com/dexon-foundation/dexon/log" "github.com/dexon-foundation/dexon/params" ) @@ -70,8 +71,9 @@ type StateTransition struct { initialGas uint64 value *big.Int data []byte - state evm.StateDB + state vm.StateDB evm *evm.EVM + sqlvm *sqlvm.SQLVM } // Message represents a message sent to a contract. @@ -246,7 +248,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo return } msg := st.msg - sender := evm.AccountRef(msg.From()) + sender := vm.AccountRef(msg.From()) homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber) contractCreation := msg.To() == nil @@ -260,14 +262,19 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo } var ( - evm = st.evm + evm = st.evm + sqlvm = st.sqlvm // vm errors do not effect consensus and are therefor // not assigned to err, except for insufficient balance // error. vmerr error ) if contractCreation { - ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value) + if len(st.data) != 0 && st.data[0] == 0xed { + ret, _, st.gas, vmerr = sqlvm.Create(sender, st.data, st.gas, st.value) + } else { + ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value) + } } else { // Increment the nonce for the next transaction st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1) |