Skip to content

Commit

Permalink
Merge pull request #42 from siburu/fix/both-gasprice-and-maxfeepergas…
Browse files Browse the repository at this point in the history
…-or-maxpriorityfeepergas-specificied

[BUGFIX] Set only the fields of CallMsg required for each tx type
  • Loading branch information
siburu authored May 2, 2024
2 parents c08b4a6 + f01f289 commit 58c30b0
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,33 @@ func (cl *ETHClient) EstimateGasFromTx(ctx context.Context, tx *gethtypes.Transa
if err != nil {
return 0, err
}
to := tx.To()
value := tx.Value()
gasTipCap := tx.GasTipCap()
gasFeeCap := tx.GasFeeCap()
gasPrice := tx.GasPrice()
data := tx.Data()
accessList := tx.AccessList()

callMsg := ethereum.CallMsg{
From: from,
To: to,
GasPrice: gasPrice,
GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap,
Value: value,
Data: data,
AccessList: accessList,
}
estimatedGas, err := cl.EstimateGas(ctx, callMsg)
if err != nil {
return 0, err
}
return estimatedGas, nil
From: from,
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
}

switch tx.Type() {
case gethtypes.BlobTxType:
callMsg.GasTipCap = tx.GasTipCap()
callMsg.GasFeeCap = tx.GasFeeCap()
callMsg.AccessList = tx.AccessList()
callMsg.BlobGasFeeCap = tx.BlobGasFeeCap()
callMsg.BlobHashes = tx.BlobHashes()
case gethtypes.DynamicFeeTxType:
callMsg.GasTipCap = tx.GasTipCap()
callMsg.GasFeeCap = tx.GasFeeCap()
callMsg.AccessList = tx.AccessList()
case gethtypes.AccessListTxType:
callMsg.GasPrice = tx.GasPrice()
callMsg.AccessList = tx.AccessList()
case gethtypes.LegacyTxType:
callMsg.GasPrice = tx.GasPrice()
default:
panic("unsupported tx type")
}

return cl.EstimateGas(ctx, callMsg)
}

0 comments on commit 58c30b0

Please sign in to comment.