ethclient: ensure tx json is not nil before accessing it #19653 (#1359)

This commit is contained in:
Daniel Liu 2025-08-20 14:49:43 +08:00 committed by benjamin202410
parent 2726509176
commit 819318bd7a

View file

@ -238,13 +238,14 @@ 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 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")
}
}
setSenderFromServer(json.tx, json.From, json.BlockHash)
return json.tx, err
}