From a2817751205ab61dccf4a9b6e64761cdec97fa97 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Wed, 29 May 2024 16:19:36 +0100 Subject: [PATCH] Add owner_api_listen_interface as hidden configuration field --- config/src/types.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/config/src/types.rs b/config/src/types.rs index 6a57c5428..f7266f00b 100644 --- a/config/src/types.rs +++ b/config/src/types.rs @@ -28,6 +28,9 @@ pub struct WalletConfig { pub chain_type: Option, /// The port this wallet will run on pub api_listen_port: u16, + /// Listen interface for the owner API, should be hidden from config by default + #[serde(skip_serializing)] + pub owner_api_listen_interface: Option, /// The port this wallet's owner API will run on pub owner_api_listen_port: Option, /// Location of the secret for basic auth on the Owner API @@ -61,6 +64,7 @@ impl Default for WalletConfig { WalletConfig { chain_type: Some(ChainTypes::Mainnet), api_listen_port: 3415, + owner_api_listen_interface: Some(WalletConfig::default_owner_api_listen_interface()), owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()), api_secret_path: Some(".owner_api_secret".to_string()), node_api_secret_path: Some(".foreign_api_secret".to_string()), @@ -82,6 +86,11 @@ impl WalletConfig { format!("127.0.0.1:{}", self.api_listen_port) } + /// Default listener port + pub fn default_owner_api_listen_interface() -> String { + "127.0.0.1".to_string() + } + /// Default listener port pub fn default_owner_api_listen_port() -> u16 { 3420 @@ -92,6 +101,13 @@ impl WalletConfig { 500_000 } + /// Use value from config file, defaulting to sensible value if missing. + pub fn owner_api_listen_interface(&self) -> String { + self.owner_api_listen_interface + .clone() + .unwrap_or_else(|| WalletConfig::default_owner_api_listen_interface()) + } + /// Use value from config file, defaulting to sensible value if missing. pub fn owner_api_listen_port(&self) -> u16 { self.owner_api_listen_port @@ -100,7 +116,11 @@ impl WalletConfig { /// Owner API listen address pub fn owner_api_listen_addr(&self) -> String { - format!("127.0.0.1:{}", self.owner_api_listen_port()) + format!( + "{}:{}", + self.owner_api_listen_interface(), + self.owner_api_listen_port() + ) } /// Accept fee base