Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CONTRACTS] Add owner_api_listen_interface as hidden configuration field #714

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading