Skip to content
Closed
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
131 changes: 131 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum BdkError {
"Sled",
"Rusqlite",
"Rpc",
"CompactFilters",
};

dictionary AddressInfo {
Expand Down Expand Up @@ -155,11 +156,23 @@ dictionary RpcConfig {
RpcSyncParams? sync_params;
};




dictionary CompactFiltersConfig {
sequence<string> addresses;
Network network;
string storage_dir;
u32 skip_blocks;
};


[Enum]
interface BlockchainConfig {
Electrum(ElectrumConfig config);
Esplora(EsploraConfig config);
Rpc(RpcConfig config);
Cbf(CompactFiltersConfig config);
};

interface Blockchain {
Expand Down Expand Up @@ -221,8 +234,6 @@ interface Wallet {
[Throws=BdkError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network, DatabaseConfig database_config);

Network network();

[Throws=BdkError]
AddressInfo get_address(AddressIndex address_index);

Expand Down
57 changes: 57 additions & 0 deletions bdk-ffi/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::{BdkError, Transaction};
use bdk::bitcoin::Network;
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
use bdk::blockchain::compact_filters::nakamoto::CBFBlockchainConfig;
use bdk::blockchain::rpc::Auth as BdkAuth;
use bdk::blockchain::rpc::RpcSyncParams as BdkRpcSyncParams;
use bdk::blockchain::Blockchain as BdkBlockchain;
Expand All @@ -10,6 +11,7 @@ use bdk::blockchain::GetHeight;
use bdk::blockchain::{
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig,
rpc::RpcConfig as BdkRpcConfig, ConfigurableBlockchain,
compact_filters::CompactFiltersBlockchainConfig, compact_filters::BitcoinPeerConfig,
};
use bdk::FeeRate;
use std::convert::{From, TryFrom};
Expand Down Expand Up @@ -42,13 +44,58 @@ impl Blockchain {
timeout: config.timeout,
})
}
BlockchainConfig::Cbf { config } => {

let mut peers = Vec::new();
let peer = BitcoinPeerConfig{
address:config.address,
socks5:None,
socks5_credentials:None
};
peers.push(peer);



AnyBlockchainConfig::CompactFilters(CompactFiltersBlockchainConfig {
peers: peers,
network: config.network,
storage_dir: config.storage_dir,
skip_blocks : match usize::try_from(config.skip_blocks) {
Ok(value) => Some(value),
Err(_) => None,
}
,
})
}
BlockchainConfig::Rpc { config } => AnyBlockchainConfig::Rpc(BdkRpcConfig {
url: config.url,
auth: config.auth.into(),
network: config.network,
wallet_name: config.wallet_name,
sync_params: config.sync_params.map(|p| p.into()),
}),
// TODO: not sure this is the right way to deal with the PathBuf
// Attempt 1, if you make datadir an Option<String> in the CBFConfig struct
// BlockchainConfig::CBF { config } => {
// let path0: String = config
// .datadir
// .map(|d| d)
// .unwrap_or(String::from("./nakamoto/"));
// let path: PathBuf = PathBuf::from(path0);
// AnyBlockchainConfig::CompactFilters(CBFBlockchainConfig {
// network: config.network,
// datadir: Some(path),
// })
// }

// Attempt 2, if you make the datadir field mandatory
BlockchainConfig::CBF { config } => {
AnyBlockchainConfig::CompactFilters(CBFBlockchainConfig {
network: config.network,
datadir: Some(PathBuf::from(config.datadir)),
})
}
})
};
let blockchain = AnyBlockchain::from_config(&any_blockchain_config)?;
Ok(Self {
Expand Down Expand Up @@ -190,6 +237,14 @@ pub struct RpcConfig {
pub sync_params: Option<RpcSyncParams>,
}


pub struct CompactFiltersConfig {
pub addresses: Vec<String>,
pub network: Network,
pub storage_dir: String,
pub skip_blocks: u32,
}

/// Type that can contain any of the blockchain configurations defined by the library.
pub enum BlockchainConfig {
/// Electrum client
Expand All @@ -198,4 +253,6 @@ pub enum BlockchainConfig {
Esplora { config: EsploraConfig },
/// Bitcoin Core RPC client
Rpc { config: RpcConfig },
/// CompactFilters
Cbf { config: CompactFiltersConfig },
}
2 changes: 1 addition & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod psbt;
mod wallet;

use crate::blockchain::{
Auth, Blockchain, BlockchainConfig, ElectrumConfig, EsploraConfig, RpcConfig, RpcSyncParams,
Auth, Blockchain, BlockchainConfig, ElectrumConfig, EsploraConfig, RpcConfig, CompactFiltersConfig, RpcSyncParams,
};
use crate::database::DatabaseConfig;
use crate::descriptor::Descriptor;
Expand Down