blockfilter: Construction of basic block filters.

This commit is contained in:
Jim Posen
2018-01-23 17:25:30 -08:00
committed by Jim Posen
parent 53e7874e07
commit c1855f6052
4 changed files with 129 additions and 0 deletions

View File

@@ -9,8 +9,10 @@
#include <stdint.h>
#include <vector>
#include <primitives/block.h>
#include <serialize.h>
#include <uint256.h>
#include <undo.h>
/**
* This implements a Golomb-coded set as defined in BIP 158. It is a
@@ -71,4 +73,37 @@ public:
bool MatchAny(const ElementSet& elements) const;
};
constexpr uint8_t BASIC_FILTER_P = 19;
constexpr uint32_t BASIC_FILTER_M = 784931;
enum BlockFilterType : uint8_t
{
BASIC = 0,
};
/**
* Complete block filter struct as defined in BIP 157.
*/
class BlockFilter
{
private:
BlockFilterType m_filter_type;
uint256 m_block_hash;
GCSFilter m_filter;
public:
// Construct a new BlockFilter of the specified type from a block.
BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo);
BlockFilterType GetFilterType() const { return m_filter_type; }
const GCSFilter& GetFilter() const { return m_filter; }
const std::vector<unsigned char>& GetEncodedFilter() const
{
return m_filter.GetEncoded();
}
};
#endif // BITCOIN_BLOCKFILTER_H