Skip to content

Commit 29a5d57

Browse files
committed
f Improve docs and usage example
1 parent d7550cb commit 29a5d57

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

lightning-transaction-sync/src/esplora.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ use core::ops::Deref;
1818

1919
/// Synchronizes LDK with a given [`Esplora`] server.
2020
///
21-
/// Needs to be registerd with a [`ChainMonitor`] via the [`Filter`] interface to be informed of
22-
/// transactions and outputs to montor.
21+
/// Needs to be registered with a [`ChainMonitor`] via the [`Filter`] interface to be informed of
22+
/// transactions and outputs to monitor for on-chain confirmation, unconfirmation, and
23+
/// reconfirmation.
2324
///
2425
/// [`Esplora`]: https://github.com/Blockstream/electrs
2526
/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
@@ -49,7 +50,7 @@ where
4950
EsploraSyncClient::from_client(client, logger)
5051
}
5152

52-
/// Returns a new [`EsploraSyncClient`] object using the given esplora client.
53+
/// Returns a new [`EsploraSyncClient`] object using the given Esplora client.
5354
pub fn from_client(client: EsploraClientType, logger: L) -> Self {
5455
let sync_state = MutexType::new(SyncState::new());
5556
let queue = std::sync::Mutex::new(FilterQueue::new());
@@ -61,10 +62,17 @@ where
6162
}
6263
}
6364

64-
/// Synchronizes the given confirmables via the [`Confirm`] interface. This method should be
65-
/// called regularly to keep LDK up-to-date with current chain data.
65+
/// Synchronizes the given `confirmables` via their [`Confirm`] interface implementations. This
66+
/// method should be called regularly to keep LDK up-to-date with current chain data.
67+
///
68+
/// For example, instances of [`ChannelManager`] and [`ChainMonitor`] can be informed about the
69+
/// newest on-chain activity related to the items previously registered via the [`Filter`]
70+
/// interface.
6671
///
6772
/// [`Confirm`]: lightning::chain::Confirm
73+
/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
74+
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
75+
/// [`Filter`]: lightning::chain::Filter
6876
#[maybe_async]
6977
pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> {
7078
// This lock makes sure we're syncing once at a time.

lightning-transaction-sync/src/lib.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
//! Provides utilities for syncing LDK via the transaction-based [`Confirm`] interface.
22
//!
3+
//! The provided synchronization clients need to be registered with a [`ChainMonitor`] via the
4+
//! [`Filter`] interface. Then, the respective `fn sync` needs to be called with the [`Confirm`]
5+
//! implementations to be synchronized, i.e., usually instances of [`ChannelManager`] and
6+
//! [`ChainMonitor`].
7+
//!
8+
//! ## Features and Backend Support
9+
//!
10+
//!- `esplora_blocking` enables syncing against an Esplora backend based on a blocking.
11+
//!- `esplora_async` enables syncing against an Esplora backend based on an async client.
12+
//!
13+
//! ## Usage Example:
14+
//!
15+
//! ```ignore
16+
//! let tx_sync = Arc::new(EsploraSyncClient::new(
17+
//! esplora_server_url,
18+
//! Arc::clone(&some_logger),
19+
//! ));
20+
//!
21+
//! let chain_monitor = Arc::new(ChainMonitor::new(
22+
//! Some(Arc::clone(&tx_sync)),
23+
//! Arc::clone(&some_broadcaster),
24+
//! Arc::clone(&some_logger),
25+
//! Arc::clone(&some_fee_estimator),
26+
//! Arc::clone(&some_persister),
27+
//! ));
28+
//!
29+
//! let channel_manager = Arc::new(ChannelManager::new(
30+
//! Arc::clone(&some_fee_estimator),
31+
//! Arc::clone(&chain_monitor),
32+
//! Arc::clone(&some_broadcaster),
33+
//! Arc::clone(&some_router),
34+
//! Arc::clone(&some_logger),
35+
//! Arc::clone(&some_entropy_source),
36+
//! Arc::clone(&some_node_signer),
37+
//! Arc::clone(&some_signer_provider),
38+
//! user_config,
39+
//! chain_params,
40+
//! ));
41+
//!
42+
//! let confirmables = vec![
43+
//! &*channel_manager as &(dyn Confirm + Sync + Send),
44+
//! &*chain_monitor as &(dyn Confirm + Sync + Send),
45+
//! ];
46+
//!
47+
//! tx_sync.sync(confirmables).unwrap();
48+
//! ```
49+
//!
350
//! [`Confirm`]: lightning::chain::Confirm
51+
//! [`Filter`]: lightning::chain::Filter
52+
//! [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
53+
//! [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
454
555
// Prefix these with `rustdoc::` when we update our MSRV to be >= 1.52 to remove warnings.
656
#![deny(broken_intra_doc_links)]

0 commit comments

Comments
 (0)