From 9c84c83fa1533fd1ce038e2550b227e23d7286ba Mon Sep 17 00:00:00 2001 From: Maximilian Langenfeld <15726643+ezdac@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:07:20 +0200 Subject: [PATCH] Add fee-currency-context to backend.NewEVM constructor --- contracts/celo_backend.go | 9 +++++++-- contracts/fee_currencies.go | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/celo_backend.go b/contracts/celo_backend.go index d3133c783e..b6e8e1e008 100644 --- a/contracts/celo_backend.go +++ b/contracts/celo_backend.go @@ -57,14 +57,19 @@ func (b *CeloBackend) CallContract(ctx context.Context, call ethereum.CallMsg, b // Get a vm.EVM object of you can't use the abi wrapper via the ContractCaller interface // This is usually the case when executing functions that modify state. -func (b *CeloBackend) NewEVM() *vm.EVM { - blockCtx := vm.BlockContext{BlockNumber: new(big.Int), Time: 0, +func (b *CeloBackend) NewEVM(feeCurrencyContext *common.FeeCurrencyContext) *vm.EVM { + blockCtx := vm.BlockContext{ + BlockNumber: new(big.Int), + Time: 0, Transfer: func(state vm.StateDB, from common.Address, to common.Address, value *uint256.Int) { if value.Cmp(common.U2560) != 0 { panic("Non-zero transfers not implemented, yet.") } }, } + if feeCurrencyContext != nil { + blockCtx.FeeCurrencyContext = *feeCurrencyContext + } txCtx := vm.TxContext{} vmConfig := vm.Config{} return vm.NewEVM(blockCtx, txCtx, b.State, b.ChainConfig, vmConfig) diff --git a/contracts/fee_currencies.go b/contracts/fee_currencies.go index a92bd99d24..88e9771ae7 100644 --- a/contracts/fee_currencies.go +++ b/contracts/fee_currencies.go @@ -33,8 +33,7 @@ func TryDebitFees(tx *types.Transaction, from common.Address, backend *CeloBacke amount.Mul(amount, tx.GasFeeCap()) snapshot := backend.State.Snapshot() - evm := backend.NewEVM() - evm.Context.FeeCurrencyContext = feeContext + evm := backend.NewEVM(&feeContext) _, err := DebitFees(evm, tx.FeeCurrency(), from, amount) backend.State.RevertToSnapshot(snapshot) return err