Browse Source

eth_getTransactionByBlockHash && eth_getTransactionByBlockNumber returns null when transactions are out of scope

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
358f9b49cd
  1. 4
      libethereum/ClientBase.cpp
  2. 1
      libethereum/ClientBase.h
  3. 1
      libethereum/Interface.h
  4. 9
      libweb3jsonrpc/WebThreeStubServerBase.cpp

4
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;
}

1
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

1
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;

9
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 (...)
{

Loading…
Cancel
Save