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;
}
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<h256 const, InstalledFilter>& 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<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))
// 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 h = 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, h));
}
}
}

4
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.

3
libevm/ExtVMFace.h

@ -63,9 +63,10 @@ using LogEntries = std::vector<LogEntry>;
struct LocalisedLogEntry: public LogEntry
{
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;
h256 sha3;
};
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)
res["topic"].append(toJS(t));
res["number"] = _e.number;
res["hash"] = toJS(_e.sha3);
return res;
}

Loading…
Cancel
Save