Skip to content

Commit f4c8486

Browse files
feat: add default rest_service_address
Make `rest_service_address` optional in the config file, defaulting to `127.0.0.1:3536` when not specified. This reduces required config for most users who don't need a custom REST address. Closes: #160 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 68ad8b1 commit f4c8486

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

ldk-server/ldk-server.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
// The Bitcoin network to use.
66
"network": "regtest",
77

8-
// The address on which LDK Server will accept incoming requests.
9-
"rest_service_address": "127.0.0.1:3002",
8+
// (Optional) The address on which LDK Server will accept incoming requests.
9+
// Defaults to 127.0.0.1:3536 if not specified.
10+
// "rest_service_address": "127.0.0.1:3536",
1011

1112
// The path where the underlying LDK and BDK persist their data.
1213
"storage_dir_path": "/tmp/ldk-server/",

ldk-server/src/util/config.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,25 @@ impl TryFrom<JsonConfig> for Config {
5757
}
5858
}
5959

60+
const DEFAULT_REST_SERVICE_ADDRESS: &str = "127.0.0.1:3536";
61+
6062
/// Configuration loaded from a JSON file.
6163
#[derive(Deserialize, Serialize)]
6264
pub struct JsonConfig {
6365
listening_address: String,
6466
network: Network,
67+
#[serde(default = "default_rest_service_address")]
6568
rest_service_address: String,
6669
storage_dir_path: String,
6770
bitcoind_rpc_address: String,
6871
bitcoind_rpc_user: String,
6972
bitcoind_rpc_password: String,
7073
}
7174

75+
fn default_rest_service_address() -> String {
76+
DEFAULT_REST_SERVICE_ADDRESS.to_string()
77+
}
78+
7279
/// Loads the configuration from a JSON file at the given path.
7380
pub fn load_config<P: AsRef<Path>>(config_path: P) -> io::Result<Config> {
7481
let file_contents = fs::read_to_string(config_path.as_ref()).map_err(|e| {
@@ -133,4 +140,34 @@ mod tests {
133140
}
134141
)
135142
}
143+
144+
#[test]
145+
fn test_default_rest_service_address() {
146+
let storage_path = std::env::temp_dir();
147+
let config_file_name = "config_no_rest_addr.json";
148+
149+
let json_config = r#"{
150+
"listening_address": "localhost:3001",
151+
"network": "regtest",
152+
"storage_dir_path": "/tmp",
153+
"bitcoind_rpc_address":"127.0.0.1:8332",
154+
"bitcoind_rpc_user": "bitcoind-testuser",
155+
"bitcoind_rpc_password": "bitcoind-testpassword"
156+
}"#;
157+
158+
fs::write(storage_path.join(config_file_name), json_config).unwrap();
159+
160+
assert_eq!(
161+
load_config(storage_path.join(config_file_name)).unwrap(),
162+
Config {
163+
listening_addr: SocketAddress::from_str("localhost:3001").unwrap(),
164+
network: Network::Regtest,
165+
rest_service_addr: SocketAddr::from_str("127.0.0.1:3536").unwrap(),
166+
storage_dir_path: "/tmp".to_string(),
167+
bitcoind_rpc_addr: SocketAddr::from_str("127.0.0.1:8332").unwrap(),
168+
bitcoind_rpc_user: "bitcoind-testuser".to_string(),
169+
bitcoind_rpc_password: "bitcoind-testpassword".to_string(),
170+
}
171+
)
172+
}
136173
}

0 commit comments

Comments
 (0)