Skip to content

Commit

Permalink
Add owner_api_listen_interface as hidden configuration field (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume authored May 30, 2024
1 parent c06c91d commit 93464a8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct WalletConfig {
pub chain_type: Option<ChainTypes>,
/// 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<String>,
/// The port this wallet's owner API will run on
pub owner_api_listen_port: Option<u16>,
/// Location of the secret for basic auth on the Owner API
Expand Down Expand Up @@ -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()),
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 93464a8

Please sign in to comment.