From c417e2313e6a787b01b1c118e96dbd41dd42fd8f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 10 Apr 2015 14:56:52 +0200 Subject: [PATCH 1/2] additional fields in transaction: blockHash, blockNumber, transactionIndex --- libethereum/ClientBase.cpp | 11 +++++++++++ libethereum/ClientBase.h | 2 ++ libethereum/Interface.h | 2 ++ libweb3jsonrpc/WebThreeStubServerBase.cpp | 22 ++++++++++++++++------ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index f57b2b174..692081f96 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -321,6 +321,11 @@ Transaction ClientBase::transaction(h256 _blockHash, unsigned _i) const return Transaction(); } +pair 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); +} + diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 00bb02ed4..2bc36ae15 100644 --- a/libethereum/ClientBase.h +++ b/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 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; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index ac41b0ec1..0f4e6a778 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -119,7 +119,9 @@ public: // [BLOCK QUERY API] virtual Transaction transaction(h256 _transactionHash) const = 0; + virtual std::pair 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; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 291415a68..c760005de 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/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 _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 (...) { From 6714143a92b6a3531265c3195250150609442dc8 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 10 Apr 2015 21:37:24 +0200 Subject: [PATCH 2/2] fixed blockNumber in jsonrpc transaction --- libweb3jsonrpc/WebThreeStubServerBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index dae672f58..138d6a506 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -546,7 +546,8 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByHash(string const& _tran try { h256 h = jsToFixed<32>(_transactionHash); - return toJson(client()->transaction(h), client()->transactionLocation(h), client()->numberFromHash(h)); + auto l = client()->transactionLocation(h); + return toJson(client()->transaction(h), l, client()->numberFromHash(l.first)); } catch (...) {