Skip to content

Commit e88b765

Browse files
authored
Add initial README and crate-level docs (#49)
1 parent 8bc5c40 commit e88b765

File tree

2 files changed

+105
-12
lines changed

2 files changed

+105
-12
lines changed

README.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# LDK Node
2-
A ready-to-go node implementation built using LDK.
2+
A ready-to-go Lightning node library built using [LDK](https://lightningdevkit.org/) and [BDK](https://bitcoindevkit.org/).
3+
4+
LDK Node is a non-custodial Lightning node in library form. Its central goal is to provide a small, simple, and straightforward interface that enables users to easily set up and run a Lightning node with an integrated on-chain wallet. While minimalism is at its core, LDK Node aims to be sufficiently modular and configurable to be useful for a variety of use cases.
5+
6+
## Getting Started
7+
8+
The primary abstraction of the library is the `Node`, which can be retrieved by setting up and configuring a `Builder` to your liking and calling `build()`. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send_payment`, etc.:
9+
10+
```rust
11+
use ldk_node::Builder;
12+
use ldk_node::lightning_invoice::Invoice;
13+
use std::str::FromStr;
14+
15+
fn main() {
16+
let node = Builder::new()
17+
.set_network("testnet")
18+
.set_esplora_server_url("https://blockstream.info/testnet/api".to_string())
19+
.build();
20+
21+
node.start().unwrap();
22+
23+
let _funding_address = node.new_funding_address();
24+
25+
// .. fund address ..
26+
27+
node.sync_wallets().unwrap();
28+
29+
node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, false).unwrap();
30+
31+
let invoice = Invoice::from_str("INVOICE_STR").unwrap();
32+
node.send_payment(invoice).unwrap();
33+
34+
node.stop().unwrap();
35+
}
36+
```
37+
38+
## Modularity
39+
40+
LDK Node currently comes with a decidedly opionated set of design choices:
41+
42+
- On-chain data is handled by the integrated BDK wallet
43+
- Chain data is accessed via Esplora (support for Electrum and `bitcoind` RPC will follow)
44+
- Wallet and channel state is persisted to file system (support for SQLite will follow)
45+
- Gossip data is sourced via Lightnings peer-to-peer network (support for [Rapid Gossip Sync](https://docs.rs/lightning-rapid-gossip-sync/*/lightning_rapid_gossip_sync/) will follow)
46+
- Entropy for the Lightning and on-chain wallets may be generated and persisted for or provided by the user (support for [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonics will follow)
47+
48+
49+
## Language Support
50+
51+
LDK Node is written in [Rust](https://www.rust-lang.org/) and may therefore be natively included in any `std` Rust program. Beyond its Rust API it also offers language bindings for Swift, Kotlin, and Python based on [UniFFI](https://github.com/mozilla/uniffi-rs/).

src/lib.rs

+55-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,56 @@
99

1010
#![crate_name = "ldk_node"]
1111

12-
//! A library providing a simplified API for the Lightning Dev Kit. While LDK itself provides a
13-
//! highly configurable and adaptable interface, this API champions simplicity and ease of use over
14-
//! configurability. To this end, it provides an opionated set of design choices and ready-to-go
15-
//! default modules, while still enabling some configurability when dearly needed by the user:
16-
//! - Chain data is accessed through an Esplora client.
17-
//! - Wallet and channel states are persisted to disk.
18-
//! - Gossip is retrieved over the P2P network.
19-
12+
//! # LDK Node
13+
//! A ready-to-go Lightning node library built using [LDK](https://lightningdevkit.org/) and
14+
//! [BDK](https://bitcoindevkit.org/).
15+
//!
16+
//! LDK Node is a non-custodial Lightning node in library form. Its central goal is to provide a
17+
//! small, simple, and straightforward interface that enables users to easily set up and run a
18+
//! Lightning node with an integrated on-chain wallet. While minimalism is at its core, LDK Node
19+
//! aims to be sufficiently modular and configurable to be useful for a variety of use cases.
20+
//!
21+
//! ## Getting Started
22+
//!
23+
//! The primary abstraction of the library is the [`Node`], which can be retrieved by setting up
24+
//! and configuring a [`Builder`] to your liking and calling [`build`]. `Node` can then be
25+
//! controlled via commands such as [`start`], [`stop`], [`connect_open_channel`],
26+
//! [`send_payment`], etc.:
27+
//!
28+
//! ```no_run
29+
//! use ldk_node::Builder;
30+
//! use ldk_node::lightning_invoice::Invoice;
31+
//! use std::str::FromStr;
32+
//!
33+
//! fn main() {
34+
//! let node = Builder::new()
35+
//! .set_network("testnet")
36+
//! .set_esplora_server_url("https://blockstream.info/testnet/api".to_string())
37+
//! .build();
38+
//!
39+
//! node.start().unwrap();
40+
//!
41+
//! let _funding_address = node.new_funding_address();
42+
//!
43+
//! // .. fund address ..
44+
//!
45+
//! node.sync_wallets().unwrap();
46+
//!
47+
//! node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, false).unwrap();
48+
//!
49+
//! let invoice = Invoice::from_str("INVOICE_STR").unwrap();
50+
//! node.send_payment(invoice).unwrap();
51+
//!
52+
//! node.stop().unwrap();
53+
//! }
54+
//! ```
55+
//!
56+
//! [`build`]: Builder::build
57+
//! [`start`]: Node::start
58+
//! [`stop`]: Node::stop
59+
//! [`connect_open_channel`]: Node::connect_open_channel
60+
//! [`send_payment`]: Node::send_payment
61+
//!
2062
#![deny(missing_docs)]
2163
#![deny(broken_intra_doc_links)]
2264
#![deny(private_intra_doc_links)]
@@ -273,7 +315,7 @@ impl Builder {
273315
config.network,
274316
database,
275317
)
276-
.expect("Failed to setup on-chain wallet");
318+
.expect("Failed to set up on-chain wallet");
277319

278320
let tx_sync = Arc::new(EsploraSyncClient::new(
279321
config.esplora_server_url.clone(),
@@ -482,7 +524,7 @@ struct Runtime {
482524
stop_wallet_sync: Arc<AtomicBool>,
483525
}
484526

485-
/// The main interface object of the simplified API, wrapping the necessary LDK and BDK functionalities.
527+
/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
486528
///
487529
/// Needs to be initialized and instantiated through [`Builder::build`].
488530
pub struct Node {
@@ -716,12 +758,14 @@ impl Node {
716758

717759
/// Blocks until the next event is available.
718760
///
719-
/// Note: this will always return the same event until handling is confirmed via [`Node::event_handled`].
761+
/// **Note:** this will always return the same event until handling is confirmed via [`Node::event_handled`].
720762
pub fn next_event(&self) -> Event {
721763
self.event_queue.next_event()
722764
}
723765

724766
/// Confirm the last retrieved event handled.
767+
///
768+
/// **Note:** This **MUST** be called after each event has been handled.
725769
pub fn event_handled(&self) {
726770
self.event_queue.event_handled().unwrap();
727771
}

0 commit comments

Comments
 (0)