Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,62 @@ We welcome your feedback and contributions to help shape the future of LDK Serve
### Configuration
Refer `./ldk-server/ldk-server-config.toml` to see available configuration options.

You can configure the node via a TOML file, environment variables, or CLI arguments. All options are optional — values provided via CLI override environment variables, which override the values in the TOML file.

### Building
```
git clone https://github.com/lightningdevkit/ldk-server.git
cargo build
```

### Running
- Using a config file:
```
cargo run --bin ldk-server ./ldk-server/ldk-server-config.toml
```

Interact with the node using CLI:
- Using environment variables (all optional):
```
export LDK_SERVER_NODE_NETWORK=regtest
export LDK_SERVER_NODE_LISTENING_ADDRESS=localhost:3001
export LDK_SERVER_NODE_REST_SERVICE_ADDRESS=127.0.0.1:3002
export LDK_SERVER_NODE_ALIAS=LDK-Server
export LDK_SERVER_BITCOIND_RPC_HOST=127.0.0.1
export LDK_SERVER_BITCOIND_RPC_PORT=18443
export LDK_SERVER_BITCOIND_RPC_USER=your-rpc-user
export LDK_SERVER_BITCOIND_RPC_PASSWORD=your-rpc-password
export LDK_SERVER_STORAGE_DIR_PATH=/path/to/storage
cargo run --bin ldk-server
```

- Using CLI arguments (all optional):
```
cargo run --bin ldk-server -- \
--node-network regtest \
--node-listening-address localhost:3001 \
--node-rest-service-address 127.0.0.1:3002 \
--node-alias LDK-Server \
--bitcoind-rpc-host 127.0.0.1 \
--bitcoind-rpc-port 18443 \
--bitcoind-rpc-user your-rpc-user \
--bitcoind-rpc-password your-rpc-password \
--storage-dir-path /path/to/storage
```

- Mixed configuration example (config file + overrides):
```
# config file sets listening_address = "localhost:3001"
cargo run --bin ldk-server ./ldk-server/ldk-server-config.toml --node-listening-address localhost:3009
# Result: `localhost:3009` will be used because CLI overrides the config file
```

### Interacting with the Node

Once running, use the CLI client:
```
./target/debug/ldk-server-cli -b localhost:3002 onchain-receive # To generate onchain-receive address.
./target/debug/ldk-server-cli -b localhost:3002 help # To print help/available commands.
# Generate an on-chain receive address
./target/debug/ldk-server-cli -b localhost:3002 onchain-receive

# View commands
./target/debug/ldk-server-cli -b localhost:3002 help
```
1 change: 1 addition & 0 deletions ldk-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rusqlite = { version = "0.31.0", features = ["bundled"] }
rand = { version = "0.8.5", default-features = false }
async-trait = { version = "0.1.85", default-features = false }
toml = { version = "0.8.9", default-features = false, features = ["parse"] }
clap = { version = "4.0.5", default-features = false, features = ["derive", "std", "error-context", "suggestions", "help", "env"] }

# Required for RabittMQ based EventPublisher. Only enabled for `events-rabbitmq` feature.
lapin = { version = "2.4.0", features = ["rustls"], default-features = false, optional = true }
Expand Down
7 changes: 4 additions & 3 deletions ldk-server/ldk-server-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ dir_path = "/tmp/ldk-server/" # Path for LDK and BDK data persis

# Bitcoin Core settings
[bitcoind]
rpc_address = "127.0.0.1:18444" # RPC endpoint
rpc_user = "polaruser" # RPC username
rpc_password = "polarpass" # RPC password
rpc_host = "127.0.0.1" # RPC host
rpc_port = 18444 # RPC port
rpc_user = "polaruser" # RPC username
rpc_password = "polarpass" # RPC password

# RabbitMQ settings (only required if using events-rabbitmq feature)
[rabbitmq]
Expand Down
37 changes: 9 additions & 28 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use tokio::signal::unix::SignalKind;
use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use clap::Parser;

use crate::io::events::event_publisher::{EventPublisher, NoopEventPublisher};
use crate::io::events::get_event_name;
#[cfg(feature = "events-rabbitmq")]
Expand All @@ -24,7 +26,7 @@ use crate::io::persist::{
FORWARDED_PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE, PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE,
PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::util::config::load_config;
use crate::util::config::{load_config, ArgsConfig};
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use hex::DisplayHex;
use ldk_node::config::Config;
Expand All @@ -36,38 +38,19 @@ use ldk_server_protos::events::{event_envelope, EventEnvelope};
use ldk_server_protos::types::Payment;
use prost::Message;
use rand::Rng;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::select;

const USAGE_GUIDE: &str = "Usage: ldk-server <config_path>";

fn main() {
let args: Vec<String> = std::env::args().collect();

if args.len() < 2 {
eprintln!("{USAGE_GUIDE}");
std::process::exit(-1);
}

let arg = args[1].as_str();
if arg == "-h" || arg == "--help" {
println!("{}", USAGE_GUIDE);
std::process::exit(0);
}

if fs::File::open(arg).is_err() {
eprintln!("Unable to access configuration file.");
std::process::exit(-1);
}
let args_config = ArgsConfig::parse();

let mut ldk_node_config = Config::default();
let config_file = match load_config(Path::new(arg)) {
let config_file = match load_config(&args_config) {
Ok(config) => config,
Err(e) => {
eprintln!("Invalid configuration file: {}", e);
eprintln!("Invalid configuration: {}", e);
std::process::exit(-1);
},
};
Expand All @@ -79,11 +62,9 @@ fn main() {
let mut builder = Builder::from_config(ldk_node_config);
builder.set_log_facade_logger();

let bitcoind_rpc_addr = config_file.bitcoind_rpc_addr;

builder.set_chain_source_bitcoind_rpc(
bitcoind_rpc_addr.ip().to_string(),
bitcoind_rpc_addr.port(),
config_file.bitcoind_rpc_host,
config_file.bitcoind_rpc_port,
config_file.bitcoind_rpc_user,
config_file.bitcoind_rpc_password,
);
Expand Down
Loading
Loading