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.

18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,34 @@ 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_ADDRESS=127.0.0.1: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):
```
./target/debug/ldk-server-cli -b localhost:3002 --api-key your-secret-api-key onchain-receive # To generate onchain-receive address.
./target/debug/ldk-server-cli -b localhost:3002 --api-key your-secret-api-key help # To print help/available commands.
Expand Down
1 change: 1 addition & 0 deletions ldk-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ toml = { version = "0.8.9", default-features = false, features = ["parse"] }
chrono = { version = "0.4", default-features = false, features = ["clock"] }
log = "0.4.28"
base64 = { version = "0.21", default-features = false, features = ["std"] }
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
31 changes: 7 additions & 24 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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;
use crate::io::events::get_event_name;
#[cfg(feature = "events-rabbitmq")]
Expand All @@ -34,7 +36,7 @@ use crate::io::persist::{
FORWARDED_PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE, PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE,
PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::util::config::{load_config, ChainSource};
use crate::util::config::{load_config, ArgsConfig, ChainSource};
use crate::util::logger::ServerLogger;
use crate::util::proto_adapter::{forwarded_payment_to_proto, payment_to_proto};
use crate::util::tls::get_or_generate_tls_config;
Expand All @@ -47,38 +49,19 @@ use ldk_server_protos::types::Payment;
use log::{error, info};
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 Down
Loading