LogFilter.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file LogFilter.h
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. */
  18. #pragma once
  19. #include <libdevcore/Common.h>
  20. #include <libdevcore/RLP.h>
  21. #include <libethcore/Common.h>
  22. #include "TransactionReceipt.h"
  23. #ifdef __INTEL_COMPILER
  24. #pragma warning(disable:1098) //the qualifier on this friend declaration is ignored
  25. #endif
  26. namespace dev
  27. {
  28. namespace eth
  29. {
  30. class LogFilter;
  31. }
  32. namespace eth
  33. {
  34. /// Simple stream output for the StateDiff.
  35. std::ostream& operator<<(std::ostream& _out, dev::eth::LogFilter const& _s);
  36. class State;
  37. class Block;
  38. class LogFilter
  39. {
  40. public:
  41. LogFilter(h256 _earliest = EarliestBlockHash, h256 _latest = PendingBlockHash): m_earliest(_earliest), m_latest(_latest) {}
  42. void streamRLP(RLPStream& _s) const;
  43. h256 sha3() const;
  44. /// hash of earliest block which should be filtered
  45. h256 earliest() const { return m_earliest; }
  46. /// hash of latest block which should be filtered
  47. h256 latest() const { return m_latest; }
  48. /// Range filter is a filter which doesn't care about addresses or topics
  49. /// Matches are all entries from earliest to latest
  50. /// @returns true if addresses and topics are unspecified
  51. bool isRangeFilter() const;
  52. /// @returns bloom possibilities for all addresses and topics
  53. std::vector<LogBloom> bloomPossibilities() const;
  54. bool matches(LogBloom _bloom) const;
  55. bool matches(Block const& _b, unsigned _i) const;
  56. LogEntries matches(TransactionReceipt const& _r) const;
  57. LogFilter address(Address _a) { m_addresses.insert(_a); return *this; }
  58. LogFilter topic(unsigned _index, h256 const& _t) { if (_index < 4) m_topics[_index].insert(_t); return *this; }
  59. LogFilter withEarliest(h256 _e) { m_earliest = _e; return *this; }
  60. LogFilter withLatest(h256 _e) { m_latest = _e; return *this; }
  61. friend std::ostream& dev::eth::operator<<(std::ostream& _out, dev::eth::LogFilter const& _s);
  62. private:
  63. AddressHash m_addresses;
  64. std::array<h256Hash, 4> m_topics;
  65. h256 m_earliest = EarliestBlockHash;
  66. h256 m_latest = PendingBlockHash;
  67. };
  68. }
  69. }