blockfilter: Additional helper methods to compute hash and header.
This commit is contained in:
parent
cd09c7925b
commit
a4afb9cadb
2 changed files with 27 additions and 0 deletions
|
@ -233,3 +233,24 @@ BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const
|
||||||
throw std::invalid_argument("unknown filter_type");
|
throw std::invalid_argument("unknown filter_type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 BlockFilter::GetHash() const
|
||||||
|
{
|
||||||
|
const std::vector<unsigned char>& data = GetEncodedFilter();
|
||||||
|
|
||||||
|
uint256 result;
|
||||||
|
CHash256().Write(data.data(), data.size()).Finalize(result.begin());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 BlockFilter::ComputeHeader(const uint256& prev_header) const
|
||||||
|
{
|
||||||
|
const uint256& filter_hash = GetHash();
|
||||||
|
|
||||||
|
uint256 result;
|
||||||
|
CHash256()
|
||||||
|
.Write(filter_hash.begin(), filter_hash.size())
|
||||||
|
.Write(prev_header.begin(), prev_header.size())
|
||||||
|
.Finalize(result.begin());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -106,6 +106,12 @@ public:
|
||||||
return m_filter.GetEncoded();
|
return m_filter.GetEncoded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute the filter hash.
|
||||||
|
uint256 GetHash() const;
|
||||||
|
|
||||||
|
// Compute the filter header given the previous one.
|
||||||
|
uint256 ComputeHeader(const uint256& prev_header) const;
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
void Serialize(Stream& s) const {
|
void Serialize(Stream& s) const {
|
||||||
s << m_block_hash
|
s << m_block_hash
|
||||||
|
|
Loading…
Reference in a new issue