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

feat: sync cli #6435

Merged
merged 3 commits into from
Jul 31, 2024
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
113 changes: 112 additions & 1 deletion applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ use log::*;
use minotari_app_grpc::tls::certs::{generate_self_signed_certs, print_warning, write_cert_to_disk};
use minotari_wallet::{
connectivity_service::WalletConnectivityInterface,
output_manager_service::{handle::OutputManagerHandle, UtxoSelectionCriteria},
output_manager_service::{
handle::{OutputManagerEvent, OutputManagerHandle},
UtxoSelectionCriteria,
},
transaction_service::{
handle::{TransactionEvent, TransactionServiceHandle},
storage::models::WalletTransaction,
},
utxo_scanner_service::handle::UtxoScannerEvent,
TransactionStage,
WalletConfig,
WalletSqlite,
Expand Down Expand Up @@ -1500,6 +1504,113 @@ pub async fn command_runner(
},
Err(err) => eprintln!("Error generating certificates: {}", err),
},
Sync(args) => {
let mut utxo_scanner = wallet.utxo_scanner_service.clone();
let mut receiver = utxo_scanner.get_event_receiver();

if !online {
match wait_for_comms(&connectivity_requester).await {
Ok(..) => {
online = true;
},
Err(e) => {
eprintln!("Sync error! {}", e);
continue;
},
}
}

loop {
match receiver.recv().await {
Ok(event) => match event {
UtxoScannerEvent::ConnectingToBaseNode(_) => {
println!("Connecting to base node...");
},
UtxoScannerEvent::ConnectedToBaseNode(_, _) => {
println!("Connected to base node");
},
UtxoScannerEvent::ConnectionFailedToBaseNode { .. } => {
println!("Failed to connect to base node");
},
UtxoScannerEvent::ScanningRoundFailed {
num_retries,
retry_limit,
error,
} => {
println!(
"Scanning round failed. Retries: {}/{}. Error: {}",
num_retries, retry_limit, error
);
},
UtxoScannerEvent::Progress {
current_height,
tip_height,
} => {
println!("Progress: {}/{}", current_height, tip_height);
if current_height >= args.sync_to_height && args.sync_to_height > 0 {
break;
}
},
UtxoScannerEvent::Completed {
final_height,
num_recovered,
value_recovered,
time_taken,
} => {
println!(
"Completed! Height: {}, UTXOs recovered: {}, Value recovered: {}, Time taken: {}",
final_height,
num_recovered,
value_recovered,
time_taken.as_secs()
);

break;
},
UtxoScannerEvent::ScanningFailed => {
println!("Scanning failed");
break;
},
},
Err(e) => {
eprintln!("Sync error! {}", e);
break;
},
}
}
println!("Starting validation process");
let mut oms = wallet.output_manager_service.clone();
oms.validate_txos().await?;
let mut event = oms.get_event_stream();
loop {
match event.recv().await {
Ok(event) => match *event {
OutputManagerEvent::TxoValidationSuccess(_) => {
println!("Validation succeeded");
break;
},
OutputManagerEvent::TxoValidationAlreadyBusy(_) => {
println!("Validation already busy");
},
_ => {
println!("Validation failed");
break;
},
},
Err(e) => {
eprintln!("Sync error! {}", e);
break;
},
}
}
println!("balance as of scanning height");
match output_service.clone().get_balance().await {
Ok(balance) => {
println!("{}", balance);
},
Err(e) => eprintln!("GetBalance error! {}", e),
}
},
}
}

Expand Down
7 changes: 7 additions & 0 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub enum CliCommands {
RevalidateWalletDb,
RegisterValidatorNode(RegisterValidatorNodeArgs),
CreateTlsCerts,
Sync(SyncArgs),
}

#[derive(Debug, Args, Clone)]
Expand Down Expand Up @@ -362,3 +363,9 @@ pub struct RegisterValidatorNodeArgs {
#[clap(short, long, default_value = "Registering VN")]
pub message: String,
}

#[derive(Debug, Args, Clone)]
pub struct SyncArgs {
#[clap(short, long, default_value = "0")]
pub sync_to_height: u64,
}
1 change: 1 addition & 0 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ mod test {
CliCommands::RegisterValidatorNode(_) => {},
CliCommands::CreateTlsCerts => {},
CliCommands::PreMineSpendBackupUtxo(_) => {},
CliCommands::Sync(_) => {},
}
}
assert!(
Expand Down
Loading