diff --git a/src/bin/cashierd.rs b/src/bin/cashierd.rs index aecd1c06e..5c9eafea8 100644 --- a/src/bin/cashierd.rs +++ b/src/bin/cashierd.rs @@ -9,7 +9,7 @@ use drk::{ }, serial::{deserialize, serialize}, service::{bridge, bridge::Bridge}, - util::join_config_path, + util::{expand_path, join_config_path}, wallet::{CashierDb, WalletDb}, Error, Result, }; @@ -70,16 +70,16 @@ impl Cashierd { let config: CashierdConfig = Config::::load(config_path)?; let cashier_wallet = CashierDb::new( - &PathBuf::from(config.cashier_wallet_path.clone()), + expand_path(&config.cashier_wallet_path.clone())?.as_path(), config.cashier_wallet_password.clone(), )?; let client_wallet = WalletDb::new( - &PathBuf::from(config.client_wallet_path.clone()), + expand_path(&config.client_wallet_path.clone())?.as_path(), config.client_wallet_password.clone(), )?; - let rocks = Rocks::new(&PathBuf::from(config.database_path.clone()))?; + let rocks = Rocks::new(expand_path(&config.database_path.clone())?.as_path())?; let client = Client::new( rocks, @@ -88,8 +88,8 @@ impl Cashierd { config.gateway_subscriber_url.parse()?, ), ( - PathBuf::from(config.mint_params.clone()), - PathBuf::from(config.spend_params.clone()), + expand_path(&config.mint_params.clone())?, + expand_path(&config.spend_params.clone())?, ), client_wallet.clone(), )?; @@ -151,11 +151,11 @@ impl Cashierd { let (notify, recv_coin) = async_channel::unbounded::<(jubjub::SubgroupPoint, u64)>(); let cashier_client_subscriber_task = smol::spawn(Client::connect_to_subscriber_from_cashier( - self.client.clone(), - executor.clone(), - self.cashier_wallet.clone(), - notify.clone(), - )); + self.client.clone(), + executor.clone(), + self.cashier_wallet.clone(), + notify.clone(), + )); let cashier_wallet = self.cashier_wallet.clone(); let listen_for_receiving_coins_task = smol::spawn(async move { @@ -173,7 +173,7 @@ impl Cashierd { let cfg = RpcServerConfig { socket_addr: self.config.clone().listen_url, use_tls: self.config.serve_tls, - identity_path: self.config.clone().tls_identity_path, + identity_path: expand_path(&self.config.clone().tls_identity_path)?, identity_pass: self.config.clone().tls_identity_password, }; diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 92e9db8f7..d829cecf9 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -13,7 +13,7 @@ use drk::{ rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig}, }, serial::serialize, - util::join_config_path, + util::{expand_path, join_config_path}, wallet::WalletDb, Result, }; @@ -54,7 +54,7 @@ impl Darkfid { fn new(config_path: PathBuf) -> Result { let config: DarkfidConfig = Config::::load(config_path)?; let wallet = WalletDb::new( - &PathBuf::from(&config.wallet_path), + expand_path(&config.wallet_path)?.as_path(), config.wallet_password.clone(), )?; // TODO: FIXME @@ -303,7 +303,7 @@ async fn main() -> Result<()> { let server_config = RpcServerConfig { socket_addr: darkfid.config.clone().listen_address, use_tls: darkfid.config.serve_tls, - identity_path: darkfid.config.clone().tls_identity_path, + identity_path: expand_path(&darkfid.config.clone().tls_identity_path)?, identity_pass: darkfid.config.clone().tls_identity_password, }; diff --git a/src/rpc/rpcserver.rs b/src/rpc/rpcserver.rs index 85db03a9a..6a8661fe2 100644 --- a/src/rpc/rpcserver.rs +++ b/src/rpc/rpcserver.rs @@ -1,6 +1,7 @@ use std::net::{SocketAddr, TcpListener, TcpStream}; use std::str::FromStr; use std::sync::Arc; +use std::path::PathBuf; use async_native_tls::{Identity, TlsAcceptor}; use async_trait::async_trait; @@ -16,7 +17,7 @@ use crate::Result; pub struct RpcServerConfig { pub socket_addr: String, pub use_tls: bool, - pub identity_path: String, + pub identity_path: PathBuf, pub identity_pass: String, } diff --git a/src/util.rs b/src/util.rs index cfc1a7ae8..f29cb25fc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,6 +8,20 @@ use crate::{ Result, }; +pub fn expand_path(path: &str) -> Result { + let ret: PathBuf; + + if path.starts_with("~") { + let homedir = dirs::home_dir().unwrap(); + let remains = PathBuf::from(path.strip_prefix("~/").unwrap()); + ret = [homedir, remains].iter().collect(); + } else { + ret = PathBuf::from(path); + } + + Ok(ret) +} + pub fn join_config_path(file: &Path) -> Result { let mut path = PathBuf::new(); let dfi_path = Path::new("darkfi");