refactoring in configuration

This commit is contained in:
Nikolay Volf 2016-05-13 13:53:33 +03:00
parent d5d5b0918c
commit 9150538ac4
2 changed files with 16 additions and 14 deletions

View File

@ -61,8 +61,7 @@ impl Configuration {
} }
pub fn path(&self) -> String { pub fn path(&self) -> String {
let d = self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_path); Configuration::replace_home(&self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_path))
d.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
} }
pub fn author(&self) -> Address { pub fn author(&self) -> Address {
@ -114,7 +113,7 @@ impl Configuration {
} }
pub fn keys_path(&self) -> String { pub fn keys_path(&self) -> String {
self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()) Configuration::replace_home(&self.args.flag_keys_path)
} }
pub fn spec(&self) -> Spec { pub fn spec(&self) -> Spec {
@ -267,19 +266,23 @@ impl Configuration {
self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone()) self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone())
} }
fn geth_ipc_path() -> &'static str { fn geth_ipc_path() -> String {
if cfg!(target_os = "macos") { path::ethereum::with_default("geth.ipc").to_str().unwrap().to_owned()
"$HOME/Library/Ethereum/geth.ipc"
} else {
"$HOME/.ethereum/geth.ipc"
} }
fn replace_home(arg: &str) -> String {
arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
}
fn ipc_path(&self) -> String {
if self.args.flag_geth { Self::geth_ipc_path() }
else { Configuration::replace_home(&self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone())) }
} }
pub fn ipc_settings(&self) -> IpcConfiguration { pub fn ipc_settings(&self) -> IpcConfiguration {
IpcConfiguration { IpcConfiguration {
enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off), enabled: !(self.args.flag_ipcdisable || self.args.flag_ipc_off),
socket_addr: if self.args.flag_geth { Self::geth_ipc_path().to_owned() } else { self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone()) } socket_addr: self.ipc_path(),
.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()),
apis: self.args.flag_ipcapi.clone().unwrap_or(self.args.flag_ipc_apis.clone()), apis: self.args.flag_ipcapi.clone().unwrap_or(self.args.flag_ipc_apis.clone()),
} }
} }

View File

@ -40,7 +40,7 @@ pub mod ethereum {
} }
#[cfg(not(any(target_os = "macos", windows)))] #[cfg(not(any(target_os = "macos", windows)))]
/// Default path for ethereum installation on posix system which and not Mac OS /// Default path for ethereum installation on posix system which is not Mac OS
pub fn default() -> PathBuf { pub fn default() -> PathBuf {
let mut home = ::std::env::home_dir().expect("Failed to get home dir"); let mut home = ::std::env::home_dir().expect("Failed to get home dir");
home.push(".ethereum"); home.push(".ethereum");
@ -54,4 +54,3 @@ pub mod ethereum {
pth pth
} }
} }