Changeset View
Changeset View
Standalone View
Standalone View
src/blockfilter.cpp
// Copyright (c) 2018 The Bitcoin Core developers | // Copyright (c) 2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <blockfilter.h> | #include <blockfilter.h> | ||||
#include <crypto/siphash.h> | #include <crypto/siphash.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <mutex> | |||||
#include <sstream> | |||||
/// 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 = { | static const std::map<BlockFilterType, std::string> g_filter_types = { | ||||
{BlockFilterType::BASIC, "basic"}, | {BlockFilterType::BASIC, "basic"}, | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | for (const auto &entry : g_filter_types) { | ||||
if (entry.second == name) { | if (entry.second == name) { | ||||
filter_type = entry.first; | filter_type = entry.first; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
const std::vector<BlockFilterType> &AllBlockFilterTypes() { | |||||
static std::vector<BlockFilterType> types; | |||||
static std::once_flag flag; | |||||
std::call_once(flag, []() { | |||||
types.reserve(g_filter_types.size()); | |||||
for (auto entry : g_filter_types) { | |||||
types.push_back(entry.first); | |||||
} | |||||
}); | |||||
return types; | |||||
} | |||||
const std::string &ListBlockFilterTypes() { | |||||
static std::string type_list; | |||||
static std::once_flag flag; | |||||
std::call_once(flag, []() { | |||||
std::stringstream ret; | |||||
bool first = true; | |||||
for (auto entry : g_filter_types) { | |||||
if (!first) ret << ", "; | |||||
ret << entry.second; | |||||
first = false; | |||||
} | |||||
type_list = ret.str(); | |||||
}); | |||||
return type_list; | |||||
} | |||||
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 |