Skip to content

Commit a4afb9c

Browse files
Jim Posenjimpo
authored andcommitted
blockfilter: Additional helper methods to compute hash and header.
1 parent cd09c79 commit a4afb9c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/blockfilter.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,24 @@ BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const
233233
throw std::invalid_argument("unknown filter_type");
234234
}
235235
}
236+
237+
uint256 BlockFilter::GetHash() const
238+
{
239+
const std::vector<unsigned char>& data = GetEncodedFilter();
240+
241+
uint256 result;
242+
CHash256().Write(data.data(), data.size()).Finalize(result.begin());
243+
return result;
244+
}
245+
246+
uint256 BlockFilter::ComputeHeader(const uint256& prev_header) const
247+
{
248+
const uint256& filter_hash = GetHash();
249+
250+
uint256 result;
251+
CHash256()
252+
.Write(filter_hash.begin(), filter_hash.size())
253+
.Write(prev_header.begin(), prev_header.size())
254+
.Finalize(result.begin());
255+
return result;
256+
}

src/blockfilter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class BlockFilter
106106
return m_filter.GetEncoded();
107107
}
108108

109+
// Compute the filter hash.
110+
uint256 GetHash() const;
111+
112+
// Compute the filter header given the previous one.
113+
uint256 ComputeHeader(const uint256& prev_header) const;
114+
109115
template <typename Stream>
110116
void Serialize(Stream& s) const {
111117
s << m_block_hash

0 commit comments

Comments
 (0)