From 266068a53cdf9e06acacf982d63653c03133a634 Mon Sep 17 00:00:00 2001 From: jm Date: Tue, 15 Jan 2019 00:48:13 +0800 Subject: core: vm: refactor file structure For support other vm types, this pr modified the core/vm file structures. --- core/state_transition.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'core/state_transition.go') diff --git a/core/state_transition.go b/core/state_transition.go index f5ac9bde6..fddb187af 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -26,6 +26,7 @@ import ( dexCore "github.com/dexon-foundation/dexon-consensus/core" "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/log" "github.com/dexon-foundation/dexon/params" ) @@ -69,8 +70,8 @@ type StateTransition struct { initialGas uint64 value *big.Int data []byte - state vm.StateDB - evm *vm.EVM + state evm.StateDB + evm *evm.EVM } // Message represents a message sent to a contract. @@ -122,7 +123,7 @@ func IntrinsicGas(data []byte, contractCreation, homestead bool) (uint64, error) } // NewStateTransition initialises and returns a new state transition object. -func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition { +func NewStateTransition(evm *evm.EVM, msg Message, gp *GasPool) *StateTransition { return &StateTransition{ gp: gp, evm: evm, @@ -141,7 +142,7 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition // the gas used (which includes gas refunds) and an error if it failed. An error always // indicates a core error meaning that the message would always fail for that particular // state and would never be accepted within a block. -func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) { +func ApplyMessage(evm *evm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) { return NewStateTransition(evm, msg, gp).TransitionDb() } @@ -205,7 +206,7 @@ func (st *StateTransition) inExtendedRound() bool { } } - gs := vm.GovernanceState{st.state} + gs := evm.GovernanceState{st.state} round := st.evm.Round.Uint64() if round < dexCore.ConfigRoundShift { @@ -219,7 +220,7 @@ func (st *StateTransition) inExtendedRound() bool { if err != nil { panic(err) } - rgs := vm.GovernanceState{state} + rgs := evm.GovernanceState{state} roundEnd := gs.RoundHeight(st.evm.Round).Uint64() + rgs.RoundLength().Uint64() @@ -245,7 +246,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo return } msg := st.msg - sender := vm.AccountRef(msg.From()) + sender := evm.AccountRef(msg.From()) homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber) contractCreation := msg.To() == nil @@ -290,7 +291,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo receiver := st.evm.Coinbase if !*legacyEvm && st.inExtendedRound() { - gs := vm.GovernanceState{st.state} + gs := evm.GovernanceState{st.state} receiver = gs.Owner() } -- cgit v1.2.3