From 1d6cb3517885c1015a6221f1771f18a2d6eff54e Mon Sep 17 00:00:00 2001 From: Paul Lange Date: Tue, 7 Nov 2023 16:38:24 +0100 Subject: [PATCH] Clean up `StateTransition` struct Also change `StateDB` type in `CeloBackend` --- core/celo_backend.go | 3 +-- core/state_transition.go | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/core/celo_backend.go b/core/celo_backend.go index 1d5a367d31..370b814d65 100644 --- a/core/celo_backend.go +++ b/core/celo_backend.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/params" ) @@ -15,7 +14,7 @@ import ( // access core contracts during block processing. type CeloBackend struct { chainConfig *params.ChainConfig - state *state.StateDB + state vm.StateDB } // ContractCaller implementation diff --git a/core/state_transition.go b/core/state_transition.go index 7a5c3b66aa..2151d98b9b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -252,24 +252,15 @@ type StateTransition struct { initialGas uint64 state vm.StateDB evm *vm.EVM - - // Celo additions - backend *CeloBackend } // NewStateTransition initialises and returns a new state transition object. func NewStateTransition(evm *vm.EVM, msg *Message, gp *GasPool) *StateTransition { - backend := &CeloBackend{ - chainConfig: nil, - state: nil, - } - return &StateTransition{ - gp: gp, - evm: evm, - msg: msg, - state: evm.StateDB, - backend: backend, + gp: gp, + evm: evm, + msg: msg, + state: evm.StateDB, } } @@ -344,7 +335,11 @@ func (st *StateTransition) canPayFee(checkAmount *big.Int) error { return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From.Hex(), balance, checkAmount) } } else { - balance, err := contracts.GetBalanceOf(st.backend, st.msg.From, *st.msg.FeeCurrency) + backend := &CeloBackend{ + chainConfig: st.evm.ChainConfig(), + state: st.state, + } + balance, err := contracts.GetBalanceOf(backend, st.msg.From, *st.msg.FeeCurrency) if err != nil { return err }