Skip to content

Commit 4688d3c

Browse files
authored
ethclient: fix panic when requesting missing blocks (#26817)
This fixes a regression introduced by #26723. Fixes #26816.
1 parent 544e4a7 commit 4688d3c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ethclient/ethclient.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
113113
err := ec.c.CallContext(ctx, &raw, method, args...)
114114
if err != nil {
115115
return nil, err
116-
} else if len(raw) == 0 {
117-
return nil, ethereum.NotFound
118116
}
117+
119118
// Decode header and transactions.
120119
var head *types.Header
121-
var body rpcBlock
122120
if err := json.Unmarshal(raw, &head); err != nil {
123121
return nil, err
124122
}
123+
// When the block is not found, the API returns JSON null.
124+
if head == nil {
125+
return nil, ethereum.NotFound
126+
}
127+
128+
var body rpcBlock
125129
if err := json.Unmarshal(raw, &body); err != nil {
126130
return nil, err
127131
}

0 commit comments

Comments
 (0)