Skip to content

Commit 131d2de

Browse files
committed
Implement Lightning wallet sync, reorg handling, and UniFFI bindings for CBF
1 parent d98fb47 commit 131d2de

File tree

2 files changed

+292
-21
lines changed

2 files changed

+292
-21
lines changed

src/builder.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,18 @@ impl ArcedNodeBuilder {
824824
self.inner.write().unwrap().set_chain_source_electrum(server_url, sync_config);
825825
}
826826

827+
/// Configures the [`Node`] instance to source its chain data via BIP 157 compact block
828+
/// filters.
829+
///
830+
/// `peers` is an optional list of peer addresses to connect to for sourcing compact block
831+
/// filters. If empty, the node will discover peers via DNS seeds.
832+
///
833+
/// If no `sync_config` is given, default values are used. See [`CbfSyncConfig`] for more
834+
/// information.
835+
pub fn set_chain_source_cbf(&self, peers: Vec<String>, sync_config: Option<CbfSyncConfig>) {
836+
self.inner.write().unwrap().set_chain_source_cbf(peers, sync_config);
837+
}
838+
827839
/// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC.
828840
///
829841
/// This method establishes an RPC connection that enables all essential chain operations including
@@ -2005,6 +2017,9 @@ pub(crate) fn sanitize_alias(alias_str: &str) -> Result<NodeAlias, BuildError> {
20052017

20062018
#[cfg(test)]
20072019
mod tests {
2020+
#[cfg(feature = "uniffi")]
2021+
use crate::config::CbfSyncConfig;
2022+
20082023
use super::{sanitize_alias, BuildError, NodeAlias};
20092024

20102025
#[test]
@@ -2042,4 +2057,23 @@ mod tests {
20422057
let node = sanitize_alias(alias);
20432058
assert_eq!(node.err().unwrap(), BuildError::InvalidNodeAlias);
20442059
}
2060+
2061+
#[cfg(feature = "uniffi")]
2062+
#[test]
2063+
fn arced_builder_can_set_cbf_chain_source() {
2064+
let builder = super::ArcedNodeBuilder::new();
2065+
let sync_config = CbfSyncConfig::default();
2066+
2067+
let peers = vec!["127.0.0.1:8333".to_string()];
2068+
builder.set_chain_source_cbf(peers.clone(), Some(sync_config.clone()));
2069+
2070+
let guard = builder.inner.read().unwrap();
2071+
assert!(matches!(
2072+
guard.chain_data_source_config.as_ref(),
2073+
Some(super::ChainDataSourceConfig::Cbf {
2074+
peers: p,
2075+
sync_config: Some(config),
2076+
}) if config == &sync_config && p == &peers
2077+
));
2078+
}
20452079
}

0 commit comments

Comments
 (0)