@@ -62,7 +62,7 @@ pub struct TlsConfig {
6262
6363#[ derive( Debug , PartialEq , Eq ) ]
6464pub enum ChainSource {
65- Rpc { rpc_address : SocketAddr , rpc_user : String , rpc_password : String } ,
65+ Rpc { rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String } ,
6666 Electrum { server_url : String } ,
6767 Esplora { server_url : String } ,
6868}
@@ -79,7 +79,7 @@ struct ConfigBuilder {
7979 storage_dir_path : Option < String > ,
8080 electrum_url : Option < String > ,
8181 esplora_url : Option < String > ,
82- bitcoind_rpc_addr : Option < String > ,
82+ bitcoind_rpc_address : Option < String > ,
8383 bitcoind_rpc_user : Option < String > ,
8484 bitcoind_rpc_password : Option < String > ,
8585 rabbitmq_connection_string : Option < String > ,
@@ -108,7 +108,7 @@ impl ConfigBuilder {
108108 }
109109
110110 if let Some ( bitcoind) = toml. bitcoind {
111- self . bitcoind_rpc_addr = bitcoind. rpc_address . or ( self . bitcoind_rpc_addr . clone ( ) ) ;
111+ self . bitcoind_rpc_address = bitcoind. rpc_address . or ( self . bitcoind_rpc_address . clone ( ) ) ;
112112 self . bitcoind_rpc_user = bitcoind. rpc_user . or ( self . bitcoind_rpc_user . clone ( ) ) ;
113113 self . bitcoind_rpc_password =
114114 bitcoind. rpc_password . or ( self . bitcoind_rpc_password . clone ( ) ) ;
@@ -167,7 +167,7 @@ impl ConfigBuilder {
167167 }
168168
169169 if let Some ( bitcoind_rpc_address) = & args. bitcoind_rpc_address {
170- self . bitcoind_rpc_addr = Some ( bitcoind_rpc_address. clone ( ) ) ;
170+ self . bitcoind_rpc_address = Some ( bitcoind_rpc_address. clone ( ) ) ;
171171 }
172172
173173 if let Some ( bitcoind_rpc_user) = & args. bitcoind_rpc_user {
@@ -236,7 +236,7 @@ impl ConfigBuilder {
236236 } )
237237 . transpose ( ) ?;
238238
239- let rpc_configured = self . bitcoind_rpc_addr . is_some ( )
239+ let rpc_configured = self . bitcoind_rpc_address . is_some ( )
240240 || self . bitcoind_rpc_user . is_some ( )
241241 || self . bitcoind_rpc_password . is_some ( ) ;
242242 let electrum_configured = self . electrum_url . is_some ( ) ;
@@ -256,12 +256,9 @@ impl ConfigBuilder {
256256
257257 let chain_source = if rpc_configured {
258258 let rpc_address = self
259- . bitcoind_rpc_addr
260- . ok_or_else ( || missing_field_err ( "bitcoind_rpc_address" ) ) ?
261- . parse :: < SocketAddr > ( )
262- . map_err ( |e| {
263- io:: Error :: new ( io:: ErrorKind :: InvalidInput , format ! ( "Invalid RPC addr: {}" , e) )
264- } ) ?;
259+ . bitcoind_rpc_address
260+ . ok_or_else ( || missing_field_err ( "bitcoind_rpc_address" ) ) ?;
261+ let ( rpc_host, rpc_port) = parse_host_port ( & rpc_address) ?;
265262
266263 let rpc_user =
267264 self . bitcoind_rpc_user . ok_or_else ( || missing_field_err ( "bitcoind_rpc_user" ) ) ?;
@@ -270,7 +267,7 @@ impl ConfigBuilder {
270267 . bitcoind_rpc_password
271268 . ok_or_else ( || missing_field_err ( "bitcoind_rpc_password" ) ) ?;
272269
273- ChainSource :: Rpc { rpc_address , rpc_user, rpc_password }
270+ ChainSource :: Rpc { rpc_host , rpc_port , rpc_user, rpc_password }
274271 } else if let Some ( url) = self . electrum_url {
275272 ChainSource :: Electrum { server_url : url }
276273 } else if let Some ( url) = self . esplora_url {
@@ -518,7 +515,7 @@ pub struct ArgsConfig {
518515 #[ arg(
519516 long,
520517 env = "LDK_SERVER_BITCOIND_RPC_ADDRESS" ,
521- help = "The underlying Bitcoin node RPC address."
518+ help = "The underlying Bitcoin node RPC address (host:port) ."
522519 ) ]
523520 bitcoind_rpc_address : Option < String > ,
524521
@@ -595,6 +592,16 @@ fn parse_alias(alias_str: &str) -> Result<NodeAlias, io::Error> {
595592 Ok ( NodeAlias ( bytes) )
596593}
597594
595+ fn parse_host_port ( addr : & str ) -> io:: Result < ( String , u16 ) > {
596+ let ( host, port_str) = addr. rsplit_once ( ':' ) . ok_or_else ( || {
597+ io:: Error :: new ( io:: ErrorKind :: InvalidInput , "Invalid address format, expected host:port" )
598+ } ) ?;
599+ let port = port_str
600+ . parse :: < u16 > ( )
601+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , format ! ( "Invalid port: {}" , e) ) ) ?;
602+ Ok ( ( host. to_string ( ) , port) )
603+ }
604+
598605#[ cfg( test) ]
599606mod tests {
600607 use std:: str:: FromStr ;
@@ -717,7 +724,8 @@ mod tests {
717724 hosts : vec ! [ "example.com" . to_string( ) , "ldk-server.local" . to_string( ) ] ,
718725 } ) ,
719726 chain_source : ChainSource :: Rpc {
720- rpc_address : SocketAddr :: from_str ( "127.0.0.1:8332" ) . unwrap ( ) ,
727+ rpc_host : "127.0.0.1" . to_string ( ) ,
728+ rpc_port : 8332 ,
721729 rpc_user : "bitcoind-testuser" . to_string ( ) ,
722730 rpc_password : "bitcoind-testpassword" . to_string ( ) ,
723731 } ,
@@ -826,7 +834,7 @@ mod tests {
826834 file = "/var/log/ldk-server.log"
827835
828836 [bitcoind]
829- rpc_address = "127.0.0.1:8332" # RPC endpoint
837+ rpc_address = "127.0.0.1:8332"
830838 rpc_user = "bitcoind-testuser"
831839 rpc_password = "bitcoind-testpassword"
832840
@@ -849,11 +857,13 @@ mod tests {
849857 fs:: write ( storage_path. join ( config_file_name) , toml_config) . unwrap ( ) ;
850858 let config = load_config ( & args_config) . unwrap ( ) ;
851859
852- let ChainSource :: Rpc { rpc_address, rpc_user, rpc_password } = config. chain_source else {
860+ let ChainSource :: Rpc { rpc_host, rpc_port, rpc_user, rpc_password } = config. chain_source
861+ else {
853862 panic ! ( "unexpected chain source" ) ;
854863 } ;
855864
856- assert_eq ! ( rpc_address, SocketAddr :: from_str( "127.0.0.1:8332" ) . unwrap( ) ) ;
865+ assert_eq ! ( rpc_host, "127.0.0.1" ) ;
866+ assert_eq ! ( rpc_port, 8332 ) ;
857867 assert_eq ! ( rpc_user, "bitcoind-testuser" ) ;
858868 assert_eq ! ( rpc_password, "bitcoind-testpassword" ) ;
859869
@@ -880,7 +890,7 @@ mod tests {
880890 file = "/var/log/ldk-server.log"
881891
882892 [bitcoind]
883- rpc_address = "127.0.0.1:8332" # RPC endpoint
893+ rpc_address = "127.0.0.1:8332"
884894 rpc_user = "bitcoind-testuser"
885895 rpc_password = "bitcoind-testpassword"
886896
@@ -924,7 +934,7 @@ mod tests {
924934 rest_service_address = "127.0.0.1:3002"
925935
926936 [bitcoind]
927- rpc_address = "127.0.0.1:8332" # RPC endpoint
937+ rpc_address = "127.0.0.1:8332"
928938 rpc_user = "bitcoind-testuser"
929939 rpc_password = "bitcoind-testpassword"
930940
@@ -1007,6 +1017,8 @@ mod tests {
10071017 fn test_config_from_args_config ( ) {
10081018 let args_config = default_args_config ( ) ;
10091019 let config = load_config ( & args_config) . unwrap ( ) ;
1020+ let ( host, port) =
1021+ parse_host_port ( args_config. bitcoind_rpc_address . unwrap ( ) . as_str ( ) ) . unwrap ( ) ;
10101022
10111023 let expected = Config {
10121024 listening_addrs : Some ( vec ! [ SocketAddress :: from_str(
@@ -1026,10 +1038,8 @@ mod tests {
10261038 storage_dir_path : Some ( args_config. storage_dir_path . unwrap ( ) ) ,
10271039 tls_config : None ,
10281040 chain_source : ChainSource :: Rpc {
1029- rpc_address : SocketAddr :: from_str (
1030- args_config. bitcoind_rpc_address . as_deref ( ) . unwrap ( ) ,
1031- )
1032- . unwrap ( ) ,
1041+ rpc_host : host,
1042+ rpc_port : port,
10331043 rpc_user : args_config. bitcoind_rpc_user . unwrap ( ) ,
10341044 rpc_password : args_config. bitcoind_rpc_password . unwrap ( ) ,
10351045 } ,
@@ -1091,6 +1101,9 @@ mod tests {
10911101 #[ cfg( not( feature = "events-rabbitmq" ) ) ]
10921102 let ( expected_rabbit_conn, expected_rabbit_exchange) = ( String :: new ( ) , String :: new ( ) ) ;
10931103
1104+ let ( host, port) =
1105+ parse_host_port ( args_config. bitcoind_rpc_address . clone ( ) . unwrap ( ) . as_str ( ) ) . unwrap ( ) ;
1106+
10941107 let config = load_config ( & args_config) . unwrap ( ) ;
10951108 let expected = Config {
10961109 listening_addrs : Some ( vec ! [ SocketAddress :: from_str(
@@ -1114,10 +1127,8 @@ mod tests {
11141127 hosts : vec ! [ "example.com" . to_string( ) , "ldk-server.local" . to_string( ) ] ,
11151128 } ) ,
11161129 chain_source : ChainSource :: Rpc {
1117- rpc_address : SocketAddr :: from_str (
1118- args_config. bitcoind_rpc_address . as_deref ( ) . unwrap ( ) ,
1119- )
1120- . unwrap ( ) ,
1130+ rpc_host : host,
1131+ rpc_port : port,
11211132 rpc_user : args_config. bitcoind_rpc_user . unwrap ( ) ,
11221133 rpc_password : args_config. bitcoind_rpc_password . unwrap ( ) ,
11231134 } ,
0 commit comments