-
Notifications
You must be signed in to change notification settings - Fork 328
/
evm_transaction.go
39 lines (34 loc) · 1.07 KB
/
evm_transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2024 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
package action
import (
"math/big"
"github.com/iotexproject/iotex-proto/golang/iotextypes"
)
type (
// TxDataForSimulation is the interface to run a simulation
TxDataForSimulation interface {
TxData
SanityCheck() error
Proto() *iotextypes.ActionCore
}
)
// EffectiveGas returns the effective gas
func EffectiveGasTip(tx TxDynamicGas, baseFee *big.Int) (*big.Int, error) {
tip := tx.GasTipCap()
if baseFee == nil {
return tip, nil
}
effectiveGas := tx.GasFeeCap()
effectiveGas.Sub(effectiveGas, baseFee)
if effectiveGas.Sign() < 0 {
return effectiveGas, ErrGasFeeCapTooLow
}
// effective gas = min(tip, feeCap - baseFee)
if effectiveGas.Cmp(tip) <= 0 {
return effectiveGas, nil
}
return tip, nil
}