mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
fix "~/.config" path expansion
This commit is contained in:
@@ -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::<CashierdConfig>::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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Self> {
|
||||
let config: DarkfidConfig = Config::<DarkfidConfig>::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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
14
src/util.rs
14
src/util.rs
@@ -8,6 +8,20 @@ use crate::{
|
||||
Result,
|
||||
};
|
||||
|
||||
pub fn expand_path(path: &str) -> Result<PathBuf> {
|
||||
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<PathBuf> {
|
||||
let mut path = PathBuf::new();
|
||||
let dfi_path = Path::new("darkfi");
|
||||
|
||||
Reference in New Issue
Block a user