/
tx.go
72 lines (62 loc) · 1.99 KB
/
tx.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package types
import (
"math"
"math/big"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
// EvmTxArgs encapsulates all possible params to create all EVM txs types.
// This includes LegacyTx, DynamicFeeTx and AccessListTx
type EvmTxArgs struct {
Nonce uint64
GasLimit uint64
Input []byte
GasFeeCap *big.Int
GasPrice *big.Int
ChainID *big.Int
Amount *big.Int
GasTipCap *big.Int
To *common.Address
Accesses *ethtypes.AccessList
}
// GetTxPriority returns the priority of a given Ethereum tx. It relies of the
// priority reduction global variable to calculate the tx priority given the tx
// tip price:
//
// tx_priority = tip_price / priority_reduction
func GetTxPriority(txData TxData, baseFee *big.Int) (priority int64) {
// calculate priority based on effective gas price
tipPrice := txData.EffectiveGasPrice(baseFee)
// if london hardfork is not enabled, tipPrice is the gasPrice
if baseFee != nil {
tipPrice = new(big.Int).Sub(tipPrice, baseFee)
}
priority = math.MaxInt64
priorityBig := new(big.Int).Quo(tipPrice, DefaultPriorityReduction.BigInt())
// safety check
if priorityBig.IsInt64() {
priority = priorityBig.Int64()
}
return priority
}
// Failed returns if the contract execution failed in vm errors
func (m *MsgEthereumTxResponse) Failed() bool {
return len(m.VmError) > 0
}
// Return is a helper function to help caller distinguish between revert reason
// and function return. Return returns the data after execution if no error occurs.
func (m *MsgEthereumTxResponse) Return() []byte {
if m.Failed() {
return nil
}
return common.CopyBytes(m.Ret)
}
// Revert returns the concrete revert reason if the execution is aborted by `REVERT`
// opcode. Note the reason can be nil if no data supplied with revert opcode.
func (m *MsgEthereumTxResponse) Revert() []byte {
if m.VmError != vm.ErrExecutionReverted.Error() {
return nil
}
return common.CopyBytes(m.Ret)
}