mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
configure owner api listen address
This commit is contained in:
@@ -53,6 +53,11 @@ fn comments() -> HashMap<String, String> {
|
||||
retval.insert(
|
||||
"owner_api_listen_port".to_string(),
|
||||
"
|
||||
#owner api address, for example 0.0.0.0:3420 for docker
|
||||
#overrides owner_api_listen_port when set
|
||||
#do not expose the owner api to an untrusted network
|
||||
#owner_api_listen_addr = \"127.0.0.1:3420\"
|
||||
|
||||
#port for wallet owner api
|
||||
"
|
||||
.to_string(),
|
||||
|
||||
+22
-21
@@ -28,9 +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>,
|
||||
/// Address this wallet's owner API will listen on
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub owner_api_listen_addr: 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
|
||||
@@ -66,7 +66,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_addr: None,
|
||||
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()),
|
||||
@@ -92,11 +92,6 @@ 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
|
||||
@@ -107,13 +102,6 @@ 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
|
||||
@@ -122,11 +110,9 @@ impl WalletConfig {
|
||||
|
||||
/// Owner API listen address
|
||||
pub fn owner_api_listen_addr(&self) -> String {
|
||||
format!(
|
||||
"{}:{}",
|
||||
self.owner_api_listen_interface(),
|
||||
self.owner_api_listen_port()
|
||||
)
|
||||
self.owner_api_listen_addr
|
||||
.clone()
|
||||
.unwrap_or_else(|| format!("127.0.0.1:{}", self.owner_api_listen_port()))
|
||||
}
|
||||
|
||||
/// Accept fee base
|
||||
@@ -144,6 +130,21 @@ impl WalletConfig {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::WalletConfig;
|
||||
|
||||
#[test]
|
||||
fn owner_api_address() {
|
||||
let mut config = WalletConfig::default();
|
||||
assert_eq!(config.owner_api_listen_addr(), "127.0.0.1:3420");
|
||||
|
||||
config.owner_api_listen_addr = Some("0.0.0.0:3420".to_string());
|
||||
assert_eq!(config.owner_api_listen_addr(), "0.0.0.0:3420");
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type wrapping config errors.
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
|
||||
@@ -240,7 +240,9 @@ where
|
||||
|
||||
let mut apis = ApiServer::new();
|
||||
warn!("Starting HTTP Owner API server at {}.", addr);
|
||||
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address");
|
||||
let socket_addr: SocketAddr = addr
|
||||
.parse()
|
||||
.map_err(|_| Error::GenericError(format!("Invalid owner API address: {}", addr)))?;
|
||||
let api_thread = apis
|
||||
.start(socket_addr, router, tls_config, api_chan)
|
||||
.map_err(|_| Error::GenericError("API thread failed to start".to_string()))?;
|
||||
|
||||
@@ -410,6 +410,7 @@ pub fn parse_owner_api_args(
|
||||
args: &ArgMatches,
|
||||
) -> Result<(), ParseError> {
|
||||
if let Some(port) = args.value_of("port") {
|
||||
config.owner_api_listen_addr = None;
|
||||
config.owner_api_listen_port = Some(port.parse().unwrap());
|
||||
}
|
||||
if args.is_present("run_foreign") {
|
||||
|
||||
Reference in New Issue
Block a user