Skip to content

Commit

Permalink
Added GasTipCap method (#89)
Browse files Browse the repository at this point in the history
* Added GasTipCap method

* update `GasTipCap` doc

* test fixes

---------

Co-authored-by: lmittmann <3458786+lmittmann@users.noreply.github.com>
Signed-off-by: Mohammed Sohail <sohailsameja@gmail.com>
  • Loading branch information
2 people authored and kamikazechaser committed Feb 2, 2024
1 parent ba435f8 commit e49bb1f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ List of supported RPC methods.
| `eth_createAccessList` | `eth.AccessList(msg *w3types.Message, blockNumber *big.Int).Returns(resp *eth.AccessListResponse)`
| `eth_estimateGas` | `eth.EstimateGas(msg *w3types.Message, blockNumber *big.Int).Returns(gas *uint64)`
| `eth_gasPrice` | `eth.GasPrice().Returns(gasPrice *big.Int)`
| `eth_maxPriorityFeePerGas` | `eth.GasTipCap().Returns(gasTipCap *big.Int)`
| `eth_getBalance` | `eth.Balance(addr common.Address, blockNumber *big.Int).Returns(balance *big.Int)`
| `eth_getBlockByHash` | `eth.BlockByHash(hash common.Hash).Returns(block *types.Block)`<br>`eth.HeaderByHash(hash common.Hash).Returns(header *types.Header)`
| `eth_getBlockByNumber` | `eth.BlockByNumber(number *big.Int).Returns(block *types.Block)`<br>`eth.HeaderByNumber(number *big.Int).Returns(header *types.Header)`
Expand Down
18 changes: 18 additions & 0 deletions module/eth/gas_tip_cap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package eth

import (
"math/big"

"github.com/lmittmann/w3/internal/module"
"github.com/lmittmann/w3/w3types"
)

// GasTipCap requests the currently suggested gas tip cap after EIP-1559 to
// allow a timely execution of a transaction.
func GasTipCap() w3types.CallerFactory[big.Int] {
return module.NewFactory(
"eth_maxPriorityFeePerGas",
nil,
module.WithRetWrapper(module.HexBigRetWrapper),
)
}
22 changes: 22 additions & 0 deletions module/eth/gas_tip_cap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eth_test

import (
"math/big"
"testing"

"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
"github.com/lmittmann/w3/rpctest"
)

func TestGasTipCap(t *testing.T) {
tests := []rpctest.TestCase[big.Int]{
{
Golden: "gas_tip_cap",
Call: eth.GasTipCap(),
WantRet: *w3.I("0xc0fe"),
},
}

rpctest.RunTestCases(t, tests)
}
2 changes: 2 additions & 0 deletions module/eth/testdata/gas_tip_cap.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> {"jsonrpc":"2.0","id":1,"method":"eth_maxPriorityFeePerGas"}
< {"jsonrpc":"2.0","id":1,"result":"0xc0fe"}

0 comments on commit e49bb1f

Please sign in to comment.