File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ static constexpr int GCS_SER_TYPE = SER_NETWORK;
15
15
// / Protocol version used to serialize parameters in GCS filter encoding.
16
16
static constexpr int GCS_SER_VERSION = 0 ;
17
17
18
+ static const std::map<BlockFilterType, std::string> g_filter_types = {
19
+ {BlockFilterType::BASIC, " basic" },
20
+ };
21
+
18
22
template <typename OStream>
19
23
static void GolombRiceEncode (BitStreamWriter<OStream>& bitwriter, uint8_t P, uint64_t x)
20
24
{
@@ -197,6 +201,23 @@ bool GCSFilter::MatchAny(const ElementSet& elements) const
197
201
return MatchInternal (queries.data (), queries.size ());
198
202
}
199
203
204
+ const std::string& BlockFilterTypeName (BlockFilterType filter_type)
205
+ {
206
+ static std::string unknown_retval = " " ;
207
+ auto it = g_filter_types.find (filter_type);
208
+ return it != g_filter_types.end () ? it->second : unknown_retval;
209
+ }
210
+
211
+ bool BlockFilterTypeByName (const std::string& name, BlockFilterType& filter_type) {
212
+ for (const auto & entry : g_filter_types) {
213
+ if (entry.second == name) {
214
+ filter_type = entry.first ;
215
+ return true ;
216
+ }
217
+ }
218
+ return false ;
219
+ }
220
+
200
221
static GCSFilter::ElementSet BasicFilterElements (const CBlock& block,
201
222
const CBlockUndo& block_undo)
202
223
{
Original file line number Diff line number Diff line change 6
6
#define BITCOIN_BLOCKFILTER_H
7
7
8
8
#include < stdint.h>
9
+ #include < string>
9
10
#include < unordered_set>
10
11
#include < vector>
11
12
@@ -89,6 +90,12 @@ enum class BlockFilterType : uint8_t
89
90
INVALID = 255 ,
90
91
};
91
92
93
+ /* * Get the human-readable name for a filter type. Returns empty string for unknown types. */
94
+ const std::string& BlockFilterTypeName (BlockFilterType filter_type);
95
+
96
+ /* * Find a filter type by its human-readable name. */
97
+ bool BlockFilterTypeByName (const std::string& name, BlockFilterType& filter_type);
98
+
92
99
/* *
93
100
* Complete block filter struct as defined in BIP 157. Serialization matches
94
101
* payload of "cfilter" messages.
Original file line number Diff line number Diff line change @@ -174,4 +174,16 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test)
174
174
}
175
175
}
176
176
177
+ BOOST_AUTO_TEST_CASE (blockfilter_type_names)
178
+ {
179
+ BOOST_CHECK_EQUAL (BlockFilterTypeName (BlockFilterType::BASIC), " basic" );
180
+ BOOST_CHECK_EQUAL (BlockFilterTypeName (static_cast <BlockFilterType>(255 )), " " );
181
+
182
+ BlockFilterType filter_type;
183
+ BOOST_CHECK (BlockFilterTypeByName (" basic" , filter_type));
184
+ BOOST_CHECK_EQUAL (filter_type, BlockFilterType::BASIC);
185
+
186
+ BOOST_CHECK (!BlockFilterTypeByName (" unknown" , filter_type));
187
+ }
188
+
177
189
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments