@@ -12,7 +12,8 @@ use std::path::PathBuf;
1212use clap:: { CommandFactory , Parser , Subcommand } ;
1313use clap_complete:: { generate, Shell } ;
1414use config:: {
15- get_default_api_key_path, get_default_cert_path, get_default_config_path, load_config,
15+ api_key_path_for_storage_dir, cert_path_for_storage_dir, get_default_api_key_path,
16+ get_default_cert_path, get_default_config_path, load_config,
1617} ;
1718use hex_conservative:: DisplayHex ;
1819use ldk_server_client:: client:: LdkServerClient ;
@@ -433,15 +434,22 @@ async fn main() {
433434
434435 let config_path = cli. config . map ( PathBuf :: from) . or_else ( get_default_config_path) ;
435436 let config = config_path. as_ref ( ) . and_then ( |p| load_config ( p) . ok ( ) ) ;
437+ let storage_dir =
438+ config. as_ref ( ) . and_then ( |c| c. storage . as_ref ( ) ?. disk . as_ref ( ) ?. dir_path . as_deref ( ) ) ;
436439
437- // Get API key from argument, then from api_key file
440+ // Get API key from argument, then from api_key file in storage dir, then from default location
438441 let api_key = cli
439442 . api_key
440443 . or_else ( || {
441- // Try to read from api_key file based on network (file contains raw bytes)
442- let network = config. as_ref ( ) . and_then ( |c| c. network ( ) . ok ( ) ) . unwrap_or ( "bitcoin" . to_string ( ) ) ;
443- get_default_api_key_path ( & network)
444+ let network =
445+ config. as_ref ( ) . and_then ( |c| c. network ( ) . ok ( ) ) . unwrap_or ( "bitcoin" . to_string ( ) ) ;
446+ storage_dir
447+ . map ( |dir| api_key_path_for_storage_dir ( dir, & network) )
444448 . and_then ( |path| std:: fs:: read ( & path) . ok ( ) )
449+ . or_else ( || {
450+ get_default_api_key_path ( & network)
451+ . and_then ( |path| std:: fs:: read ( & path) . ok ( ) )
452+ } )
445453 . map ( |bytes| bytes. to_lower_hex_string ( ) )
446454 } )
447455 . unwrap_or_else ( || {
@@ -457,11 +465,15 @@ async fn main() {
457465 std:: process:: exit ( 1 ) ;
458466 } ) ;
459467
460- // Get TLS cert path from argument, then from config file, then try default location
468+ // Get TLS cert path from argument, then from config tls.cert_path, then from storage dir,
469+ // then try default location.
461470 let tls_cert_path = cli. tls_cert . map ( PathBuf :: from) . or_else ( || {
462471 config
463472 . as_ref ( )
464473 . and_then ( |c| c. tls . as_ref ( ) . and_then ( |t| t. cert_path . as_ref ( ) . map ( PathBuf :: from) ) )
474+ . or_else ( || {
475+ storage_dir. map ( cert_path_for_storage_dir) . filter ( |path| path. exists ( ) )
476+ } )
465477 . or_else ( get_default_cert_path)
466478 } )
467479 . unwrap_or_else ( || {
0 commit comments