-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtransaction_overlay.go
56 lines (50 loc) · 1.97 KB
/
transaction_overlay.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
package evm
import (
"math/big"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ten-protocol/go-ten/go/common"
)
// TransactionToMessageWithOverrides is used to convert a transaction to a message to be applied to the evm.
// Overrides can change how stuff in the message is derived, e.g. the sender. This is useful for synthetic transactions,
// where we do not want to do signature validation or have a private key.
func TransactionToMessageWithOverrides(
tx *common.L2PricedTransaction,
config *params.ChainConfig,
header *types.Header,
) (*core.Message, error) {
// Override from can be used for calling system contracts from underivable addresses like all zeroes
if tx.SystemDeployer {
msg := TransactionToMessageNoSender(tx.Tx, header.BaseFee)
msg.From = common.MaskedSender(gethcommon.BigToAddress(big.NewInt(tx.Tx.ChainId().Int64())))
return msg, nil
} else if tx.FromSelf {
msg := TransactionToMessageNoSender(tx.Tx, header.BaseFee)
msg.From = common.MaskedSender(*tx.Tx.To())
return msg, nil
}
return core.TransactionToMessage(tx.Tx, types.MakeSigner(config, header.Number, header.Time), header.BaseFee)
}
func TransactionToMessageNoSender(tx *types.Transaction, baseFee *big.Int) *core.Message {
msg := &core.Message{
Nonce: tx.Nonce(),
GasLimit: tx.Gas(),
GasPrice: new(big.Int).Set(tx.GasPrice()),
GasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
GasTipCap: new(big.Int).Set(tx.GasTipCap()),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
SkipFromEOACheck: false,
SkipNonceChecks: false,
BlobHashes: tx.BlobHashes(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
}
if baseFee != nil {
msg.GasPrice = common.BigMin(msg.GasPrice.Add(msg.GasTipCap, baseFee), msg.GasFeeCap)
}
return msg
}