ethclient/simulated: add function to create a type 0x04 transaction

This commit is contained in:
tr1sm0s1n 2025-03-02 00:09:48 +05:30
parent 31c972febf
commit 2ca14aa5f0
No known key found for this signature in database
GPG key ID: 0F30FF07CAB2F87A

View file

@ -54,6 +54,41 @@ func simTestBackend(testAddr common.Address) *Backend {
)
}
func newSetCodeTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
client := sim.Client()
head, _ := client.HeaderByNumber(context.Background(), nil)
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))
addr := crypto.PubkeyToAddress(key.PublicKey)
chainid, _ := client.ChainID(context.Background())
nonce, err := client.PendingNonceAt(context.Background(), addr)
if err != nil {
return nil, err
}
auth := types.SetCodeAuthorization{
ChainID: *uint256.NewInt(chainid.Uint64()),
Address: addr,
Nonce: nonce,
}
auth, err = types.SignSetCode(key, auth)
if err != nil {
return nil, err
}
tx := types.NewTx(&types.SetCodeTx{
ChainID: uint256.NewInt(chainid.Uint64()),
Nonce: nonce,
GasTipCap: uint256.NewInt(params.GWei),
GasFeeCap: uint256.NewInt(gasPrice.Uint64()),
Gas: 46000,
To: addr,
AuthList: []types.SetCodeAuthorization{auth},
})
return types.SignTx(tx, types.LatestSignerForChainID(chainid), key)
}
func newBlobTx(sim *Backend, key *ecdsa.PrivateKey) (*types.Transaction, error) {
client := sim.Client()