ethclient: fix panic when requesting missing blocks (#26817)
This fixes a regression introduced by #26723. Fixes #26816.
This commit is contained in:
parent
544e4a700b
commit
4688d3c8f4
@ -113,15 +113,19 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
|
|||||||
err := ec.c.CallContext(ctx, &raw, method, args...)
|
err := ec.c.CallContext(ctx, &raw, method, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if len(raw) == 0 {
|
|
||||||
return nil, ethereum.NotFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode header and transactions.
|
// Decode header and transactions.
|
||||||
var head *types.Header
|
var head *types.Header
|
||||||
var body rpcBlock
|
|
||||||
if err := json.Unmarshal(raw, &head); err != nil {
|
if err := json.Unmarshal(raw, &head); err != nil {
|
||||||
return nil, err
|
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 {
|
if err := json.Unmarshal(raw, &body); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user