Compact Filters blockchain implementation

This commit is contained in:
Alekos Filini
2020-08-25 16:07:26 +02:00
parent c12aa3d327
commit 77c95b93ac
14 changed files with 2185 additions and 50 deletions

View File

@@ -19,10 +19,14 @@ pub mod esplora;
#[cfg(feature = "esplora")]
pub use self::esplora::EsploraBlockchain;
#[cfg(feature = "compact_filters")]
pub mod compact_filters;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Capability {
FullHistory,
GetAnyTx,
AccurateFees,
}
pub trait Blockchain {
@@ -46,13 +50,13 @@ impl Blockchain for OfflineBlockchain {
pub trait OnlineBlockchain: Blockchain {
fn get_capabilities(&self) -> HashSet<Capability>;
fn setup<D: BatchDatabase + DatabaseUtils, P: Progress>(
fn setup<D: BatchDatabase + DatabaseUtils, P: 'static + Progress>(
&self,
stop_gap: Option<usize>,
database: &mut D,
progress_update: P,
) -> Result<(), Error>;
fn sync<D: BatchDatabase + DatabaseUtils, P: Progress>(
fn sync<D: BatchDatabase + DatabaseUtils, P: 'static + Progress>(
&self,
stop_gap: Option<usize>,
database: &mut D,
@@ -70,7 +74,7 @@ pub trait OnlineBlockchain: Blockchain {
pub type ProgressData = (f32, Option<String>);
pub trait Progress {
pub trait Progress: Send {
fn update(&self, progress: f32, message: Option<String>) -> Result<(), Error>;
}
@@ -89,6 +93,7 @@ impl Progress for Sender<ProgressData> {
}
}
#[derive(Clone)]
pub struct NoopProgress;
pub fn noop_progress() -> NoopProgress {
@@ -100,3 +105,18 @@ impl Progress for NoopProgress {
Ok(())
}
}
#[derive(Clone)]
pub struct LogProgress;
pub fn log_progress() -> LogProgress {
LogProgress
}
impl Progress for LogProgress {
fn update(&self, progress: f32, message: Option<String>) -> Result<(), Error> {
log::info!("Sync {:.3}%: `{}`", progress, message.unwrap_or("".into()));
Ok(())
}
}