From 461c1b06e0f6733bdd6e20b7fff093423499fda6 Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Wed, 11 Feb 2026 03:35:39 +0000 Subject: [PATCH] rework waitsync flag to use the lightclient await_sync method --- README.md | 2 +- zingo-cli/src/lib.rs | 64 +++++++++++++------------------------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 25706d0d5..5e0578610 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/zingo-cli/src/lib.rs b/zingo-cli/src/lib.rs index 21da59c3c..783b2c0a8 100644 --- a/zingo-cli/src/lib.rs +++ b/zingo-cli/src/lib.rs @@ -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}"); @@ -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); @@ -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(),