Browse Source

updated LocalisedLogEntry

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
7690647be8
  1. 1
      libethereum/BlockChain.h
  2. 20
      libethereum/Client.cpp
  3. 2
      libethereum/Client.h
  4. 9
      libethereum/ClientBase.cpp
  5. 2
      libethereum/ClientBase.h
  6. 19
      libevm/ExtVMFace.h
  7. 20
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  8. 2
      libweb3jsonrpc/WebThreeStubServerBase.h
  9. 4
      mix/MixClient.cpp

1
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<BlockReceipts, ExtraReceipts>(_hash, m_receipts, x_receipts, NullBlockReceipts); }
BlockReceipts receipts() const { return receipts(currentHash()); }

20
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<h256 const, InstalledFilter>& 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<h256 const, InstalledFilter>& 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.

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

9
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));
}
}

2
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
{

19
libevm/ExtVMFace.h

@ -63,10 +63,21 @@ using LogEntries = std::vector<LogEntry>;
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<LocalisedLogEntry>;

20
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;
}

2
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.
*/

4
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();

Loading…
Cancel
Save