Changeset View
Changeset View
Standalone View
Standalone View
src/blockfilter.cpp
Show All 9 Lines | |||||
#include <streams.h> | #include <streams.h> | ||||
/// SerType used to serialize parameters in GCS filter encoding. | /// SerType used to serialize parameters in GCS filter encoding. | ||||
static constexpr int GCS_SER_TYPE = SER_NETWORK; | static constexpr int GCS_SER_TYPE = SER_NETWORK; | ||||
/// Protocol version used to serialize parameters in GCS filter encoding. | /// Protocol version used to serialize parameters in GCS filter encoding. | ||||
static constexpr int GCS_SER_VERSION = 0; | static constexpr int GCS_SER_VERSION = 0; | ||||
static const std::map<BlockFilterType, std::string> g_filter_types = { | |||||
{BlockFilterType::BASIC, "basic"}, | |||||
}; | |||||
template <typename OStream> | template <typename OStream> | ||||
static void GolombRiceEncode(BitStreamWriter<OStream> &bitwriter, uint8_t P, | static void GolombRiceEncode(BitStreamWriter<OStream> &bitwriter, uint8_t P, | ||||
uint64_t x) { | uint64_t x) { | ||||
// Write quotient as unary-encoded: q 1's followed by one 0. | // Write quotient as unary-encoded: q 1's followed by one 0. | ||||
uint64_t q = x >> P; | uint64_t q = x >> P; | ||||
while (q > 0) { | while (q > 0) { | ||||
int nbits = q <= 64 ? static_cast<int>(q) : 64; | int nbits = q <= 64 ? static_cast<int>(q) : 64; | ||||
bitwriter.Write(~0ULL, nbits); | bitwriter.Write(~0ULL, nbits); | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | bool GCSFilter::Match(const Element &element) const { | ||||
return MatchInternal(&query, 1); | return MatchInternal(&query, 1); | ||||
} | } | ||||
bool GCSFilter::MatchAny(const ElementSet &elements) const { | bool GCSFilter::MatchAny(const ElementSet &elements) const { | ||||
const std::vector<uint64_t> queries = BuildHashedSet(elements); | const std::vector<uint64_t> queries = BuildHashedSet(elements); | ||||
return MatchInternal(queries.data(), queries.size()); | return MatchInternal(queries.data(), queries.size()); | ||||
} | } | ||||
const std::string &BlockFilterTypeName(BlockFilterType filter_type) { | |||||
static std::string unknown_retval = ""; | |||||
auto it = g_filter_types.find(filter_type); | |||||
return it != g_filter_types.end() ? it->second : unknown_retval; | |||||
} | |||||
bool BlockFilterTypeByName(const std::string &name, | |||||
BlockFilterType &filter_type) { | |||||
for (const auto &entry : g_filter_types) { | |||||
if (entry.second == name) { | |||||
filter_type = entry.first; | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
static GCSFilter::ElementSet BasicFilterElements(const CBlock &block, | static GCSFilter::ElementSet BasicFilterElements(const CBlock &block, | ||||
const CBlockUndo &block_undo) { | const CBlockUndo &block_undo) { | ||||
GCSFilter::ElementSet elements; | GCSFilter::ElementSet elements; | ||||
for (const CTransactionRef &tx : block.vtx) { | for (const CTransactionRef &tx : block.vtx) { | ||||
for (const CTxOut &txout : tx->vout) { | for (const CTxOut &txout : tx->vout) { | ||||
const CScript &script = txout.scriptPubKey; | const CScript &script = txout.scriptPubKey; | ||||
if (script.empty() || script[0] == OP_RETURN) { | if (script.empty() || script[0] == OP_RETURN) { | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |