Skip to content

Commit

Permalink
updated interface names
Browse files Browse the repository at this point in the history
  • Loading branch information
lmittmann committed Feb 1, 2024
1 parent a725232 commit 12cdd62
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions client.go
Expand Up @@ -73,7 +73,7 @@ func (c *Client) Close() error {
//
// An error is returned if RPC request creation, networking, or RPC response
// handling fails.
func (c *Client) CallCtx(ctx context.Context, calls ...w3types.Caller) error {
func (c *Client) CallCtx(ctx context.Context, calls ...w3types.RPCCaller) error {
// no requests = nothing to do
if len(calls) <= 0 {
return nil
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *Client) CallCtx(ctx context.Context, calls ...w3types.Caller) error {
}

// Call is like [Client.CallCtx] with ctx equal to context.Background().
func (c *Client) Call(calls ...w3types.Caller) error {
func (c *Client) Call(calls ...w3types.RPCCaller) error {
return c.CallCtx(context.Background(), calls...)
}

Expand Down
22 changes: 11 additions & 11 deletions client_test.go
Expand Up @@ -106,50 +106,50 @@ func ExampleClient_Call_nonceAndBalance() {
func TestClientCall(t *testing.T) {
tests := []struct {
Buf *bytes.Buffer
Calls []w3types.Caller
Calls []w3types.RPCCaller
WantErr error
}{
{
Buf: bytes.NewBufferString(jsonCalls1),
Calls: []w3types.Caller{&testCaller{}},
Calls: []w3types.RPCCaller{&testCaller{}},
},
{
Buf: bytes.NewBufferString(jsonCalls1),
Calls: []w3types.Caller{&testCaller{RequestErr: errors.New("err")}},
Calls: []w3types.RPCCaller{&testCaller{RequestErr: errors.New("err")}},
WantErr: errors.New("err"),
},
{
Buf: bytes.NewBufferString(jsonCalls1),
Calls: []w3types.Caller{&testCaller{ReturnErr: errors.New("err")}},
Calls: []w3types.RPCCaller{&testCaller{ReturnErr: errors.New("err")}},
WantErr: errors.New("w3: call failed: err"),
},
{
Buf: bytes.NewBufferString(jsonCalls2),
Calls: []w3types.Caller{
Calls: []w3types.RPCCaller{
&testCaller{RequestErr: errors.New("err")},
&testCaller{},
},
WantErr: errors.New("err"),
},
{
Buf: bytes.NewBufferString(jsonCalls2),
Calls: []w3types.Caller{
Calls: []w3types.RPCCaller{
&testCaller{ReturnErr: errors.New("err")},
&testCaller{},
},
WantErr: errors.New("w3: 1 call failed:\ncall[0]: err"),
},
{
Buf: bytes.NewBufferString(jsonCalls2),
Calls: []w3types.Caller{
Calls: []w3types.RPCCaller{
&testCaller{},
&testCaller{ReturnErr: errors.New("err")},
},
WantErr: errors.New("w3: 1 call failed:\ncall[1]: err"),
},
{
Buf: bytes.NewBufferString(jsonCalls2),
Calls: []w3types.Caller{
Calls: []w3types.RPCCaller{
&testCaller{ReturnErr: errors.New("err")},
&testCaller{ReturnErr: errors.New("err")},
},
Expand Down Expand Up @@ -266,7 +266,7 @@ func BenchmarkCall_Balance100(b *testing.B) {
b.Run("Batch", func(b *testing.B) {
var balance big.Int
for i := 0; i < b.N; i++ {
requests := make([]w3types.Caller, len(addr100))
requests := make([]w3types.RPCCaller, len(addr100))
for j := 0; j < len(requests); j++ {
requests[j] = eth.Balance(addr100[j], nil).Returns(&balance)
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func BenchmarkCall_BalanceOf100(b *testing.B) {
b.Run("Batch", func(b *testing.B) {
var balance big.Int
for i := 0; i < b.N; i++ {
requests := make([]w3types.Caller, len(addr100))
requests := make([]w3types.RPCCaller, len(addr100))
for j := 0; j < len(requests); j++ {
requests[j] = eth.CallFunc(addrWeth9, funcBalanceOf, addr100[j]).Returns(&balance)
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func BenchmarkCall_Block100(b *testing.B) {
b.Run("Batch", func(b *testing.B) {
var block types.Block
for i := 0; i < b.N; i++ {
requests := make([]w3types.Caller, len(block100))
requests := make([]w3types.RPCCaller, len(block100))
for j := 0; j < len(requests); j++ {
requests[j] = eth.BlockByNumber(block100[j]).Returns(&block)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/scan_blocks/main.go
Expand Up @@ -47,7 +47,7 @@ func main() {
defer client.Close()

// fetch blocks in bulk
calls := make([]w3types.Caller, bulkSize)
calls := make([]w3types.RPCCaller, bulkSize)
blocks := make([]types.Block, bulkSize)

for i, txCount := 0, 0; ; i++ {
Expand Down
2 changes: 1 addition & 1 deletion examples/uniswap_quote/main.go
Expand Up @@ -83,7 +83,7 @@ func main() {
// fetch quotes
var (
fees = []*big.Int{big.NewInt(100), big.NewInt(500), big.NewInt(3000), big.NewInt(10000)}
calls = make([]w3types.Caller, len(fees))
calls = make([]w3types.RPCCaller, len(fees))
amountsOut = make([]big.Int, len(fees))
)
for i, fee := range fees {
Expand Down
2 changes: 1 addition & 1 deletion internal/module/factory.go
Expand Up @@ -43,7 +43,7 @@ func NewFactory[T any](method string, args []any, opts ...Option[T]) *Factory[T]
return f
}

func (f Factory[T]) Returns(ret *T) w3types.Caller {
func (f Factory[T]) Returns(ret *T) w3types.RPCCaller {
f.ret = ret
return f
}
Expand Down
4 changes: 2 additions & 2 deletions module/debug/call_trace.go
Expand Up @@ -11,7 +11,7 @@ import (
)

// CallTraceCall requests the call trace of the given message.
func CallTraceCall(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w3types.CallerFactory[CallTrace] {
func CallTraceCall(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w3types.RPCCallerFactory[CallTrace] {
return module.NewFactory(
"debug_traceCall",
[]any{msg, module.BlockNumberArg(blockNumber), &traceConfig{Tracer: "callTracer", Overrides: overrides}},
Expand All @@ -20,7 +20,7 @@ func CallTraceCall(msg *w3types.Message, blockNumber *big.Int, overrides w3types
}

// CallTraceTx requests the call trace of the transaction with the given hash.
func CallTraceTx(txHash common.Hash, overrides w3types.State) w3types.CallerFactory[CallTrace] {
func CallTraceTx(txHash common.Hash, overrides w3types.State) w3types.RPCCallerFactory[CallTrace] {
return module.NewFactory[CallTrace](
"debug_traceTransaction",
[]any{txHash, &traceConfig{Tracer: "callTracer", Overrides: overrides}},
Expand Down
4 changes: 2 additions & 2 deletions module/debug/trace.go
Expand Up @@ -14,7 +14,7 @@ import (
)

// TraceCall requests the trace of the given message.
func TraceCall(msg *w3types.Message, blockNumber *big.Int, config *TraceConfig) w3types.CallerFactory[Trace] {
func TraceCall(msg *w3types.Message, blockNumber *big.Int, config *TraceConfig) w3types.RPCCallerFactory[Trace] {
if config == nil {
config = &TraceConfig{}
}
Expand All @@ -26,7 +26,7 @@ func TraceCall(msg *w3types.Message, blockNumber *big.Int, config *TraceConfig)
}

// TraceTx requests the trace of the transaction with the given hash.
func TraceTx(txHash common.Hash, config *TraceConfig) w3types.CallerFactory[Trace] {
func TraceTx(txHash common.Hash, config *TraceConfig) w3types.RPCCallerFactory[Trace] {
if config == nil {
config = &TraceConfig{}
}
Expand Down
2 changes: 1 addition & 1 deletion module/eth/balance.go
Expand Up @@ -11,7 +11,7 @@ import (
// Balance requests the balance of the given common.Address addr at the given
// blockNumber. If blockNumber is nil, the balance at the latest known block is
// requested.
func Balance(addr common.Address, blockNumber *big.Int) w3types.CallerFactory[big.Int] {
func Balance(addr common.Address, blockNumber *big.Int) w3types.RPCCallerFactory[big.Int] {
return module.NewFactory(
"eth_getBalance",
[]any{addr, module.BlockNumberArg(blockNumber)},
Expand Down
12 changes: 6 additions & 6 deletions module/eth/block.go
Expand Up @@ -11,7 +11,7 @@ import (
)

// BlockByHash requests the block with the given hash with full transactions.
func BlockByHash(hash common.Hash) w3types.CallerFactory[types.Block] {
func BlockByHash(hash common.Hash) w3types.RPCCallerFactory[types.Block] {
return module.NewFactory(
"eth_getBlockByHash",
[]any{hash, true},
Expand All @@ -21,7 +21,7 @@ func BlockByHash(hash common.Hash) w3types.CallerFactory[types.Block] {

// BlockByNumber requests the block with the given number with full
// transactions. If number is nil, the latest block is requested.
func BlockByNumber(number *big.Int) w3types.CallerFactory[types.Block] {
func BlockByNumber(number *big.Int) w3types.RPCCallerFactory[types.Block] {
return module.NewFactory(
"eth_getBlockByNumber",
[]any{module.BlockNumberArg(number), true},
Expand All @@ -31,7 +31,7 @@ func BlockByNumber(number *big.Int) w3types.CallerFactory[types.Block] {

// BlockTxCountByHash requests the number of transactions in the block with the
// given hash.
func BlockTxCountByHash(hash common.Hash) w3types.CallerFactory[uint] {
func BlockTxCountByHash(hash common.Hash) w3types.RPCCallerFactory[uint] {
return module.NewFactory(
"eth_getBlockTransactionCountByHash",
[]any{hash},
Expand All @@ -41,7 +41,7 @@ func BlockTxCountByHash(hash common.Hash) w3types.CallerFactory[uint] {

// BlockTxCountByNumber requests the number of transactions in the block with
// the given number.
func BlockTxCountByNumber(number *big.Int) w3types.CallerFactory[uint] {
func BlockTxCountByNumber(number *big.Int) w3types.RPCCallerFactory[uint] {
return module.NewFactory(
"eth_getBlockTransactionCountByNumber",
[]any{module.BlockNumberArg(number)},
Expand All @@ -50,7 +50,7 @@ func BlockTxCountByNumber(number *big.Int) w3types.CallerFactory[uint] {
}

// HeaderByHash requests the header with the given hash.
func HeaderByHash(hash common.Hash) w3types.CallerFactory[types.Header] {
func HeaderByHash(hash common.Hash) w3types.RPCCallerFactory[types.Header] {
return module.NewFactory[types.Header](
"eth_getBlockByHash",
[]any{hash, false},
Expand All @@ -59,7 +59,7 @@ func HeaderByHash(hash common.Hash) w3types.CallerFactory[types.Header] {

// HeaderByNumber requests the header with the given number. If number is nil,
// the latest header is requested.
func HeaderByNumber(number *big.Int) w3types.CallerFactory[types.Header] {
func HeaderByNumber(number *big.Int) w3types.RPCCallerFactory[types.Header] {
return module.NewFactory[types.Header](
"eth_getBlockByNumber",
[]any{module.BlockNumberArg(number), false},
Expand Down
2 changes: 1 addition & 1 deletion module/eth/block_number.go
Expand Up @@ -8,7 +8,7 @@ import (
)

// BlockNumber requests the number of the most recent block.
func BlockNumber() w3types.CallerFactory[big.Int] {
func BlockNumber() w3types.RPCCallerFactory[big.Int] {
return module.NewFactory(
"eth_blockNumber",
nil,
Expand Down
8 changes: 4 additions & 4 deletions module/eth/call.go
Expand Up @@ -15,7 +15,7 @@ import (
// Call requests the output data of the given message at the given blockNumber.
// If blockNumber is nil, the output of the message at the latest known block is
// requested.
func Call(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w3types.CallerFactory[[]byte] {
func Call(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w3types.RPCCallerFactory[[]byte] {
args := []any{msg, module.BlockNumberArg(blockNumber)}
if overrides != nil {
args = append(args, overrides)
Expand All @@ -32,7 +32,7 @@ func Call(msg *w3types.Message, blockNumber *big.Int, overrides w3types.State) w
// EstimateGas requests the estimated gas cost of the given message at the given
// blockNumber. If blockNumber is nil, the estimated gas cost of the message at
// the latest block is requested.
func EstimateGas(msg *w3types.Message, blockNumber *big.Int) w3types.CallerFactory[uint64] {
func EstimateGas(msg *w3types.Message, blockNumber *big.Int) w3types.RPCCallerFactory[uint64] {
return module.NewFactory(
"eth_estimateGas",
[]any{msg, module.BlockNumberArg(blockNumber)},
Expand All @@ -44,7 +44,7 @@ func EstimateGas(msg *w3types.Message, blockNumber *big.Int) w3types.CallerFacto
// AccessList requests the access list of the given message at the given
// blockNumber. If blockNumber is nil, the access list of the message at the
// latest block is requested.
func AccessList(msg *w3types.Message, blockNumber *big.Int) w3types.CallerFactory[AccessListResponse] {
func AccessList(msg *w3types.Message, blockNumber *big.Int) w3types.RPCCallerFactory[AccessListResponse] {
return module.NewFactory(
"eth_createAccessList",
[]any{msg, module.BlockNumberArg(blockNumber)},
Expand Down Expand Up @@ -110,7 +110,7 @@ type CallFuncFactory struct {
returns []any
}

func (f *CallFuncFactory) Returns(returns ...any) w3types.Caller {
func (f *CallFuncFactory) Returns(returns ...any) w3types.RPCCaller {
f.returns = returns
return f
}
Expand Down
2 changes: 1 addition & 1 deletion module/eth/chain_id.go
Expand Up @@ -6,7 +6,7 @@ import (
)

// ChainID requests the chains ID.
func ChainID() w3types.CallerFactory[uint64] {
func ChainID() w3types.RPCCallerFactory[uint64] {
return module.NewFactory(
"eth_chainId",
nil,
Expand Down
2 changes: 1 addition & 1 deletion module/eth/code.go
Expand Up @@ -11,7 +11,7 @@ import (
// Code requests the code of the given common.Address addr at the given
// blockNumber. If blockNumber is nil, the code at the latest known block is
// requested.
func Code(addr common.Address, blockNumber *big.Int) w3types.CallerFactory[[]byte] {
func Code(addr common.Address, blockNumber *big.Int) w3types.RPCCallerFactory[[]byte] {
return module.NewFactory(
"eth_getCode",
[]any{addr, module.BlockNumberArg(blockNumber)},
Expand Down
2 changes: 1 addition & 1 deletion module/eth/gas_price.go
Expand Up @@ -8,7 +8,7 @@ import (
)

// GasPrice requests the current gas price in wei.
func GasPrice() w3types.CallerFactory[big.Int] {
func GasPrice() w3types.RPCCallerFactory[big.Int] {
return module.NewFactory(
"eth_gasPrice",
nil,
Expand Down
2 changes: 1 addition & 1 deletion module/eth/gas_tip_cap.go
Expand Up @@ -9,7 +9,7 @@ import (

// 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] {
func GasTipCap() w3types.RPCCallerFactory[big.Int] {
return module.NewFactory(
"eth_maxPriorityFeePerGas",
nil,
Expand Down
4 changes: 2 additions & 2 deletions module/eth/get_logs.go
Expand Up @@ -11,7 +11,7 @@ import (
)

// Logs requests the logs of the given ethereum.FilterQuery q.
func Logs(q ethereum.FilterQuery) w3types.CallerFactory[[]types.Log] {
func Logs(q ethereum.FilterQuery) w3types.RPCCallerFactory[[]types.Log] {
return &logsFactory{filterQuery: q}
}

Expand All @@ -23,7 +23,7 @@ type logsFactory struct {
returns *[]types.Log
}

func (f *logsFactory) Returns(logs *[]types.Log) w3types.Caller {
func (f *logsFactory) Returns(logs *[]types.Log) w3types.RPCCaller {
f.returns = logs
return f
}
Expand Down
2 changes: 1 addition & 1 deletion module/eth/storage_at.go
Expand Up @@ -11,7 +11,7 @@ import (
// StorageAt requests the storage of the given common.Address addr at the
// given common.Hash slot at the given blockNumber. If block number is nil, the
// slot at the latest known block is requested.
func StorageAt(addr common.Address, slot common.Hash, blockNumber *big.Int) w3types.CallerFactory[common.Hash] {
func StorageAt(addr common.Address, slot common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[common.Hash] {
return module.NewFactory[common.Hash](
"eth_getStorageAt",
[]any{addr, slot, module.BlockNumberArg(blockNumber)},
Expand Down

0 comments on commit 12cdd62

Please sign in to comment.