From e6f85271a37d9992b8e1bfb0635c09e519bcb197 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 20 Aug 2025 14:49:43 +0800 Subject: [PATCH] ethclient: ensure tx json is not nil before accessing it #19653 (#1359) --- ethclient/ethclient.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 82ccfea48c..0d1b86d04d 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -253,12 +253,13 @@ func (ec *Client) TransactionCount(ctx context.Context, blockHash common.Hash) ( func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { var json *rpcTransaction err := ec.c.CallContext(ctx, &json, "eth_getTransactionByBlockHashAndIndex", blockHash, hexutil.Uint64(index)) - if err == nil { - if json == nil { - return nil, ethereum.ErrNotFound - } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { - return nil, errors.New("server returned transaction without signature") - } + if err != nil { + return nil, err + } + if json == nil { + return nil, ethereum.ErrNotFound + } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { + return nil, errors.New("server returned transaction without signature") } if json.From != nil && json.BlockHash != nil { setSenderFromServer(json.tx, *json.From, *json.BlockHash)