Skip to content

Commit

Permalink
Add fee-currency-context to backend.NewEVM constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ezdac committed Aug 5, 2024
1 parent d5fef79 commit 9c84c83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions contracts/celo_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions contracts/fee_currencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c84c83

Please sign in to comment.