Crate ldk_node

Source
Expand description

§LDK Node

A ready-to-go Lightning node library built using LDK and BDK.

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.

§Getting Started

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, open_channel, send, etc.:

use ldk_node::Builder;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::bitcoin::Network;
use ldk_node::bitcoin::secp256k1::PublicKey;
use std::str::FromStr;

fn main() {
	let mut builder = Builder::new();
	builder.set_network(Network::Testnet);
	builder.set_chain_source_esplora("https://blockstream.info/testnet/api".to_string(), None);
	builder.set_gossip_source_rgs("https://rapidsync.lightningdevkit.org/testnet/snapshot".to_string());

	let node = builder.build().unwrap();

	node.start().unwrap();

	let funding_address = node.onchain_payment().new_address();

	// .. fund address ..

	let node_id = PublicKey::from_str("NODE_ID").unwrap();
	let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
	node.open_channel(node_id, node_addr, 10000, None, None).unwrap();

	let event = node.wait_next_event();
	println!("EVENT: {:?}", event);
	node.event_handled();

	let invoice = Bolt11Invoice::from_str("INVOICE_STR").unwrap();
	node.bolt11_payment().send(&invoice, None).unwrap();

	node.stop().unwrap();
}

Re-exports§

pub use bip39;
pub use bitcoin;
pub use lightning;
pub use lightning_invoice;
pub use vss_client;

Modules§

config
Objects for configuring the node.
graph
Objects for querying the network graph.
io
Objects and traits for data persistence.
payment
Objects for different types of payments.

Structs§

BalanceDetails
Details of the known available balances returned by Node::list_balances.
BuilderNon-uniffi
A builder for an Node instance, allowing to set some configuration and module choices from the getgo.
ChannelDetails
Details of a channel as returned by Node::list_channels.
Node
The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
NodeStatus
Represents the status of the Node.
PeerDetails
Details of a known Lightning peer as returned by Node::list_peers.
UserChannelId
A local, potentially user-provided, identifier of a channel.

Enums§

BuildError
An error encountered during building a Node.
Event
An event emitted by Node, which should be handled by the user.
LightningBalance
Details about the status of a known Lightning balance.
LogLevel
An enum representing the available verbosity levels of the logger.
NodeError
An error that possibly needs to be handled by the user.
PendingSweepBalance
Details about the status of a known balance currently being swept to our on-chain wallet.

Functions§

generate_entropy_mnemonic
Generates a random BIP 39 mnemonic.