fix compatibility of getting tx by number (#3409)

* fix compatibility of getting tx by number

`eth_getTransactionByBlockHashAndIndex` and `eth_getTransactionByBlockNumberAndIndex` should return `null` if the index provided is out of bound (checked with Infura and Cloudflare ETH gateway).

* small fixup (formatting)
This commit is contained in:
Igor Mandrigin 2022-02-02 15:25:16 +01:00 committed by GitHub
parent e23f23757f
commit ff4fa5efd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,6 @@ package commands
import (
"bytes"
"context"
"fmt"
"math/big"
"github.com/ledgerwatch/erigon-lib/gointerfaces"
@ -161,7 +160,7 @@ func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, block
txs := block.Transactions()
if uint64(txIndex) >= uint64(len(txs)) {
return nil, fmt.Errorf("txIndex (%d) out of range (nTxs: %d)", uint64(txIndex), uint64(len(txs)))
return nil, nil // not error
}
return newRPCTransaction(txs[txIndex], block.Hash(), block.NumberU64(), uint64(txIndex), block.BaseFee()), nil
@ -211,7 +210,7 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo
txs := block.Transactions()
if uint64(txIndex) >= uint64(len(txs)) {
return nil, fmt.Errorf("txIndex (%d) out of range (nTxs: %d)", uint64(txIndex), uint64(len(txs)))
return nil, nil // not error
}
return newRPCTransaction(txs[txIndex], block.Hash(), block.NumberU64(), uint64(txIndex), block.BaseFee()), nil