Browse Source

additional fields in transaction: blockHash, blockNumber, transactionIndex

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
c417e2313e
  1. 11
      libethereum/ClientBase.cpp
  2. 2
      libethereum/ClientBase.h
  3. 2
      libethereum/Interface.h
  4. 22
      libweb3jsonrpc/WebThreeStubServerBase.cpp

11
libethereum/ClientBase.cpp

@ -321,6 +321,11 @@ Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const
return Transaction();
}
pair<h256, unsigned> ClientBase::transactionLocation(h256 const& _transactionHash) const
{
return bc().transactionLocation(_transactionHash);
}
Transactions ClientBase::transactions(h256 _blockHash) const
{
auto bl = bc().block(_blockHash);
@ -419,3 +424,9 @@ h256 ClientBase::hashFromNumber(BlockNumber _number) const
return bc().currentHash();
return bc().numberHash(_number);
}
BlockNumber ClientBase::numberFromHash(h256 _blockHash) const
{
return bc().number(_blockHash);
}

2
libethereum/ClientBase.h

@ -110,10 +110,12 @@ public:
virtual LocalisedLogEntries checkWatch(unsigned _watchId) override;
virtual h256 hashFromNumber(BlockNumber _number) const override;
virtual BlockNumber numberFromHash(h256 _blockHash) const override;
virtual eth::BlockInfo blockInfo(h256 _hash) const override;
virtual eth::BlockDetails blockDetails(h256 _hash) const override;
virtual eth::Transaction transaction(h256 _transactionHash) const override;
virtual eth::Transaction transaction(h256 _blockHash, unsigned _i) const override;
virtual std::pair<h256, unsigned> transactionLocation(h256 const& _transactionHash) const override;
virtual eth::Transactions transactions(h256 _blockHash) const override;
virtual eth::TransactionHashes transactionHashes(h256 _blockHash) const override;
virtual eth::BlockInfo uncle(h256 _blockHash, unsigned _i) const override;

2
libethereum/Interface.h

@ -119,7 +119,9 @@ public:
// [BLOCK QUERY API]
virtual Transaction transaction(h256 _transactionHash) const = 0;
virtual std::pair<h256, unsigned> transactionLocation(h256 const& _transactionHash) const = 0;
virtual h256 hashFromNumber(BlockNumber _number) const = 0;
virtual BlockNumber numberFromHash(h256 _blockHash) const = 0;
virtual BlockInfo blockInfo(h256 _hash) const = 0;
virtual BlockDetails blockDetails(h256 _hash) const = 0;

22
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -79,7 +79,7 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi)
return res;
}
static Json::Value toJson(dev::eth::Transaction const& _t)
static Json::Value toJson(dev::eth::Transaction const& _t, std::pair<h256, unsigned> _location, BlockNumber _blockNumber)
{
Json::Value res;
if (_t)
@ -92,6 +92,9 @@ static Json::Value toJson(dev::eth::Transaction const& _t)
res["gasPrice"] = toJS(_t.gasPrice());
res["nonce"] = toJS(_t.nonce());
res["value"] = toJS(_t.value());
res["blockHash"] = toJS(_location.first);
res["transactionIndex"] = toJS(_location.second);
res["blockNumber"] = toJS(_blockNumber);
}
return res;
}
@ -105,8 +108,8 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi, UncleHashes const& _us
for (h256 h: _us)
res["uncles"].append(toJS(h));
res["transactions"] = Json::Value(Json::arrayValue);
for (Transaction const& t: _ts)
res["transactions"].append(toJson(t));
for (unsigned i = 0; i < _ts.size(); i++)
res["transactions"].append(toJson(_ts[i], std::make_pair(_bi.hash(), i), (BlockNumber)_bi.number));
}
return res;
}
@ -551,7 +554,8 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByHash(string const& _tran
{
try
{
return toJson(client()->transaction(jsToFixed<32>(_transactionHash)));
h256 h = jsToFixed<32>(_transactionHash);
return toJson(client()->transaction(h), client()->transactionLocation(h), client()->numberFromHash(h));
}
catch (...)
{
@ -563,7 +567,10 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockHashAndIndex(string
{
try
{
return toJson(client()->transaction(jsToFixed<32>(_blockHash), jsToInt(_transactionIndex)));
h256 bh = jsToFixed<32>(_blockHash);
unsigned ti = jsToInt(_transactionIndex);
Transaction t = client()->transaction(bh, ti);
return toJson(t, make_pair(bh, ti), client()->numberFromHash(bh));
}
catch (...)
{
@ -575,7 +582,10 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByBlockNumberAndIndex(stri
{
try
{
return toJson(client()->transaction(jsToBlockNumber(_blockNumber), jsToInt(_transactionIndex)));
BlockNumber bn = jsToBlockNumber(_blockNumber);
unsigned ti = jsToInt(_transactionIndex);
Transaction t = client()->transaction(bn, ti);
return toJson(t, make_pair(client()->hashFromNumber(bn), ti), bn);
}
catch (...)
{

Loading…
Cancel
Save