Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Here are some CLI arguments you can pass to `zingo-cli`. Please run `zingo-cli -

* `--data-dir`: uses the specified path as data directory. This is required when not using the `--regtest` option.
* Example: `./zingo-cli --data-dir /path/to/data_directory/` will use the provided directory to store `zingo-wallet.dat` and logs. If the provided directory does not exist, it will create it.
* `--waitsync`: Wait for sync before running a command in non-interactive mode
* `--waitsync`: Wait for sync before running a command in non-interactive mode or entering the command prompt in interactive mode.
* Example: `./zingo-cli --data-dir /path/to/data_directory/ --waitsync balance`
* `--server`: Connect to a custom zcash lightwalletd server.
* Example: `./zingo-cli --data-dir /path/to/data_directory/ --server 127.0.0.1:9067`
Expand Down
64 changes: 18 additions & 46 deletions zingo-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,6 @@ pub fn startup(
);
}

if filled_template.tor_enabled {
info!("Creating tor client");
lightclient = RT.block_on(async move {
if let Err(e) = lightclient.create_tor_client(None).await {
eprintln!("error: failed to create tor client. price updates disabled. {e}");
}
lightclient
});
}

// At startup, run a sync.
if filled_template.sync {
let update = commands::do_user_command("sync", &["run"], &mut lightclient);
println!("{update}");
Expand All @@ -488,6 +477,24 @@ pub fn startup(
let update = commands::do_user_command("save", &["run"], &mut lightclient);
println!("{update}");

lightclient = RT.block_on(async move {
if filled_template.tor_enabled {
info!("Creating tor client");
if let Err(e) = lightclient.create_tor_client(None).await {
eprintln!("error: failed to create tor client. price updates disabled. {e}");
}
}

if filled_template.sync
&& filled_template.waitsync
&& let Err(e) = lightclient.await_sync().await
{
eprintln!("error: {e}");
}

lightclient
});

// Start the command loop
let (command_transmitter, resp_receiver) = command_loop(lightclient);

Expand Down Expand Up @@ -516,41 +523,6 @@ fn dispatch_command_or_start_interactive(cli_config: &ConfigTemplate) {
if cli_config.command.is_none() {
start_interactive(command_transmitter, resp_receiver);
} else {
// Optionally wait for background sync to finish before executing command
if cli_config.sync && cli_config.waitsync {
use std::{thread, time::Duration};
loop {
// Poll sync task status
command_transmitter
.send(("sync".to_string(), vec!["poll".to_string()]))
.unwrap();
match resp_receiver.recv() {
Ok(resp) => {
if resp.starts_with("Error:") {
eprintln!(
"Sync error while waiting: {resp}\nProceeding to execute the command."
);
break;
} else if resp.starts_with("Sync completed succesfully:") {
// Sync finished; proceed
break;
} else if resp == "Sync task has not been launched." {
// Try to launch sync and continue waiting
command_transmitter
.send(("sync".to_string(), vec!["run".to_string()]))
.unwrap();
let _ = resp_receiver.recv();
thread::sleep(Duration::from_millis(500));
} else {
// Not ready yet
thread::sleep(Duration::from_millis(500));
}
}
Err(_) => break,
}
}
}

command_transmitter
.send((
cli_config.command.clone().unwrap(),
Expand Down