diff --git a/ldk-server/ldk-server-config.toml b/ldk-server/ldk-server-config.toml index 45967f5..e4343b6 100644 --- a/ldk-server/ldk-server-config.toml +++ b/ldk-server/ldk-server-config.toml @@ -20,6 +20,11 @@ rpc_address = "127.0.0.1:18444" # RPC endpoint rpc_user = "polaruser" # RPC username rpc_password = "polarpass" # RPC password +# Electrum settings +[electrum] +server_url = "ssl://electrum.blockstream.info:50002" # Electrum endpoint +# server_url = "tcp://electrum.blockstream.info:50001" + # Esplora settings [esplora] server_url = "https://mempool.space/api" # Esplora endpoint diff --git a/ldk-server/src/main.rs b/ldk-server/src/main.rs index e16d5f0..70fad7e 100644 --- a/ldk-server/src/main.rs +++ b/ldk-server/src/main.rs @@ -123,6 +123,9 @@ fn main() { rpc_password, ); }, + ChainSource::Electrum { server_url } => { + builder.set_chain_source_electrum(server_url, None); + }, ChainSource::Esplora { server_url } => { builder.set_chain_source_esplora(server_url, None); }, diff --git a/ldk-server/src/util/config.rs b/ldk-server/src/util/config.rs index 79fda35..98a78f4 100644 --- a/ldk-server/src/util/config.rs +++ b/ldk-server/src/util/config.rs @@ -37,6 +37,7 @@ pub struct Config { #[derive(Debug)] pub enum ChainSource { Rpc { rpc_address: SocketAddr, rpc_user: String, rpc_password: String }, + Electrum { server_url: String }, Esplora { server_url: String }, } @@ -58,9 +59,12 @@ impl TryFrom for Config { format!("Invalid rest service address configured: {}", e), ) })?; - let chain_source = match (toml_config.esplora, toml_config.bitcoind) { - (Some(EsploraConfig { server_url }), None) => ChainSource::Esplora { server_url }, - (None, Some(BitcoindConfig { rpc_address, rpc_user, rpc_password })) => { + let chain_source = match (toml_config.esplora, toml_config.electrum, toml_config.bitcoind) { + (Some(EsploraConfig { server_url }), None, None) => ChainSource::Esplora { server_url }, + (None, Some(ElectrumConfig { server_url }), None) => { + ChainSource::Electrum { server_url } + }, + (None, None, Some(BitcoindConfig { rpc_address, rpc_user, rpc_password })) => { let rpc_address = SocketAddr::from_str(&rpc_address).map_err(|e| { io::Error::new( io::ErrorKind::InvalidInput, @@ -69,16 +73,18 @@ impl TryFrom for Config { })?; ChainSource::Rpc { rpc_address, rpc_user, rpc_password } }, - (Some(_), Some(_)) => { + (None, None, None) => { return Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("Must set a single chain source, multiple were configured"), + format!( + "At least one chain source must be set, either esplora, electrum, or bitcoind" + ), )) }, - (None, None) => { + _ => { return Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("At least one chain source must be set, either bitcoind or esplora"), + format!("Must set a single chain source, multiple were configured"), )) }, }; @@ -161,6 +167,7 @@ pub struct TomlConfig { node: NodeConfig, storage: StorageConfig, bitcoind: Option, + electrum: Option, esplora: Option, rabbitmq: Option, liquidity: Option, @@ -192,6 +199,11 @@ struct BitcoindConfig { rpc_password: String, } +#[derive(Deserialize, Serialize)] +struct ElectrumConfig { + server_url: String, +} + #[derive(Deserialize, Serialize)] struct EsploraConfig { server_url: String, @@ -370,6 +382,50 @@ mod tests { #[cfg(feature = "experimental-lsps2-support")] assert_eq!(config.lsps2_service_config.is_some(), expected.lsps2_service_config.is_some()); + // Test case where only electrum is set + + let toml_config = r#" + [node] + network = "regtest" + listening_address = "localhost:3001" + rest_service_address = "127.0.0.1:3002" + alias = "LDK Server" + + [storage.disk] + dir_path = "/tmp" + + [log] + level = "Trace" + file = "/var/log/ldk-server.log" + + [electrum] + server_url = "ssl://electrum.blockstream.info:50002" + + [rabbitmq] + connection_string = "rabbitmq_connection_string" + exchange_name = "rabbitmq_exchange_name" + + [liquidity.lsps2_service] + advertise_service = false + channel_opening_fee_ppm = 1000 # 0.1% fee + channel_over_provisioning_ppm = 500000 # 50% extra capacity + min_channel_opening_fee_msat = 10000000 # 10,000 satoshis + min_channel_lifetime = 4320 # ~30 days + max_client_to_self_delay = 1440 # ~10 days + min_payment_size_msat = 10000000 # 10,000 satoshis + max_payment_size_msat = 25000000000 # 0.25 BTC + client_trusts_lsp = true + "#; + + fs::write(storage_path.join(config_file_name), toml_config).unwrap(); + let config = load_config(storage_path.join(config_file_name)).unwrap(); + + let ChainSource::Electrum { server_url } = config.chain_source else { + panic!("unexpected chain source"); + }; + + assert_eq!(server_url, "ssl://electrum.blockstream.info:50002"); + // Test case where only bitcoind is set let toml_config = r#"