Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
[#86] Add support for providing --data-dir to CLI (#87)
Browse files Browse the repository at this point in the history
* [#86] Add support for providing `--data-dir` to CLI

minor comment

Add readme example

* Fix merge conflict and update code to new models
  • Loading branch information
pacu authored Aug 27, 2022
1 parent d6d8d15 commit 7f49488
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Here are some CLI arguments you can pass to `zecwallet-cli`. Please run `zecwall
* Example: `./zecwallet-cli --seed "twenty four words seed phrase"`
* `--recover`: Attempt to recover the seed phrase from a corrupted wallet

* `--data-dir`: uses the specified path as data directory.
* Example: `./zecwallet-cli --server 127.0.0.1:9067 --data-dir /Users/ZecWalletRocks/my-test-wallet` will use the provided directory to store `zecwallet-light-wallet.dat` and logs. If the provided directory does not exist, it will create it.
15 changes: 12 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ macro_rules! configure_clapapp {
.value_name("server")
.help("Lightwalletd server to connect to.")
.takes_value(true)
.default_value(lightclient::lightclient_config::DEFAULT_SERVER))
.default_value(lightclient::lightclient_config::DEFAULT_SERVER)
.takes_value(true))
.arg(Arg::with_name("data-dir")
.long("data-dir")
.value_name("data-dir")
.help("Absolute path to use as data directory")
.takes_value(true))
.arg(Arg::with_name("COMMAND")
.help("Command to execute. If a command is not specified, zecwallet-cli will start in interactive mode.")
.required(false)
Expand Down Expand Up @@ -74,12 +80,13 @@ pub fn startup(
server: http::Uri,
seed: Option<String>,
birthday: u64,
data_dir: Option<String>,
first_sync: bool,
print_updates: bool,
) -> io::Result<(Sender<(String, Vec<String>)>, Receiver<String>)> {
// Try to get the configuration
let (config, latest_block_height) = LightClientConfig::create(MainNetwork, server.clone())?;

let (config, latest_block_height) = LightClientConfig::create(MainNetwork, server.clone(), data_dir)?;
let lightclient = match seed {
Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday, false)?),
None => {
Expand Down Expand Up @@ -242,4 +249,6 @@ pub fn attempt_recover_seed(_password: Option<String>) {
data_dir: None,
params: MainNetwork,
};

}

4 changes: 3 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub fn main() {

let maybe_server = matches.value_of("server").map(|s| s.to_string());

let maybe_data_dir = matches.value_of("data-dir").map(|s| s.to_string());

let seed = matches.value_of("seed").map(|s| s.to_string());
let maybe_birthday = matches.value_of("birthday");

Expand Down Expand Up @@ -60,7 +62,7 @@ pub fn main() {

let nosync = matches.is_present("nosync");

let startup_chan = startup(server, seed, birthday, !nosync, command.is_none());
let startup_chan = startup(server, seed, birthday, maybe_data_dir ,!nosync, command.is_none());
let (command_tx, resp_rx) = match startup_chan {
Ok(c) => c,
Err(e) => {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/lightclient/lightclient_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<P: consensus::Parameters> LightClientConfig<P> {
}
}

pub fn create(params: P, server: http::Uri) -> io::Result<(LightClientConfig<P>, u64)> {
pub fn create(params: P, server: http::Uri, data_dir: Option<String>) -> io::Result<(LightClientConfig<P>, u64)> {
use std::net::ToSocketAddrs;

let s = server.clone();
Expand All @@ -131,16 +131,19 @@ impl<P: consensus::Parameters> LightClientConfig<P> {
Ok::<_, std::io::Error>((info.chain_name, info.sapling_activation_height, info.block_height))
})
{

// Create a Light Client Config
let config = LightClientConfig {
server: s,
chain_name,
monitor_mempool: false,
sapling_activation_height,
anchor_offset: DEFAULT_ANCHOR_OFFSET,
data_dir: None,
data_dir: data_dir,
params,
};


Ok((config, block_height))
} else {
return Err(io::Error::new(
Expand Down Expand Up @@ -194,6 +197,7 @@ impl<P: consensus::Parameters> LightClientConfig<P> {
PathBuf::from(&self.data_dir.as_ref().unwrap()).into_boxed_path()
} else {
let mut zcash_data_location;
// If there's some --data-dir path provided, use it
if self.data_dir.is_some() {
zcash_data_location = PathBuf::from(&self.data_dir.as_ref().unwrap());
} else {
Expand Down

0 comments on commit 7f49488

Please sign in to comment.