Browse Source

Merge pull request #1175 from debris/event_sha3

transaction hash in event logs, second approach
cl-refactor
Gav Wood 10 years ago
parent
commit
e910720e69
  1. 28
      libethereum/Client.cpp
  2. 4
      libethereum/Client.h
  3. 3
      libevm/ExtVMFace.h
  4. 1
      libweb3jsonrpc/WebThreeStubServerBase.cpp

28
libethereum/Client.cpp

@ -291,7 +291,7 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId)
return ret; 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); Guard l(m_filterLock);
for (pair<h256 const, InstalledFilter>& i: m_filters) for (pair<h256 const, InstalledFilter>& i: m_filters)
@ -303,7 +303,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& i
{ {
// filter catches them // filter catches them
for (LogEntry const& l: m) 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); io_changed.insert(i.first);
} }
} }
@ -319,14 +319,16 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed)
for (pair<h256 const, InstalledFilter>& i: m_filters) for (pair<h256 const, InstalledFilter>& i: m_filters)
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom)) 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. // 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); auto m = i.second.filter.matches(tr);
if (m.size()) if (m.size())
{ {
auto sha3 = transaction(d.hash, j).sha3();
// filter catches them // filter catches them
for (LogEntry const& l: m) 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); io_changed.insert(i.first);
} }
} }
@ -582,8 +584,9 @@ void Client::doWork()
TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq); TransactionReceipts newPendingReceipts = m_postMine.sync(m_bc, m_tq);
if (newPendingReceipts.size()) if (newPendingReceipts.size())
{ {
for (auto i: newPendingReceipts) for (size_t i = 0; i < newPendingReceipts.size(); i++)
appendFromNewPending(i, changeds); appendFromNewPending(newPendingReceipts[i], changeds, m_postMine.pending()[i].sha3());
changeds.insert(PendingChangedFilter); changeds.insert(PendingChangedFilter);
if (isMining()) if (isMining())
@ -756,6 +759,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const
{ {
// Might have a transaction that contains a matching log. // Might have a transaction that contains a matching log.
TransactionReceipt const& tr = m_postMine.receipt(i); TransactionReceipt const& tr = m_postMine.receipt(i);
auto sha3 = m_postMine.pending()[i].sha3();
LogEntries le = _f.matches(tr); LogEntries le = _f.matches(tr);
if (le.size()) if (le.size())
{ {
@ -763,7 +767,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const
if (s) if (s)
s--; s--;
else else
ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin)); ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin, sha3));
} }
} }
begin = m_bc.number(); begin = m_bc.number();
@ -782,11 +786,15 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const
int total = 0; int total = 0;
#endif #endif
// check block bloom // check block bloom
if (_f.matches(m_bc.info(h).logBloom)) auto info = m_bc.info(h);
for (TransactionReceipt receipt: m_bc.receipts(h).receipts) 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())) if (_f.matches(receipt.bloom()))
{ {
auto h = transaction(info.hash, i).sha3();
LogEntries le = _f.matches(receipt); LogEntries le = _f.matches(receipt);
if (le.size()) if (le.size())
{ {
@ -798,7 +806,7 @@ LocalisedLogEntries Client::logs(LogFilter const& _f) const
if (s) if (s)
s--; s--;
else else
ret.insert(ret.begin(), LocalisedLogEntry(le[j], n)); ret.insert(ret.begin(), LocalisedLogEntry(le[j], n, h));
} }
} }
} }

4
libethereum/Client.h

@ -220,7 +220,7 @@ public:
/// @returns the length of the chain. /// @returns the length of the chain.
virtual unsigned number() const { return m_bc.number(); } 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(). /// @TODO: Remove in favour of transactions().
virtual Transactions pending() const { return m_postMine.pending(); } virtual Transactions pending() const { return m_postMine.pending(); }
@ -311,7 +311,7 @@ public:
protected: protected:
/// Collate the changed filters for the bloom filter of the given pending transaction. /// Collate the changed filters for the bloom filter of the given pending transaction.
/// Insert any filters that are activated into @a o_changed. /// 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. /// Collate the changed filters for the hash of the given block.
/// Insert any filters that are activated into @a o_changed. /// Insert any filters that are activated into @a o_changed.

3
libevm/ExtVMFace.h

@ -63,9 +63,10 @@ using LogEntries = std::vector<LogEntry>;
struct LocalisedLogEntry: public LogEntry struct LocalisedLogEntry: public LogEntry
{ {
LocalisedLogEntry() {} LocalisedLogEntry() {}
LocalisedLogEntry(LogEntry const& _le, unsigned _number): LogEntry(_le), number(_number) {} LocalisedLogEntry(LogEntry const& _le, unsigned _number, h256 _sha3 = {}): LogEntry(_le), number(_number), sha3(_sha3) {}
unsigned number = 0; unsigned number = 0;
h256 sha3;
}; };
using LocalisedLogEntries = std::vector<LocalisedLogEntry>; using LocalisedLogEntries = std::vector<LocalisedLogEntry>;

1
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -95,6 +95,7 @@ static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e)
for (auto const& t: _e.topics) for (auto const& t: _e.topics)
res["topic"].append(toJS(t)); res["topic"].append(toJS(t));
res["number"] = _e.number; res["number"] = _e.number;
res["hash"] = toJS(_e.sha3);
return res; return res;
} }

Loading…
Cancel
Save