Skip to content

Commit 18e8f3c

Browse files
committed
refactor GenerateTransaction
1 parent 65c8b94 commit 18e8f3c

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

pkg/coordinator/tasks/tx_pool_throughput_analysis/transaction.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,35 @@ func NewTransactionGenerator(task *Task) *TransactionGenerator {
2222
}
2323
}
2424

25+
// buildDynamicFeeTx constructs a dynamic fee transaction for the wallet
26+
func (g *TransactionGenerator) buildDynamicFeeTx(_ context.Context, nonce uint64, _ bind.SignerFn) (*ethtypes.Transaction, error) {
27+
addr := g.task.wallet.GetAddress()
28+
toAddr := &addr
29+
30+
txAmount, _ := crand.Int(crand.Reader, big.NewInt(0).SetUint64(10*1e18))
31+
32+
feeCap := &helper.BigInt{Value: *big.NewInt(100000000000)} // 100 Gwei
33+
tipCap := &helper.BigInt{Value: *big.NewInt(1000000000)} // 1 Gwei
34+
35+
var txObj ethtypes.TxData
36+
37+
txObj = &ethtypes.DynamicFeeTx{
38+
ChainID: g.task.ctx.Scheduler.GetServices().ClientPool().GetExecutionPool().GetBlockCache().GetChainID(),
39+
Nonce: nonce,
40+
GasTipCap: &tipCap.Value,
41+
GasFeeCap: &feeCap.Value,
42+
Gas: 50000,
43+
To: toAddr,
44+
Value: txAmount,
45+
Data: []byte{},
46+
}
47+
48+
return ethtypes.NewTx(txObj), nil
49+
}
50+
2551
// GenerateTransaction creates a new transaction
2652
func (g *TransactionGenerator) GenerateTransaction(ctx context.Context) (*ethtypes.Transaction, error) {
27-
tx, err := g.task.wallet.BuildTransaction(ctx, func(_ context.Context, nonce uint64, _ bind.SignerFn) (*ethtypes.Transaction, error) {
28-
addr := g.task.wallet.GetAddress()
29-
toAddr := &addr
30-
31-
txAmount, _ := crand.Int(crand.Reader, big.NewInt(0).SetUint64(10*1e18))
32-
33-
feeCap := &helper.BigInt{Value: *big.NewInt(100000000000)} // 100 Gwei
34-
tipCap := &helper.BigInt{Value: *big.NewInt(1000000000)} // 1 Gwei
35-
36-
var txObj ethtypes.TxData
37-
38-
txObj = &ethtypes.DynamicFeeTx{
39-
ChainID: g.task.ctx.Scheduler.GetServices().ClientPool().GetExecutionPool().GetBlockCache().GetChainID(),
40-
Nonce: nonce,
41-
GasTipCap: &tipCap.Value,
42-
GasFeeCap: &feeCap.Value,
43-
Gas: 50000,
44-
To: toAddr,
45-
Value: txAmount,
46-
Data: []byte{},
47-
}
48-
49-
return ethtypes.NewTx(txObj), nil
50-
})
53+
tx, err := g.task.wallet.BuildTransaction(ctx, g.buildDynamicFeeTx)
5154

5255
if err != nil {
5356
return nil, err

0 commit comments

Comments
 (0)