From 97fc7305dcf098ccd166c4aa66f798b0c8917768 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sun, 1 Mar 2015 19:09:01 +0100 Subject: [PATCH] transaction hash in event logs, second approach --- libethereum/Client.cpp | 28 +++++++++++++++-------- libethereum/Client.h | 4 ++-- libevm/ExtVMFace.h | 3 ++- libweb3jsonrpc/WebThreeStubServerBase.cpp | 1 + 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 5ea513f0a..02412f4c1 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -291,7 +291,7 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId) return ret; } -void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed) +void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _sha3) { Guard l(m_filterLock); for (pair& i: m_filters) @@ -303,7 +303,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& i { // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, m_bc.number() + 1)); + i.second.changes.push_back(LocalisedLogEntry(l, m_bc.number() + 1, _sha3)); io_changed.insert(i.first); } } @@ -319,14 +319,16 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed) for (pair& i: m_filters) if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom)) // acceptable number & looks like block may contain a matching log entry. - for (TransactionReceipt const& tr: br.receipts) + for (size_t j = 0; j < br.receipts.size(); j++) { + auto tr = br.receipts[j]; auto m = i.second.filter.matches(tr); if (m.size()) { + auto sha3 = transaction(d.hash, j).sha3(); // filter catches them for (LogEntry const& l: m) - i.second.changes.push_back(LocalisedLogEntry(l, (unsigned)d.number)); + i.second.changes.push_back(LocalisedLogEntry(l, (unsigned)d.number, sha3)); io_changed.insert(i.first); } } @@ -582,8 +584,9 @@ void Client::doWork() TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq); if (newPendingReceipts.size()) { - for (auto i: newPendingReceipts) - appendFromNewPending(i, changeds); + for (size_t i = 0; i < newPendingReceipts.size(); i++) + appendFromNewPending(newPendingReceipts[i], changeds, m_postMine.pending()[i].sha3()); + changeds.insert(PendingChangedFilter); if (isMining()) @@ -756,6 +759,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const { // Might have a transaction that contains a matching log. TransactionReceipt const& tr = m_postMine.receipt(i); + auto sha3 = m_postMine.pending()[i].sha3(); LogEntries le = _f.matches(tr); if (le.size()) { @@ -763,7 +767,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const if (s) s--; else - ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin)); + ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin, sha3)); } } begin = m_bc.number(); @@ -782,11 +786,15 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const int total = 0; #endif // check block bloom - if (_f.matches(m_bc.info(h).logBloom)) - for (TransactionReceipt receipt: m_bc.receipts(h).receipts) + auto info = m_bc.info(h); + auto receipts = m_bc.receipts(h).receipts; + if (_f.matches(info.logBloom)) + for (size_t i = 0; i < receipts.size(); i++) { + TransactionReceipt receipt = receipts[i]; if (_f.matches(receipt.bloom())) { + auto sha3 = transaction(info.hash, i).sha3(); LogEntries le = _f.matches(receipt); if (le.size()) { @@ -798,7 +806,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const if (s) s--; else - ret.insert(ret.begin(), LocalisedLogEntry(le[j], n)); + ret.insert(ret.begin(), LocalisedLogEntry(le[j], n, sha3)); } } } diff --git a/libethereum/Client.h b/libethereum/Client.h index 7cd520ab6..c689363b3 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -220,7 +220,7 @@ public: /// @returns the length of the chain. virtual unsigned number() const { return m_bc.number(); } - /// Get a map containing each of the pending transactions. + /// Get the list of pending transactions. /// @TODO: Remove in favour of transactions(). virtual Transactions pending() const { return m_postMine.pending(); } @@ -311,7 +311,7 @@ public: 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, h256Set& io_changed); + void appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _sha3); /// Collate the changed filters for the hash of the given block. /// Insert any filters that are activated into @a o_changed. diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 13e8712b8..95910d7cb 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -63,9 +63,10 @@ using LogEntries = std::vector; struct LocalisedLogEntry: public LogEntry { LocalisedLogEntry() {} - LocalisedLogEntry(LogEntry const& _le, unsigned _number): LogEntry(_le), number(_number) {} + LocalisedLogEntry(LogEntry const& _le, unsigned _number, h256 _sha3 = h256(u256(0))): LogEntry(_le), number(_number), sha3(_sha3) {} unsigned number = 0; + h256 sha3; }; using LocalisedLogEntries = std::vector; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index dbf3b2ec9..6e0db8b47 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -95,6 +95,7 @@ static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) for (auto const& t: _e.topics) res["topic"].append(toJS(t)); res["number"] = _e.number; + res["hash"] = toJS(_e.sha3); return res; }