MCPcopy Create free account
hub / github.com/ElementsProject/elements / BlockFilter

Class BlockFilter

src/blockfilter.h:110–169  ·  view source on GitHub ↗

* Complete block filter struct as defined in BIP 157. Serialization matches * payload of "cfilter" messages. */

Source from the content-addressed store, hash-verified

108 * payload of "cfilter" messages.
109 */
110class BlockFilter
111{
112private:
113 BlockFilterType m_filter_type = BlockFilterType::INVALID;
114 uint256 m_block_hash;
115 GCSFilter m_filter;
116
117 bool BuildParams(GCSFilter::Params& params) const;
118
119public:
120
121 BlockFilter() = default;
122
123 //! Reconstruct a BlockFilter from parts.
124 BlockFilter(BlockFilterType filter_type, const uint256& block_hash,
125 std::vector<unsigned char> filter);
126
127 //! Construct a new BlockFilter of the specified type from a block.
128 BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo);
129
130 BlockFilterType GetFilterType() const { return m_filter_type; }
131 const uint256& GetBlockHash() const { return m_block_hash; }
132 const GCSFilter& GetFilter() const { return m_filter; }
133
134 const std::vector<unsigned char>& GetEncodedFilter() const
135 {
136 return m_filter.GetEncoded();
137 }
138
139 //! Compute the filter hash.
140 uint256 GetHash() const;
141
142 //! Compute the filter header given the previous one.
143 uint256 ComputeHeader(const uint256& prev_header) const;
144
145 template <typename Stream>
146 void Serialize(Stream& s) const {
147 s << static_cast<uint8_t>(m_filter_type)
148 << m_block_hash
149 << m_filter.GetEncoded();
150 }
151
152 template <typename Stream>
153 void Unserialize(Stream& s) {
154 std::vector<unsigned char> encoded_filter;
155 uint8_t filter_type;
156
157 s >> filter_type
158 >> m_block_hash
159 >> encoded_filter;
160
161 m_filter_type = static_cast<BlockFilterType>(filter_type);
162
163 GCSFilter::Params params;
164 if (!BuildParams(params)) {
165 throw std::ios_base::failure("unknown filter_type");
166 }
167 m_filter = GCSFilter(params, std::move(encoded_filter));

Callers 2

ComputeFilterFunction · 0.85
ReadFilterFromDiskMethod · 0.85

Calls

no outgoing calls

Tested by 1

ComputeFilterFunction · 0.68