From 8f4589615eba76cfecb8261d287ce6fa2bb4c5c9 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Sun, 23 Jul 2023 19:36:12 +0300 Subject: [PATCH] config: add node api address function --- src/gui/views/network/setup/node.rs | 8 ++++---- src/node/config.rs | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gui/views/network/setup/node.rs b/src/gui/views/network/setup/node.rs index 55f1d0a..fa92c77 100644 --- a/src/gui/views/network/setup/node.rs +++ b/src/gui/views/network/setup/node.rs @@ -46,7 +46,7 @@ pub struct NodeSetup { impl Default for NodeSetup { fn default() -> Self { - let (api_ip, api_port) = NodeConfig::get_api_address(); + let (api_ip, api_port) = NodeConfig::get_api_ip_port(); let is_api_port_available = NodeConfig::is_api_port_available(&api_ip, &api_port); Self { available_ips: NodeConfig::get_ip_addrs(), @@ -141,7 +141,7 @@ impl NodeSetup { ui.add_space(6.0); // Show API IP addresses to select. - let (api_ip, api_port) = NodeConfig::get_api_address(); + let (api_ip, api_port) = NodeConfig::get_api_ip_port(); NetworkSettings::ip_addrs_ui(ui, &api_ip, &self.available_ips, |selected_ip| { let api_available = NodeConfig::is_api_port_available(selected_ip, &api_port); self.is_api_port_available = api_available; @@ -214,7 +214,7 @@ impl NodeSetup { ); ui.add_space(6.0); - let (_, port) = NodeConfig::get_api_address(); + let (_, port) = NodeConfig::get_api_ip_port(); View::button(ui, format!("{} {}", PLUG, port.clone()), Colors::BUTTON, || { // Setup values for modal. self.api_port_edit = port; @@ -279,7 +279,7 @@ impl NodeSetup { // Save button callback. let on_save = || { // Check if port is available. - let (api_ip, _) = NodeConfig::get_api_address(); + let (api_ip, _) = NodeConfig::get_api_ip_port(); let available = NodeConfig::is_api_port_available(&api_ip, &self.api_port_edit); self.api_port_available_edit = available; diff --git a/src/node/config.rs b/src/node/config.rs index e3d9dcc..c2ea0c2 100644 --- a/src/node/config.rs +++ b/src/node/config.rs @@ -346,7 +346,7 @@ impl NodeConfig { fn is_not_running_stratum_port_available(ip: &String, port: &String) -> bool { if Self::is_host_port_available(&ip, &port) { if &Self::get_p2p_port() != port { - let (api_ip, api_port) = Self::get_api_address(); + let (api_ip, api_port) = Self::get_api_ip_port(); return if &api_ip == ip { &api_port != port } else { @@ -438,15 +438,16 @@ impl NodeConfig { w_node_config.save(); } - /// Get API server IP address and port. - pub fn get_api_address() -> (String, String) { + /// Get API server address. + pub fn get_api_address() -> String { let r_config = Settings::node_config_to_read(); - let saved_api_addr = r_config - .node - .server - .api_http_addr - .as_str(); - let (addr, port) = saved_api_addr.split_once(":").unwrap(); + r_config.node.server.api_http_addr.clone() + } + + /// Get API server IP and port. + pub fn get_api_ip_port() -> (String, String) { + let saved_addr = Self::get_api_address().as_str(); + let (addr, port) = saved_addr.split_once(":").unwrap(); (addr.into(), port.into()) } @@ -628,7 +629,7 @@ impl NodeConfig { if port.parse::().is_err() { return false; } - let (_, api_port) = Self::get_api_address(); + let (_, api_port) = Self::get_api_ip_port(); if Node::is_running() { // Check if P2P server with same port is running. let same_running = if let Some(running_port) = Node::get_p2p_port() {