File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,8 @@ enum BlockFilterType : uint8_t
82
82
};
83
83
84
84
/* *
85
- * Complete block filter struct as defined in BIP 157.
85
+ * Complete block filter struct as defined in BIP 157. Serialization matches
86
+ * payload of "cfilter" messages.
86
87
*/
87
88
class BlockFilter
88
89
{
@@ -104,6 +105,35 @@ class BlockFilter
104
105
{
105
106
return m_filter.GetEncoded ();
106
107
}
108
+
109
+ template <typename Stream>
110
+ void Serialize (Stream& s) const {
111
+ s << m_block_hash
112
+ << static_cast <uint8_t >(m_filter_type)
113
+ << m_filter.GetEncoded ();
114
+ }
115
+
116
+ template <typename Stream>
117
+ void Unserialize (Stream& s) {
118
+ std::vector<unsigned char > encoded_filter;
119
+ uint8_t filter_type;
120
+
121
+ s >> m_block_hash
122
+ >> filter_type
123
+ >> encoded_filter;
124
+
125
+ m_filter_type = static_cast <BlockFilterType>(filter_type);
126
+
127
+ switch (m_filter_type) {
128
+ case BlockFilterType::BASIC:
129
+ m_filter = GCSFilter (m_block_hash.GetUint64 (0 ), m_block_hash.GetUint64 (1 ),
130
+ BASIC_FILTER_P, BASIC_FILTER_M, std::move (encoded_filter));
131
+ break ;
132
+
133
+ default :
134
+ throw std::ios_base::failure (" unknown filter_type" );
135
+ }
136
+ }
107
137
};
108
138
109
139
#endif // BITCOIN_BLOCKFILTER_H
You can’t perform that action at this time.
0 commit comments