Unverified Commit 4688d3c8 authored by Felix Lange's avatar Felix Lange Committed by GitHub

ethclient: fix panic when requesting missing blocks (#26817)

This fixes a regression introduced by #26723.
Fixes #26816.
parent 544e4a70
......@@ -113,15 +113,19 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
err := ec.c.CallContext(ctx, &raw, method, args...)
if err != nil {
return nil, err
} else if len(raw) == 0 {
return nil, ethereum.NotFound
}
// Decode header and transactions.
var head *types.Header
var body rpcBlock
if err := json.Unmarshal(raw, &head); err != nil {
return nil, err
}
// When the block is not found, the API returns JSON null.
if head == nil {
return nil, ethereum.NotFound
}
var body rpcBlock
if err := json.Unmarshal(raw, &body); err != nil {
return nil, err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment