From ff4fa5efd35f4bf609d34293b904c1af8d8b5ad8 Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Wed, 2 Feb 2022 15:25:16 +0100 Subject: [PATCH] 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) --- cmd/rpcdaemon/commands/eth_txs.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/rpcdaemon/commands/eth_txs.go b/cmd/rpcdaemon/commands/eth_txs.go index edfb679dd..08868ef4c 100644 --- a/cmd/rpcdaemon/commands/eth_txs.go +++ b/cmd/rpcdaemon/commands/eth_txs.go @@ -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