bitcoint4/network/
message_filter.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Bitcoin Client Side Block Filtering network messages.
4//!
5//! This module describes BIP157 Client Side Block Filtering network messages.
6//!
7
8use crate::hash_types::{BlockHash, FilterHash, FilterHeader};
9use crate::internal_macros::impl_consensus_encoding;
10
11/// getcfilters message
12#[derive(PartialEq, Eq, Clone, Debug)]
13pub struct GetCFilters {
14    /// Filter type for which headers are requested
15    pub filter_type: u8,
16    /// The height of the first block in the requested range
17    pub start_height: u32,
18    /// The hash of the last block in the requested range
19    pub stop_hash: BlockHash,
20}
21impl_consensus_encoding!(GetCFilters, filter_type, start_height, stop_hash);
22
23/// cfilter message
24#[derive(PartialEq, Eq, Clone, Debug)]
25pub struct CFilter {
26    /// Byte identifying the type of filter being returned
27    pub filter_type: u8,
28    /// Block hash of the Bitcoin block for which the filter is being returned
29    pub block_hash: BlockHash,
30    /// The serialized compact filter for this block
31    pub filter: Vec<u8>,
32}
33impl_consensus_encoding!(CFilter, filter_type, block_hash, filter);
34
35/// getcfheaders message
36#[derive(PartialEq, Eq, Clone, Debug)]
37pub struct GetCFHeaders {
38    /// Byte identifying the type of filter being returned
39    pub filter_type: u8,
40    /// The height of the first block in the requested range
41    pub start_height: u32,
42    /// The hash of the last block in the requested range
43    pub stop_hash: BlockHash,
44}
45impl_consensus_encoding!(GetCFHeaders, filter_type, start_height, stop_hash);
46
47/// cfheaders message
48#[derive(PartialEq, Eq, Clone, Debug)]
49pub struct CFHeaders {
50    /// Filter type for which headers are requested
51    pub filter_type: u8,
52    /// The hash of the last block in the requested range
53    pub stop_hash: BlockHash,
54    /// The filter header preceding the first block in the requested range
55    pub previous_filter_header: FilterHeader,
56    /// The filter hashes for each block in the requested range
57    pub filter_hashes: Vec<FilterHash>,
58}
59impl_consensus_encoding!(CFHeaders, filter_type, stop_hash, previous_filter_header, filter_hashes);
60
61/// getcfcheckpt message
62#[derive(PartialEq, Eq, Clone, Debug)]
63pub struct GetCFCheckpt {
64    /// Filter type for which headers are requested
65    pub filter_type: u8,
66    /// The hash of the last block in the requested range
67    pub stop_hash: BlockHash,
68}
69impl_consensus_encoding!(GetCFCheckpt, filter_type, stop_hash);
70
71/// cfcheckpt message
72#[derive(PartialEq, Eq, Clone, Debug)]
73pub struct CFCheckpt {
74    /// Filter type for which headers are requested
75    pub filter_type: u8,
76    /// The hash of the last block in the requested range
77    pub stop_hash: BlockHash,
78    /// The filter headers at intervals of 1,000
79    pub filter_headers: Vec<FilterHeader>,
80}
81impl_consensus_encoding!(CFCheckpt, filter_type, stop_hash, filter_headers);