Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Aug 7, 2023
1 parent af08a69 commit 0d6d3a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
22 changes: 7 additions & 15 deletions ethrpc/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ func (p *Provider) Do(ctx context.Context, calls ...Call) error {
}

if res.StatusCode < 200 || res.StatusCode > 299 {
if len(body) > 40 {
body = body[:40]
if len(body) > 100 {
body = body[:100]
}
return superr.Wrap(ErrRequestFail, fmt.Errorf("non-200 response with status code: %d with body '%s'", res.StatusCode, body))
}

if err := json.Unmarshal(body, &batch); err != nil {
if len(body) > 40 {
body = body[:40]
if len(body) > 100 {
body = body[:100]
}
return superr.Wrap(ErrRequestFail, fmt.Errorf("failed to unmarshal response: '%s' due to %w", string(body), err))
}
Expand Down Expand Up @@ -195,18 +195,10 @@ func (p *Provider) BlockByNumber(ctx context.Context, blockNum *big.Int) (*types
}

func (p *Provider) BlockRange(ctx context.Context, startBlockNum, endBlockNum *big.Int) ([]*types.Block, error) {
chainID, err := p.ChainID(ctx)
if err != nil {
return nil, err
}

// eth_getBlockRange is only available on Optimism at this time.
if chainID.Cmp(big.NewInt(10)) != 0 {
return nil, ErrUnsupportedMethodOnChain
}

// NOTE: eth_getBlockRange is only available on Optimism at this time.
// however, it appears to be deprecated.
var ret []*types.Block
err = p.Do(ctx, BlockRange(startBlockNum, endBlockNum).Into(&ret))
err := p.Do(ctx, BlockRange(startBlockNum, endBlockNum).Into(&ret))
return ret, err
}

Expand Down
21 changes: 11 additions & 10 deletions ethrpc/ethrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ func TestBlockByNumber(t *testing.T) {
}
}

// func TestBlockRange(t *testing.T) {
// p, err := ethrpc.NewProvider("https://dev-nodes.sequence.app/optimism")
// require.NoError(t, err)

// {
// block, err := p.BlockRange(context.Background(), big.NewInt(1_000_000), big.NewInt(1_000_100))
// require.NoError(t, err)
// require.NotNil(t, block)
// }
// }
// NOTE: it appears eth_getBlockRange has been deprecated on Optimism
func XTestBlockRange(t *testing.T) {
p, err := ethrpc.NewProvider("https://dev-nodes.sequence.app/optimism")
require.NoError(t, err)

{
block, err := p.BlockRange(context.Background(), big.NewInt(1_000_000), big.NewInt(1_000_100))
require.NoError(t, err)
require.NotNil(t, block)
}
}

func ExampleBatchCall() {
p, err := ethrpc.NewProvider("https://nodes.sequence.app/polygon")
Expand Down
2 changes: 2 additions & 0 deletions ethrpc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type Interface interface {

// BlockRange = eth_getBlockRange
// https://community.optimism.io/docs/developers/build/json-rpc/#eth-getblockrange
//
// NOTE: it appears eth_getBlockRange has been deprecated on Optimism
BlockRange(ctx context.Context, startBlockNum, endBlockNum *big.Int) ([]*types.Block, error)

// PeerCount = net_peerCount
Expand Down

0 comments on commit 0d6d3a0

Please sign in to comment.