lightning_transaction_sync/lib.rs
1// This file is Copyright its original authors, visible in version control history.
2//
3// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6// accordance with one or both of these licenses.
7
8//! Provides utilities for syncing LDK via the transaction-based [`Confirm`] interface.
9//!
10//! The provided synchronization clients need to be registered with a [`ChainMonitor`] via the
11//! [`Filter`] interface. Then, the respective `fn sync` needs to be called with the [`Confirm`]
12//! implementations to be synchronized, i.e., usually instances of [`ChannelManager`] and
13//! [`ChainMonitor`].
14//!
15//! ## Features and Backend Support
16//!
17//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client.
18//!- `esplora-async` enables syncing against an Esplora backend based on an async client.
19//!- `esplora-async-https` enables the async Esplora client with support for HTTPS.
20//!
21//! ## Version Compatibility
22//!
23//! Currently this crate is compatible with LDK version 0.0.114 and above using channels which were
24//! created on LDK version 0.0.113 and above.
25//!
26//! ## Usage Example:
27//!
28//! ```ignore
29//! let tx_sync = Arc::new(EsploraSyncClient::new(
30//! esplora_server_url,
31//! Arc::clone(&some_logger),
32//! ));
33//!
34//! let chain_monitor = Arc::new(ChainMonitor::new(
35//! Some(Arc::clone(&tx_sync)),
36//! Arc::clone(&some_broadcaster),
37//! Arc::clone(&some_logger),
38//! Arc::clone(&some_fee_estimator),
39//! Arc::clone(&some_persister),
40//! ));
41//!
42//! let channel_manager = Arc::new(ChannelManager::new(
43//! Arc::clone(&some_fee_estimator),
44//! Arc::clone(&chain_monitor),
45//! Arc::clone(&some_broadcaster),
46//! Arc::clone(&some_router),
47//! Arc::clone(&some_logger),
48//! Arc::clone(&some_entropy_source),
49//! Arc::clone(&some_node_signer),
50//! Arc::clone(&some_signer_provider),
51//! user_config,
52//! chain_params,
53//! ));
54//!
55//! let confirmables = vec![
56//! &*channel_manager as &(dyn Confirm + Sync + Send),
57//! &*chain_monitor as &(dyn Confirm + Sync + Send),
58//! ];
59//!
60//! tx_sync.sync(confirmables).unwrap();
61//! ```
62//!
63//! [`Confirm`]: lightning::chain::Confirm
64//! [`Filter`]: lightning::chain::Filter
65//! [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
66//! [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
67
68#![deny(rustdoc::broken_intra_doc_links)]
69#![deny(rustdoc::private_intra_doc_links)]
70#![deny(missing_docs)]
71#![deny(unsafe_code)]
72#![cfg_attr(docsrs, feature(doc_auto_cfg))]
73
74#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
75mod esplora;
76
77#[cfg(any(feature = "electrum"))]
78mod electrum;
79
80#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
81mod common;
82#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
83mod error;
84#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
85pub use error::TxSyncError;
86
87#[cfg(feature = "electrum")]
88pub use electrum::ElectrumSyncClient;
89#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
90pub use esplora::EsploraSyncClient;