From 7690647be86f5af4b136fd62fb4e424fe5627f45 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 9 Jun 2015 09:28:09 +0200 Subject: [PATCH] updated LocalisedLogEntry --- libethereum/BlockChain.h | 1 + libethereum/Client.cpp | 20 ++++++++++++-------- libethereum/Client.h | 2 +- libethereum/ClientBase.cpp | 9 +++++---- libethereum/ClientBase.h | 2 +- libevm/ExtVMFace.h | 19 +++++++++++++++---- libweb3jsonrpc/WebThreeStubServerBase.cpp | 20 +++++++++++++++++--- libweb3jsonrpc/WebThreeStubServerBase.h | 2 -- mix/MixClient.cpp | 4 ++-- 9 files changed, 54 insertions(+), 25 deletions(-) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index a67ec9a9c..3868ad5e4 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -143,6 +143,7 @@ public: BlockLogBlooms logBlooms() const { return logBlooms(currentHash()); } /// Get the transactions' receipts of a block (or the most recent mined if none given). Thread-safe. + /// receipts are given in the same order are in the same order as the transactions BlockReceipts receipts(h256 const& _hash) const { return queryExtras(_hash, m_receipts, x_receipts, NullBlockReceipts); } BlockReceipts receipts() const { return receipts(currentHash()); } diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index bdc631dae..8022f83bf 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -336,7 +336,7 @@ static S& filtersStreamOut(S& _out, T const& _fs) return _out; } -void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed, h256 _transactionHash) +void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed) { Guard l(x_filtersWatches); for (pair& i: m_filters) @@ -347,7 +347,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& { // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, m_bc.number() + 1, _transactionHash)); + i.second.changes.push_back(LocalisedLogEntry(l)); io_changed.insert(i.first); } } @@ -357,24 +357,28 @@ void Client::appendFromNewBlock(h256 const& _block, h256Hash& io_changed) { // TODO: more precise check on whether the txs match. auto d = m_bc.info(_block); - auto br = m_bc.receipts(_block); + auto receipts = m_bc.receipts(_block).receipts; Guard l(x_filtersWatches); for (pair& i: m_filters) + { // acceptable number & looks like block may contain a matching log entry. - for (size_t j = 0; j < br.receipts.size(); j++) + unsigned logIndex = 0; + for (size_t j = 0; j < receipts.size(); j++) { - auto tr = br.receipts[j]; + logIndex++; + auto tr = receipts[j]; auto m = i.second.filter.matches(tr); if (m.size()) { auto transactionHash = transaction(d.hash(), j).sha3(); // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, (unsigned)d.number, transactionHash)); + i.second.changes.push_back(LocalisedLogEntry(l, d, transactionHash, j, logIndex)); io_changed.insert(i.first); } } + } } void Client::setForceMining(bool _enable) @@ -508,7 +512,7 @@ void Client::syncTransactionQueue() DEV_READ_GUARDED(x_postMine) for (size_t i = 0; i < newPendingReceipts.size(); i++) - appendFromNewPending(newPendingReceipts[i], changeds, m_postMine.pending()[i].sha3()); + appendFromNewPending(newPendingReceipts[i], changeds); changeds.insert(PendingChangedFilter); // Tell farm about new transaction (i.e. restartProofOfWork mining). @@ -649,7 +653,7 @@ void Client::noteChanged(h256Hash const& _filters) else { cwatch << "!!!" << w.first << LogTag::Special << (w.second.id == PendingChangedFilter ? "pending" : w.second.id == ChainChangedFilter ? "chain" : "???"); - w.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry, 0)); + w.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry)); } } // clear the filters now. diff --git a/libethereum/Client.h b/libethereum/Client.h index 5132b5a30..fe310cfa0 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -229,7 +229,7 @@ protected: /// Collate the changed filters for the bloom filter of the given pending transaction. /// Insert any filters that are activated into @a o_changed. - void appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed, h256 _sha3); + void appendFromNewPending(TransactionReceipt const& _receipt, h256Hash& io_changed); /// Collate the changed filters for the hash of the given block. /// Insert any filters that are activated into @a o_changed. diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 12246daa2..aa7883ee1 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -182,11 +182,10 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const { // Might have a transaction that contains a matching log. TransactionReceipt const& tr = temp.receipt(i); - auto th = temp.pending()[i].sha3(); LogEntries le = _f.matches(tr); if (le.size()) for (unsigned j = 0; j < le.size(); ++j) - ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin, th)); + ret.insert(ret.begin(), LocalisedLogEntry(le[j])); } begin = bc().number(); } @@ -201,20 +200,22 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const { int total = 0; auto h = bc().numberHash(n); + auto info = bc().info(h); auto receipts = bc().receipts(h).receipts; + unsigned logIndex = 0; for (size_t i = 0; i < receipts.size(); i++) { + logIndex++; TransactionReceipt receipt = receipts[i]; if (_f.matches(receipt.bloom())) { - auto info = bc().info(h); auto th = transaction(info.hash(), i).sha3(); LogEntries le = _f.matches(receipt); if (le.size()) { total += le.size(); for (unsigned j = 0; j < le.size(); ++j) - ret.insert(ret.begin(), LocalisedLogEntry(le[j], n, th)); + ret.insert(ret.begin(), LocalisedLogEntry(le[j], info, th, i, logIndex)); } } diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 7b7b3cb76..d0b2773aa 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -44,7 +44,7 @@ static const h256 PendingChangedFilter = u256(0); static const h256 ChainChangedFilter = u256(1); static const LogEntry SpecialLogEntry = LogEntry(Address(), h256s(), bytes()); -static const LocalisedLogEntry InitialChange(SpecialLogEntry, 0); +static const LocalisedLogEntry InitialChange(SpecialLogEntry); struct ClientWatch { diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 6b35094bb..46dc908ee 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -63,10 +63,21 @@ using LogEntries = std::vector; struct LocalisedLogEntry: public LogEntry { LocalisedLogEntry() {} - LocalisedLogEntry(LogEntry const& _le, unsigned _number, h256 _transactionHash = h256()): LogEntry(_le), number(_number), transactionHash(_transactionHash) {} - - unsigned number = 0; - h256 transactionHash; + explicit LocalisedLogEntry(LogEntry const& _le): LogEntry(_le) {}; + explicit LocalisedLogEntry( + LogEntry const& _le, + BlockInfo const& _bi, + h256 _th, + unsigned _ti, + unsigned _li + ): LogEntry(_le), blockHash(_bi.hash()), blockNumber((BlockNumber)_bi.number), transactionHash(_th), transactionIndex(_ti), logIndex(_li), mined(true) {}; + + h256 blockHash = h256(); + BlockNumber blockNumber = 0; + h256 transactionHash = h256(); + unsigned transactionIndex = 0; + unsigned logIndex = 0; + bool mined = false; }; using LocalisedLogEntries = std::vector; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 6919bb70c..ff1784975 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -164,15 +164,29 @@ static Json::Value toJson(dev::eth::Transaction const& _t) static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) { Json::Value res; - if (_e.transactionHash) + if (_e.topics.size() > 0) { res["data"] = toJS(_e.data); res["address"] = toJS(_e.address); res["topics"] = Json::Value(Json::arrayValue); for (auto const& t: _e.topics) res["topics"].append(toJS(t)); - res["number"] = _e.number; - res["transactionHash"] = toJS(_e.transactionHash); + if (_e.mined) + { + res["blockNumber"] = _e.blockNumber; + res["blockHash"] = toJS(_e.blockHash); + res["logIndex"] = _e.logIndex; + res["transactionHash"] = toJS(_e.transactionHash); + res["transactionIndex"] = _e.transactionIndex; + } + else + { + res["blockNumber"] = Json::Value(Json::nullValue); + res["blockHash"] = Json::Value(Json::nullValue); + res["logIndex"] = Json::Value(Json::nullValue); + res["transactionHash"] = Json::Value(Json::nullValue); + res["transactionIndex"] = Json::Value(Json::nullValue); + } } return res; } diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 32a9fdd68..7cdc96682 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -60,8 +60,6 @@ public: /** * @brief JSON-RPC api implementation - * @todo filters should work on unsigned instead of int - * unsigned are not supported in json-rpc-cpp and there are bugs with double in json-rpc-cpp version 0.2.1 * @todo split these up according to subprotocol (eth, shh, db, p2p, web3) and make it /very/ clear about how to add other subprotocols. * @todo modularise everything so additional subprotocols don't need to change this file. */ diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 568d4061b..b21398102 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -260,7 +260,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c { // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1)); + i.second.changes.push_back(LocalisedLogEntry(l)); changed.insert(i.first); } } @@ -375,7 +375,7 @@ void MixClient::noteChanged(h256Set const& _filters) if (m_filters.count(i.second.id)) i.second.changes += m_filters.at(i.second.id).changes; else - i.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry, 0)); + i.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry)); } for (auto& i: m_filters) i.second.changes.clear();