Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsused filter method, move to mod #189

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ use crate::{
cfheader_batch::CFHeaderBatch,
cfheader_chain::{AppendAttempt, CFHeaderChain, QueuedCFHeader},
error::{CFHeaderSyncError, CFilterSyncError},
filter::Filter,
filter_chain::FilterChain,
CF_HEADER_BATCH_SIZE, FILTER_BATCH_SIZE,
Filter, CF_HEADER_BATCH_SIZE, FILTER_BATCH_SIZE,
},
prelude::{params_from_network, MEDIAN_TIME_PAST},
IndexedBlock,
Expand Down
85 changes: 0 additions & 85 deletions src/filters/filter.rs

This file was deleted.

49 changes: 48 additions & 1 deletion src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,52 @@ pub(crate) mod cfheader_batch;
pub(crate) mod cfheader_chain;
#[allow(dead_code)]
pub(crate) mod error;
pub(crate) mod filter;
pub(crate) mod filter_chain;

use std::collections::HashSet;

use bitcoin::{bip158::BlockFilter, BlockHash, FilterHash, ScriptBuf};
use bitcoin_hashes::{sha256d, Hash};

use error::FilterError;

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Filter {
filter_hash: FilterHash,
block_hash: BlockHash,
block_filter: BlockFilter,
}

#[allow(dead_code)]
impl Filter {
pub fn new(contents: Vec<u8>, block_hash: BlockHash) -> Self {
let hash = sha256d::Hash::hash(&contents);
let filter_hash = FilterHash::from_raw_hash(hash);
let block_filter = BlockFilter::new(&contents);
Self {
filter_hash,
block_hash,
block_filter,
}
}

pub fn filter_hash(&self) -> &FilterHash {
&self.filter_hash
}

pub fn block_hash(&self) -> &BlockHash {
&self.block_hash
}

pub async fn contains_any(
&mut self,
scripts: &HashSet<ScriptBuf>,
) -> Result<bool, FilterError> {
self.block_filter
.match_any(
&self.block_hash,
&mut scripts.iter().map(|script| script.to_bytes()),
)
.map_err(|_| FilterError::IORead)
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod filters;
mod network;
mod prelude;
#[cfg(feature = "silent-payments")]
use filters::filter::Filter;
use filters::Filter;
#[cfg(feature = "silent-payments")]
use std::collections::HashSet;

Expand Down
Loading