configs: avoid SocketAddr parse unwrap

This commit is contained in:
andrussal 2025-12-18 21:59:40 +01:00
parent 4f202295ba
commit 9b2cfeadfe

View File

@ -3,6 +3,8 @@ use std::net::SocketAddr;
use nomos_utils::net::get_available_tcp_port;
use thiserror::Error;
const LOCALHOST: [u8; 4] = [127, 0, 0, 1];
#[derive(Clone)]
pub struct GeneralApiConfig {
pub address: SocketAddr,
@ -23,8 +25,8 @@ pub fn create_api_configs(ids: &[[u8; 32]]) -> Result<Vec<GeneralApiConfig>, Api
let testing_port =
get_available_tcp_port().ok_or(ApiConfigError::PortAllocationFailed)?;
Ok(GeneralApiConfig {
address: format!("127.0.0.1:{address_port}").parse().unwrap(),
testing_http_address: format!("127.0.0.1:{testing_port}").parse().unwrap(),
address: SocketAddr::from((LOCALHOST, address_port)),
testing_http_address: SocketAddr::from((LOCALHOST, testing_port)),
})
})
.collect()