diff --git a/ethrpc/ethrpc.go b/ethrpc/ethrpc.go index 7c5c54ba..aae8192e 100644 --- a/ethrpc/ethrpc.go +++ b/ethrpc/ethrpc.go @@ -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)) } @@ -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 } diff --git a/ethrpc/ethrpc_test.go b/ethrpc/ethrpc_test.go index 71a1afb2..9f3dd802 100644 --- a/ethrpc/ethrpc_test.go +++ b/ethrpc/ethrpc_test.go @@ -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") diff --git a/ethrpc/interface.go b/ethrpc/interface.go index 0ffa79e1..b9c9d3f4 100644 --- a/ethrpc/interface.go +++ b/ethrpc/interface.go @@ -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