Browse Source

logs are being returned in proper order, without ancestor

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ad88435391
  1. 17
      libethereum/ClientBase.cpp
  2. 2
      libethereum/ClientBase.h

17
libethereum/ClientBase.cpp

@ -185,7 +185,7 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const
tie(blocks, ancestor, ancestorIndex) = bc().treeRoute(_f.earliest(), _f.latest(), false); tie(blocks, ancestor, ancestorIndex) = bc().treeRoute(_f.earliest(), _f.latest(), false);
for (size_t i = 0; i < ancestorIndex; i++) for (size_t i = 0; i < ancestorIndex; i++)
appendLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret); prependLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret);
// cause end is our earliest block, let's compare it with our ancestor // cause end is our earliest block, let's compare it with our ancestor
// if ancestor is smaller let's move our end to it // if ancestor is smaller let's move our end to it
@ -195,11 +195,11 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const
// -> g // -> g
// 3a -> 2a -> 1a // 3a -> 2a -> 1a
// //
// if earliest is at 1a and latest is a 3b, coverting them to numbers // if earliest is at 2a and latest is a 3b, coverting them to numbers
// will give us pair (1, 3) // will give us pair (2, 3)
// and we want to get all logs from g (ancestor) to 3 // and we want to get all logs from 1 (ancestor + 1) to 3
// so we have to move 1a to g // so we have to move 2a to g + 1
end = min(end, (unsigned)numberFromHash(ancestor)); end = min(end, (unsigned)numberFromHash(ancestor) + 1);
// Handle blocks from main chain // Handle blocks from main chain
set<unsigned> matchingBlocks; set<unsigned> matchingBlocks;
@ -213,12 +213,13 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const
matchingBlocks.insert(i); matchingBlocks.insert(i);
for (auto n: matchingBlocks) for (auto n: matchingBlocks)
appendLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret); prependLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret);
reverse(ret.begin(), ret.end());
return ret; return ret;
} }
void ClientBase::appendLogsFromBlock(LogFilter const& _f, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const void ClientBase::prependLogsFromBlock(LogFilter const& _f, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const
{ {
auto receipts = bc().receipts(_blockHash).receipts; auto receipts = bc().receipts(_blockHash).receipts;
for (size_t i = 0; i < receipts.size(); i++) for (size_t i = 0; i < receipts.size(); i++)

2
libethereum/ClientBase.h

@ -104,7 +104,7 @@ public:
virtual LocalisedLogEntries logs(unsigned _watchId) const override; virtual LocalisedLogEntries logs(unsigned _watchId) const override;
virtual LocalisedLogEntries logs(LogFilter const& _filter) const override; virtual LocalisedLogEntries logs(LogFilter const& _filter) const override;
virtual void appendLogsFromBlock(LogFilter const& _filter, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const; virtual void prependLogsFromBlock(LogFilter const& _filter, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const;
/// Install, uninstall and query watches. /// Install, uninstall and query watches.
virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override; virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;

Loading…
Cancel
Save