pub fn from_args() -> Config {
        use internal::ResultExt;

        let (mut config, args) =
            internal::Config::including_optional_config_files(default_config_files())
                .unwrap_or_exit();

        let db_subdir = match config.network {
            Network::Bitcoin => "bitcoin",
            Network::Testnet => "testnet",
            Network::Regtest => "regtest",
            Network::Signet => "signet",
        };

        config.db_dir.push(db_subdir);

        let default_daemon_rpc_port = match config.network {
            Network::Bitcoin => 8332,
            Network::Testnet => 18332,
            Network::Regtest => 18443,
            Network::Signet => 38332,
        };
        let default_daemon_p2p_port = match config.network {
            Network::Bitcoin => 8333,
            Network::Testnet => 18333,
            Network::Regtest => 18444,
            Network::Signet => 38333,
        };
        let default_electrum_port = match config.network {
            Network::Bitcoin => 50001,
            Network::Testnet => 60001,
            Network::Regtest => 60401,
            Network::Signet => 60601,
        };
        let default_monitoring_port = match config.network {
            Network::Bitcoin => 4224,
            Network::Testnet => 14224,
            Network::Regtest => 24224,
            Network::Signet => 34224,
        };

        let daemon_rpc_addr: SocketAddr = config.daemon_rpc_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_daemon_rpc_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        let daemon_p2p_addr: SocketAddr = config.daemon_p2p_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_daemon_p2p_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        let electrum_rpc_addr: SocketAddr = config.electrum_rpc_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_electrum_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        #[cfg(not(feature = "metrics"))]
        {
            if config.monitoring_addr.is_some() {
                eprintln!("Error: enable \"metrics\" feature to specify monitoring_addr");
                std::process::exit(1);
            }
        }
        let monitoring_addr: SocketAddr = config.monitoring_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_monitoring_port).into(),
            ResolvAddr::resolve_or_exit,
        );

        match config.network {
            Network::Bitcoin => (),
            Network::Testnet => config.daemon_dir.push("testnet3"),
            Network::Regtest => config.daemon_dir.push("regtest"),
            Network::Signet => config.daemon_dir.push("signet"),
        }

        let daemon_dir = &config.daemon_dir;
        let daemon_auth = SensitiveAuth(match (config.auth, config.cookie_file) {
            (None, None) => Auth::CookieFile(daemon_dir.join(".cookie")),
            (None, Some(cookie_file)) => Auth::CookieFile(cookie_file),
            (Some(auth), None) => {
                let parts: Vec<&str> = auth.splitn(2, ':').collect();
                if parts.len() != 2 {
                    eprintln!("Error: auth cookie doesn't contain colon");
                    std::process::exit(1);
                }
                Auth::UserPass(parts[0].to_owned(), parts[1].to_owned())
            }
            (Some(_), Some(_)) => {
                eprintln!("Error: ambigous configuration - auth and cookie_file can't be specified at the same time");
                std::process::exit(1);
            }
        });

        let level = match config.verbose {
            0 => log::LevelFilter::Error,
            1 => log::LevelFilter::Warn,
            2 => log::LevelFilter::Info,
            _ => log::LevelFilter::Debug,
        };

        let index_lookup_limit = match config.index_lookup_limit {
            0 => None,
            _ => Some(config.index_lookup_limit),
        };

        if config.jsonrpc_timeout_secs <= config.wait_duration_secs {
            eprintln!(
                "Error: jsonrpc_timeout_secs ({}) must be higher than wait_duration_secs ({})",
                config.jsonrpc_timeout_secs, config.wait_duration_secs
            );
            std::process::exit(1);
        }

        let config = Config {
            network: config.network,
            db_path: config.db_dir,
            daemon_dir: config.daemon_dir,
            daemon_auth,
            daemon_rpc_addr,
            daemon_p2p_addr,
            electrum_rpc_addr,
            monitoring_addr,
            wait_duration: Duration::from_secs(config.wait_duration_secs),
            jsonrpc_timeout: Duration::from_secs(config.jsonrpc_timeout_secs),
            index_batch_size: config.index_batch_size,
            index_lookup_limit,
            reindex_last_blocks: config.reindex_last_blocks,
            auto_reindex: config.auto_reindex,
            ignore_mempool: config.ignore_mempool,
            sync_once: config.sync_once,
            disable_electrum_rpc: config.disable_electrum_rpc,
            server_banner: config.server_banner,
            args: args.map(|a| a.into_string().unwrap()).collect(),
        };
        eprintln!(
            "Starting electrs {} on {} {} with {:?}",
            ELECTRS_VERSION, ARCH, OS, config
        );
        env_logger::Builder::from_default_env()
            .default_format()
            .format_timestamp_millis()
            .filter_level(level)
            .init();
        config
    }
/// Parses args, env vars, config files and post-processes them
Parses args, env vars, config files and post-processes them
Parses args env vars config files and post - processes them
pub fn from_args() -> Config {
        use internal::ResultExt;
        let (mut config, args) =
            internal::Config::including_optional_config_files(default_config_files())
                .unwrap_or_exit();
        let db_subdir = match config.network {
            Network::Bitcoin => "bitcoin",
            Network::Testnet => "testnet",
            Network::Regtest => "regtest",
            Network::Signet => "signet",
        };
        config.db_dir.push(db_subdir);
        let default_daemon_rpc_port = match config.network {
            Network::Bitcoin => 8332,
            Network::Testnet => 18332,
            Network::Regtest => 18443,
            Network::Signet => 38332,
        };
        let default_daemon_p2p_port = match config.network {
            Network::Bitcoin => 8333,
            Network::Testnet => 18333,
            Network::Regtest => 18444,
            Network::Signet => 38333,
        };
        let default_electrum_port = match config.network {
            Network::Bitcoin => 50001,
            Network::Testnet => 60001,
            Network::Regtest => 60401,
            Network::Signet => 60601,
        };
        let default_monitoring_port = match config.network {
            Network::Bitcoin => 4224,
            Network::Testnet => 14224,
            Network::Regtest => 24224,
            Network::Signet => 34224,
        };
        let daemon_rpc_addr: SocketAddr = config.daemon_rpc_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_daemon_rpc_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        let daemon_p2p_addr: SocketAddr = config.daemon_p2p_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_daemon_p2p_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        let electrum_rpc_addr: SocketAddr = config.electrum_rpc_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_electrum_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        #[cfg(not(feature = "metrics"))]
        {
            if config.monitoring_addr.is_some() {
                eprintln!("Error: enable \"metrics\" feature to specify monitoring_addr");
                std::process::exit(1);
            }
        }
        let monitoring_addr: SocketAddr = config.monitoring_addr.map_or(
            (DEFAULT_SERVER_ADDRESS, default_monitoring_port).into(),
            ResolvAddr::resolve_or_exit,
        );
        match config.network {
            Network::Bitcoin => (),
            Network::Testnet => config.daemon_dir.push("testnet3"),
            Network::Regtest => config.daemon_dir.push("regtest"),
            Network::Signet => config.daemon_dir.push("signet"),
        }
        let daemon_dir = &config.daemon_dir;
        let daemon_auth = SensitiveAuth(match (config.auth, config.cookie_file) {
            (None, None) => Auth::CookieFile(daemon_dir.join(".cookie")),
            (None, Some(cookie_file)) => Auth::CookieFile(cookie_file),
            (Some(auth), None) => {
                let parts: Vec<&str> = auth.splitn(2, ':').collect();
                if parts.len() != 2 {
                    eprintln!("Error: auth cookie doesn't contain colon");
                    std::process::exit(1);
                }
                Auth::UserPass(parts[0].to_owned(), parts[1].to_owned())
            }
            (Some(_), Some(_)) => {
                eprintln!("Error: ambigous configuration - auth and cookie_file can't be specified at the same time");
                std::process::exit(1);
            }
        });
        let level = match config.verbose {
            0 => log::LevelFilter::Error,
            1 => log::LevelFilter::Warn,
            2 => log::LevelFilter::Info,
            _ => log::LevelFilter::Debug,
        };
        let index_lookup_limit = match config.index_lookup_limit {
            0 => None,
            _ => Some(config.index_lookup_limit),
        };
        if config.jsonrpc_timeout_secs <= config.wait_duration_secs {
            eprintln!(
                "Error: jsonrpc_timeout_secs ({}) must be higher than wait_duration_secs ({})",
                config.jsonrpc_timeout_secs, config.wait_duration_secs
            );
            std::process::exit(1);
        }
        let config = Config {
            network: config.network,
            db_path: config.db_dir,
            daemon_dir: config.daemon_dir,
            daemon_auth,
            daemon_rpc_addr,
            daemon_p2p_addr,
            electrum_rpc_addr,
            monitoring_addr,
            wait_duration: Duration::from_secs(config.wait_duration_secs),
            jsonrpc_timeout: Duration::from_secs(config.jsonrpc_timeout_secs),
            index_batch_size: config.index_batch_size,
            index_lookup_limit,
            reindex_last_blocks: config.reindex_last_blocks,
            auto_reindex: config.auto_reindex,
            ignore_mempool: config.ignore_mempool,
            sync_once: config.sync_once,
            disable_electrum_rpc: config.disable_electrum_rpc,
            server_banner: config.server_banner,
            args: args.map(|a| a.into_string().unwrap()).collect(),
        };
        eprintln!(
            "Starting electrs {} on {} {} with {:?}",
            ELECTRS_VERSION, ARCH, OS, config
        );
        env_logger::Builder::from_default_env()
            .default_format()
            .format_timestamp_millis()
            .filter_level(level)
            .init();
        config
    }
pub fn from_args ( ) -> Config { use internal :: ResultExt ; let ( mut config , args ) = internal :: Config :: including_optional_config_files ( default_config_files ( ) ) . unwrap_or_exit ( ) ; let db_subdir = match config . network { Network :: Bitcoin => " " , Network :: Testnet => " " , Network :: Regtest => " " , Network :: Signet => " " , } ; config . db_dir . push ( db_subdir ) ; let default_daemon_rpc_port = match config . network { Network :: Bitcoin => 8332 , Network :: Testnet => 18332 , Network :: Regtest => 18443 , Network :: Signet => 38332 , } ; let default_daemon_p2p_port = match config . network { Network :: Bitcoin => 8333 , Network :: Testnet => 18333 , Network :: Regtest => 18444 , Network :: Signet => 38333 , } ; let default_electrum_port = match config . network { Network :: Bitcoin => 50001 , Network :: Testnet => 60001 , Network :: Regtest => 60401 , Network :: Signet => 60601 , } ; let default_monitoring_port = match config . network { Network :: Bitcoin => 4224 , Network :: Testnet => 14224 , Network :: Regtest => 24224 , Network :: Signet => 34224 , } ; let daemon_rpc_addr : SocketAddr = config . daemon_rpc_addr . map_or ( ( DEFAULT_SERVER_ADDRESS , default_daemon_rpc_port ) . into ( ) , ResolvAddr :: resolve_or_exit , ) ; let daemon_p2p_addr : SocketAddr = config . daemon_p2p_addr . map_or ( ( DEFAULT_SERVER_ADDRESS , default_daemon_p2p_port ) . into ( ) , ResolvAddr :: resolve_or_exit , ) ; let electrum_rpc_addr : SocketAddr = config . electrum_rpc_addr . map_or ( ( DEFAULT_SERVER_ADDRESS , default_electrum_port ) . into ( ) , ResolvAddr :: resolve_or_exit , ) ; # [ cfg ( not ( feature " " ) ) ] { if config . monitoring_addr . is_some ( ) { eprintln ! ( " \" \" " ) ; std :: process :: exit ( 1 ) ; } } let monitoring_addr : SocketAddr = config . monitoring_addr . map_or ( ( DEFAULT_SERVER_ADDRESS , default_monitoring_port ) . into ( ) , ResolvAddr :: resolve_or_exit , ) ; match config . network { Network :: Bitcoin => ( ) , Network :: Testnet => config . daemon_dir . push ( " " ) , Network :: Regtest => config . daemon_dir . push ( " " ) , Network :: Signet => config . daemon_dir . push ( " " ) , } let daemon_dir = & config . daemon_dir ; let daemon_auth = SensitiveAuth ( match ( config . auth , config . cookie_file ) { ( None , None ) => Auth :: CookieFile ( daemon_dir . join ( " " ) ) , ( None , Some ( cookie_file ) ) => Auth :: CookieFile ( cookie_file ) , ( Some ( auth ) , None ) => { let parts : Vec < & str > = auth . splitn ( 2 , ':' ) . collect ( ) ; if parts . len ( ) != 2 { eprintln ! ( " " ) ; std :: process :: exit ( 1 ) ; } Auth :: UserPass ( parts [ 0 ] . to_owned ( ) , parts [ 1 ] . to_owned ( ) ) } ( Some ( _ ) , Some ( _ ) ) => { eprintln ! ( " " ) ; std :: process :: exit ( 1 ) ; } } ) ; let level = match config . verbose { 0 => log :: LevelFilter :: Error , 1 => log :: LevelFilter :: Warn , 2 => log :: LevelFilter :: Info , _ => log :: LevelFilter :: Debug , } ; let index_lookup_limit = match config . index_lookup_limit { 0 => None , _ => Some ( config . index_lookup_limit ) , } ; if config . jsonrpc_timeout_secs <= config . wait_duration_secs { eprintln ! ( " " config jsonrpc_timeout_secs config wait_duration_secs ) ; std :: process :: exit ( 1 ) ; } let config = Config { network : config . network , db_path : config . db_dir , daemon_dir : config . daemon_dir , daemon_auth , daemon_rpc_addr , daemon_p2p_addr , electrum_rpc_addr , monitoring_addr , wait_duration : Duration :: from_secs ( config . wait_duration_secs ) , jsonrpc_timeout : Duration :: from_secs ( config . jsonrpc_timeout_secs ) , index_batch_size : config . index_batch_size , index_lookup_limit , reindex_last_blocks : config . reindex_last_blocks , auto_reindex : config . auto_reindex , ignore_mempool : config . ignore_mempool , sync_once : config . sync_once , disable_electrum_rpc : config . disable_electrum_rpc , server_banner : config . server_banner , args : args . map ( | a | a . into_string ( ) . unwrap ( ) ) . collect ( ) , } ; eprintln ! ( " " ELECTRS_VERSION ARCH OS config ) ; env_logger :: Builder :: from_default_env ( ) . default_format ( ) . format_timestamp_millis ( ) . filter_level ( level ) . init ( ) ; config }
Parses args, env vars, config files and post-processes them
Parses args env vars config files and post - processes them