aboutsummaryrefslogtreecommitdiff
path: root/src/blockfilter.cpp
diff options
context:
space:
mode:
authorJim Posen <jimpo@coinbase.com>2018-01-23 17:25:30 -0800
committerJim Posen <jim.posen@gmail.com>2018-08-25 10:02:37 -0700
commitc1855f6052aca806fdb51be01b30dfeee8b55f40 (patch)
tree7bfbd95109be83236777956b9465727eba5cd3da /src/blockfilter.cpp
parent53e7874e079f9ddfe8b176f11d46e6b59c7283d5 (diff)
downloadbitcoin-c1855f6052aca806fdb51be01b30dfeee8b55f40.tar.xz
blockfilter: Construction of basic block filters.
Diffstat (limited to 'src/blockfilter.cpp')
-rw-r--r--src/blockfilter.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp
index 52d8f8c296..1119b54901 100644
--- a/src/blockfilter.cpp
+++ b/src/blockfilter.cpp
@@ -4,6 +4,8 @@
#include <blockfilter.h>
#include <hash.h>
+#include <primitives/transaction.h>
+#include <script/script.h>
#include <streams.h>
/// SerType used to serialize parameters in GCS filter encoding.
@@ -193,3 +195,41 @@ bool GCSFilter::MatchAny(const ElementSet& elements) const
const std::vector<uint64_t> queries = BuildHashedSet(elements);
return MatchInternal(queries.data(), queries.size());
}
+
+static GCSFilter::ElementSet BasicFilterElements(const CBlock& block,
+ const CBlockUndo& block_undo)
+{
+ GCSFilter::ElementSet elements;
+
+ for (const CTransactionRef& tx : block.vtx) {
+ for (const CTxOut& txout : tx->vout) {
+ const CScript& script = txout.scriptPubKey;
+ if (script[0] == OP_RETURN) continue;
+ elements.emplace(script.begin(), script.end());
+ }
+ }
+
+ for (const CTxUndo& tx_undo : block_undo.vtxundo) {
+ for (const Coin& prevout : tx_undo.vprevout) {
+ const CScript& script = prevout.out.scriptPubKey;
+ elements.emplace(script.begin(), script.end());
+ }
+ }
+
+ return elements;
+}
+
+BlockFilter::BlockFilter(BlockFilterType filter_type, const CBlock& block, const CBlockUndo& block_undo)
+ : m_filter_type(filter_type), m_block_hash(block.GetHash())
+{
+ switch (m_filter_type) {
+ case BlockFilterType::BASIC:
+ m_filter = GCSFilter(m_block_hash.GetUint64(0), m_block_hash.GetUint64(1),
+ BASIC_FILTER_P, BASIC_FILTER_M,
+ BasicFilterElements(block, block_undo));
+ break;
+
+ default:
+ throw std::invalid_argument("unknown filter_type");
+ }
+}