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.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,33 @@ 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
```

- 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
```

Interact with the node using CLI:
```
ldk-server-cli -b localhost:3002 --api-key your-secret-api-key --tls-cert /path/to/tls_cert.pem onchain-receive # To generate onchain-receive address.
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
46 changes: 6 additions & 40 deletions ldk-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};

use clap::Parser;
use hex::DisplayHex;
use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;
Expand Down Expand Up @@ -48,15 +49,14 @@ use crate::io::persist::{
PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::service::NodeService;
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;

const DEFAULT_CONFIG_FILE: &str = "config.toml";
const API_KEY_FILE: &str = "api_key";

fn get_default_data_dir() -> Option<PathBuf> {
pub fn get_default_data_dir() -> Option<PathBuf> {
#[cfg(target_os = "macos")]
{
#[allow(deprecated)] // todo can remove once we update MSRV to 1.87+
Expand All @@ -73,48 +73,14 @@ fn get_default_data_dir() -> Option<PathBuf> {
}
}

fn get_default_config_path() -> Option<PathBuf> {
get_default_data_dir().map(|data_dir| data_dir.join(DEFAULT_CONFIG_FILE))
}

const USAGE_GUIDE: &str = "Usage: ldk-server [config_path]

If no config path is provided, ldk-server will look for a config file at:
Linux: ~/.ldk-server/config.toml
macOS: ~/Library/Application Support/ldk-server/config.toml
Windows: %APPDATA%\\ldk-server\\config.toml";

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

let config_path: PathBuf = if args.len() < 2 {
match get_default_config_path() {
Some(path) => path,
None => {
eprintln!("Unable to determine home directory for default config path.");
eprintln!("{USAGE_GUIDE}");
std::process::exit(-1);
},
}
} else {
let arg = args[1].as_str();
if arg == "-h" || arg == "--help" {
println!("{USAGE_GUIDE}");
std::process::exit(0);
}
PathBuf::from(arg)
};

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

let mut ldk_node_config = Config::default();
let config_file = match load_config(&config_path) {
let config_file = match load_config(&args_config) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config path and the args above is never used now. We should be able to remove that logic as we use clap now, but we still should check for the default config file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Ok(config) => config,
Err(e) => {
eprintln!("Invalid configuration file: {}", e);
eprintln!("Invalid configuration: {e}");
std::process::exit(-1);
},
};
Expand Down
Loading