From 358f9b49cd06366dac4b5073057df357a5baa234 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 15 Jul 2015 10:31:32 +0200 Subject: [PATCH] eth_getTransactionByBlockHash && eth_getTransactionByBlockNumber returns null when transactions are out of scope --- libethereum/ClientBase.cpp | 4 ++++ libethereum/ClientBase.h | 1 + libethereum/Interface.h | 1 + libweb3jsonrpc/WebThreeStubServerBase.cpp | 9 ++++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 440443156..4f913304d 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -503,3 +503,7 @@ bool ClientBase::isKnownTransaction(h256 const& _transactionHash) const return bc().isKnownTransaction(_transactionHash); } +bool ClientBase::isKnownTransaction(h256 const& _blockHash, unsigned _i) const +{ + return isKnown(_blockHash) && bc().transactions().size() > _i; +} diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index b68fc540f..9e513124a 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -152,6 +152,7 @@ public: virtual bool isKnown(h256 const& _hash) const override; virtual bool isKnown(BlockNumber _block) const override; virtual bool isKnownTransaction(h256 const& _transactionHash) const override; + virtual bool isKnownTransaction(h256 const& _blockHash, unsigned _i) const override; /// TODO: consider moving it to a separate interface diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 418b8e0ff..753b712ea 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -134,6 +134,7 @@ public: // [BLOCK QUERY API] virtual bool isKnownTransaction(h256 const& _transactionHash) const = 0; + virtual bool isKnownTransaction(h256 const& _blockHash, unsigned _i) const = 0; virtual Transaction transaction(h256 _transactionHash) const = 0; virtual LocalisedTransaction localisedTransaction(h256 const& _transactionHash) const = 0; virtual TransactionReceipt transactionReceipt(h256 const& _transactionHash) const = 0; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index a9d74d3ac..8b1962941 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -394,6 +394,9 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockHashAndIndex(string { h256 bh = jsToFixed<32>(_blockHash); unsigned ti = jsToInt(_transactionIndex); + if (!client()->isKnownTransaction(bh, ti)) + return Json::Value(Json::nullValue); + return toJson(client()->localisedTransaction(bh, ti)); } catch (...) @@ -407,8 +410,12 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockNumberAndIndex(stri try { BlockNumber bn = jsToBlockNumber(_blockNumber); + h256 bh = client()->hashFromNumber(bn); unsigned ti = jsToInt(_transactionIndex); - return toJson(client()->localisedTransaction(client()->hashFromNumber(bn), ti)); + if (!client()->isKnownTransaction(bh, ti)) + return Json::Value(Json::nullValue); + + return toJson(client()->localisedTransaction(bh, ti)); } catch (...) {