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

Make persisted file names configurable #442

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
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
29 changes: 18 additions & 11 deletions zingoconfig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use zcash_primitives::{

pub const DEFAULT_LIGHTWALLETD_SERVER: &str = "https://mainnet.lightwalletd.com:9067";
pub const MAX_REORG: usize = 100;
pub const WALLET_NAME: &str = "zingo-wallet.dat";
pub const LOGFILE_NAME: &str = "zingo-wallet.debug.log";
pub const DEFAULT_WALLET_NAME: &str = "zingo-wallet.dat";
pub const DEFAULT_LOGFILE_NAME: &str = "zingo-wallet.debug.log";
pub const REORG_BUFFER_OFFSET: u32 = 0;

#[cfg(any(target_os = "ios", target_os = "android"))]
Expand Down Expand Up @@ -62,7 +62,12 @@ pub struct ZingoConfig {
pub chain: ChainType,
pub reorg_buffer_offset: u32,
pub monitor_mempool: bool,
pub zingo_wallet_dir: Option<PathBuf>,
/// The directory where the wallet and logfiles will be created. By default, this will be in ~/.zcash on Linux and %APPDATA%\Zcash on Windows.
pub wallet_dir: Option<PathBuf>,
/// The filename of the wallet. This will be created in the `wallet_dir`.
pub wallet_name: PathBuf,
/// The filename of the logfile. This will be created in the `wallet_dir`.
pub logfile_name: PathBuf,
}

impl ZingoConfig {
Expand All @@ -73,7 +78,9 @@ impl ZingoConfig {
chain,
monitor_mempool: false,
reorg_buffer_offset: REORG_BUFFER_OFFSET,
zingo_wallet_dir: dir,
wallet_dir: dir,
wallet_name: DEFAULT_WALLET_NAME.into(),
logfile_name: DEFAULT_LOGFILE_NAME.into(),
}
}

Expand All @@ -92,7 +99,7 @@ impl ZingoConfig {
.into()
}
pub fn set_data_dir(&mut self, dir_str: String) {
self.zingo_wallet_dir = Some(PathBuf::from(dir_str));
self.wallet_dir = Some(PathBuf::from(dir_str));
}

/// Build the Logging config
Expand Down Expand Up @@ -130,15 +137,15 @@ impl ZingoConfig {
pub fn get_zingo_wallet_dir(&self) -> Box<Path> {
#[cfg(any(target_os = "ios", target_os = "android"))]
{
PathBuf::from(&self.zingo_wallet_dir.as_ref().unwrap()).into_boxed_path()
PathBuf::from(&self.wallet_dir.as_ref().unwrap()).into_boxed_path()
}

#[cfg(not(any(target_os = "ios", target_os = "android")))]
{
let mut zcash_data_location;
// If there's some --data-dir path provided, use it
if self.zingo_wallet_dir.is_some() {
zcash_data_location = PathBuf::from(&self.zingo_wallet_dir.as_ref().unwrap());
if self.wallet_dir.is_some() {
zcash_data_location = PathBuf::from(&self.wallet_dir.as_ref().unwrap());
} else {
#[cfg(any(target_os = "macos", target_os = "windows"))]
{
Expand Down Expand Up @@ -181,7 +188,7 @@ impl ZingoConfig {
pub fn get_zcash_params_path(&self) -> io::Result<Box<Path>> {
#[cfg(any(target_os = "ios", target_os = "android"))]
{
Ok(PathBuf::from(&self.zingo_wallet_dir.as_ref().unwrap()).into_boxed_path())
Ok(PathBuf::from(&self.wallet_dir.as_ref().unwrap()).into_boxed_path())
}

//TODO: This fn is not correct for regtest mode
Expand Down Expand Up @@ -221,7 +228,7 @@ impl ZingoConfig {
}
pub fn get_wallet_path(&self) -> Box<Path> {
let mut wallet_location = self.get_zingo_wallet_dir().into_path_buf();
wallet_location.push(WALLET_NAME);
wallet_location.push(&self.wallet_name);

wallet_location.into_boxed_path()
}
Expand Down Expand Up @@ -256,7 +263,7 @@ impl ZingoConfig {

pub fn get_log_path(&self) -> Box<Path> {
let mut log_path = self.get_zingo_wallet_dir().into_path_buf();
log_path.push(LOGFILE_NAME);
log_path.push(&self.logfile_name);
//println!("LogFile:\n{}", log_path.to_str().unwrap());

log_path.into_boxed_path()
Expand Down
6 changes: 4 additions & 2 deletions zingolib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{
path::PathBuf,
sync::{Arc, RwLock},
};
use zingoconfig::{ChainType, ZingoConfig};
use zingoconfig::{ChainType, ZingoConfig, DEFAULT_LOGFILE_NAME, DEFAULT_WALLET_NAME};

pub fn load_clientconfig(
lightwallet_uri: http::Uri,
Expand All @@ -51,7 +51,9 @@ pub fn load_clientconfig(
chain,
monitor_mempool,
reorg_buffer_offset: zingoconfig::REORG_BUFFER_OFFSET,
zingo_wallet_dir: data_dir,
wallet_dir: data_dir,
wallet_name: DEFAULT_WALLET_NAME.into(),
logfile_name: DEFAULT_LOGFILE_NAME.into(),
};

Ok(config)
Expand Down
Loading