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