Skip to content

Commit

Permalink
Add compact block filters blockchain feature using the Nakamoto client
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Oct 13, 2022
1 parent 1cc9afa commit dca9209
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ crate-type = ["staticlib", "cdylib"]
name = "bdkffi"

[dependencies]
bdk = { version = "0.22", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled"] }
# bdk = { version = "0.22", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled"] }
bdk = { git = "https://github.com/rajarshimaitra/bdk.git", branch = "cbf", features = ["all-keys", "use-esplora-ureq", "sqlite-bundled", "compact_filters"] }

uniffi_macros = { version = "0.19.3", features = ["builtin-bindgen"] }
uniffi = { version = "0.19.3", features = ["builtin-bindgen"] }
Expand Down
7 changes: 7 additions & 0 deletions src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum BdkError {
"Esplora",
"Sled",
"Rusqlite",
"Cbf",
};

dictionary AddressInfo {
Expand Down Expand Up @@ -127,10 +128,16 @@ dictionary EsploraConfig {
u64? timeout;
};

dictionary CBFConfig {
Network network;
string? datadir;
};

[Enum]
interface BlockchainConfig {
Electrum(ElectrumConfig config);
Esplora(EsploraConfig config);
CBF(CBFConfig config);
};

interface Blockchain {
Expand Down
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
use bdk::blockchain::GetBlockHash;
use bdk::blockchain::GetHeight;
use bdk::blockchain::{
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
compact_filters::nakamoto::CBFBlockchainConfig, electrum::ElectrumBlockchainConfig,
esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
};
use bdk::blockchain::{Blockchain as BdkBlockchain, Progress as BdkProgress};
use bdk::database::any::{AnyDatabase, SledDbConfiguration, SqliteDbConfiguration};
Expand All @@ -30,6 +31,7 @@ use std::collections::HashSet;
use std::convert::{From, TryFrom};
use std::fmt;
use std::ops::Deref;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::{Arc, Mutex, MutexGuard};

Expand Down Expand Up @@ -131,12 +133,19 @@ pub struct EsploraConfig {
pub timeout: Option<u64>,
}

pub struct CBFConfig {
network: Network,
datadir: Option<String>,
}

/// Type that can contain any of the blockchain configurations defined by the library.
pub enum BlockchainConfig {
/// Electrum client
Electrum { config: ElectrumConfig },
/// Esplora client
Esplora { config: EsploraConfig },
/// Nakamoto client
CBF { config: CBFConfig },
}

/// A wallet transaction
Expand Down Expand Up @@ -197,6 +206,22 @@ impl Blockchain {
timeout: config.timeout,
})
}
// TODO: not sure this is the right way to deal with the PathBuf
// This String to PathBuf conversion is not working out well
BlockchainConfig::CBF { config } => {
let path0: String = config
.datadir
.map(|d| d)
.unwrap_or(String::from("./nakamoto/"));
let path: PathBuf = PathBuf::from(path0);
// let path: PathBuf = PathBuf::from("./nakamoto/");
AnyBlockchainConfig::CompactFilters(CBFBlockchainConfig {
network: config.network,
datadir: Some(path),
// datadir: Option::from(PathBuf::from_str(config.datadir.unwrap_or_default(".".to_string()))),
// datadir: Option::from(PathBuf::from(config.datadir)),
})
}
};
let blockchain = AnyBlockchain::from_config(&any_blockchain_config)?;
Ok(Self {
Expand Down

0 comments on commit dca9209

Please sign in to comment.