floresta_compact_filters/
lib.rs#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::manual_is_multiple_of)]
use core::fmt::Debug;
use std::fmt::Display;
use std::sync::PoisonError;
use std::sync::RwLockWriteGuard;
use bitcoin::bip158;
use flat_filters_store::FlatFiltersStore;
pub mod flat_filters_store;
pub mod kv_filter_database;
pub mod network_filters;
pub trait BlockFilterStore: Send + Sync {
fn get_filter(&self, block_height: u32) -> Option<bip158::BlockFilter>;
fn put_filter(&self, block_height: u32, block_filter: bip158::BlockFilter);
fn put_height(&self, height: u32);
fn get_height(&self) -> Option<u32>;
}
pub enum IterableFilterStoreError {
Io(std::io::Error),
Eof,
Poisoned,
FilterTooLarge,
}
impl Debug for IterableFilterStoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IterableFilterStoreError::Io(e) => write!(f, "I/O error: {e}"),
IterableFilterStoreError::Eof => write!(f, "End of file"),
IterableFilterStoreError::Poisoned => write!(f, "Lock poisoned"),
IterableFilterStoreError::FilterTooLarge => write!(f, "Filter too large"),
}
}
}
impl From<std::io::Error> for IterableFilterStoreError {
fn from(e: std::io::Error) -> Self {
IterableFilterStoreError::Io(e)
}
}
impl Display for IterableFilterStoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
impl From<PoisonError<RwLockWriteGuard<'_, FlatFiltersStore>>> for IterableFilterStoreError {
fn from(_: PoisonError<RwLockWriteGuard<'_, FlatFiltersStore>>) -> Self {
IterableFilterStoreError::Poisoned
}
}
pub trait IterableFilterStore:
Send + Sync + IntoIterator<Item = (u32, bip158::BlockFilter)>
{
type I: Iterator<Item = (u32, bip158::BlockFilter)>;
fn iter(&self, start_height: Option<usize>) -> Result<Self::I, IterableFilterStoreError>;
fn put_filter(
&self,
block_filter: bip158::BlockFilter,
height: u32,
) -> Result<(), IterableFilterStoreError>;
fn set_height(&self, height: u32) -> Result<(), IterableFilterStoreError>;
fn get_height(&self) -> Result<u32, IterableFilterStoreError>;
}