pub async fn wallet_recovery(wallet: &WalletSqlite, base_node_config: &PeerConfig) -> Result<(), ExitCodes> {
    println!("\nPress Ctrl-C to stop the recovery process\n");
    // We dont care about the shutdown signal here, so we just create one
    let shutdown = Shutdown::new();
    let shutdown_signal = shutdown.to_signal();

    let peer_public_keys = base_node_config
        .get_all_peers()
        .iter()
        .map(|peer| peer.public_key.clone())
        .collect();

    let mut recovery_task = UtxoScannerService::<WalletSqliteDatabase>::builder()
        .with_peers(peer_public_keys)
        .with_retry_limit(10)
        .build_with_wallet(wallet, shutdown_signal);

    let mut event_stream = recovery_task.get_event_receiver().fuse();

    let recovery_join_handle = tokio::spawn(recovery_task.run()).fuse();

    // Read recovery task events. The event stream will end once recovery has completed.
    while let Some(event) = event_stream.next().await {
        match event {
            Ok(UtxoScannerEvent::ConnectingToBaseNode(peer)) => {
                print!("Connecting to base node {}... ", peer);
            },
            Ok(UtxoScannerEvent::ConnectedToBaseNode(_, latency)) => {
                println!("OK (latency = {:.2?})", latency);
            },
            Ok(UtxoScannerEvent::Progress {
                current_block: current,
                current_chain_height: total,
            }) => {
                let percentage_progress = ((current as f32) * 100f32 / (total as f32)).round() as u32;
                debug!(
                    target: LOG_TARGET,
                    "{}: Recovery process {}% complete ({} of {} utxos).",
                    Local::now(),
                    percentage_progress,
                    current,
                    total
                );
                println!(
                    "{}: Recovery process {}% complete ({} of {} utxos).",
                    Local::now(),
                    percentage_progress,
                    current,
                    total
                );
            },
            Ok(UtxoScannerEvent::ScanningRoundFailed {
                num_retries,
                retry_limit,
            }) => {
                let s = format!("Failed to sync. Attempt {} of {}", num_retries, retry_limit);
                println!("{}", s);
                warn!(target: LOG_TARGET, "{}", s);
            },
            Ok(UtxoScannerEvent::ConnectionFailedToBaseNode {
                peer,
                num_retries,
                retry_limit,
                error,
            }) => {
                let s = format!(
                    "Base node connection error to {} (retries {} of {}: {})",
                    peer, num_retries, retry_limit, error
                );
                println!("{}", s);
                warn!(target: LOG_TARGET, "{}", s);
            },
            Ok(UtxoScannerEvent::Completed {
                number_scanned: num_scanned,
                number_received: num_utxos,
                value_received: total_amount,
                time_taken: elapsed,
            }) => {
                let rate = (num_scanned as f32) * 1000f32 / (elapsed.as_millis() as f32);
                let stats = format!(
                    "Recovery complete! Scanned = {} in {:.2?} ({:.2?} utxos/s), Recovered {} worth {}",
                    num_scanned, elapsed, rate, num_utxos, total_amount
                );
                info!(target: LOG_TARGET, "{}", stats);
                println!("{}", stats);
            },
            Err(e) => {
                // Can occur if we read events too slowly (lagging/slow subscriber)
                debug!(target: LOG_TARGET, "Error receiving Wallet recovery events: {}", e);
                continue;
            },
            Ok(UtxoScannerEvent::ScanningFailed) => {
                error!(target: LOG_TARGET, "Wallet Recovery process failed and is exiting");
            },
        }
    }

    recovery_join_handle
        .await
        .map_err(|e| ExitCodes::RecoveryError(format!("{}", e)))?
        .map_err(|e| ExitCodes::RecoveryError(format!("{}", e)))
}
/// Recovers wallet funds by connecting to a given base node peer, downloading the transaction outputs stored in the
/// blockchain, and attempting to rewind them. Any outputs that are successfully rewound are then imported into the
/// wallet.
Recovers wallet funds by connecting to a given base node peer, downloading the transaction outputs stored in the
blockchain, and attempting to rewind them. Any outputs that are successfully rewound are then imported into the
wallet.
Recovers wallet funds by connecting to a given base node peer downloading the transaction outputs stored in the blockchain and attempting to rewind them . Any outputs that are successfully rewound are then imported into the wallet .
pub async fn wallet_recovery(wallet: &WalletSqlite, base_node_config: &PeerConfig) -> Result<(), ExitCodes> {
    println!("\nPress Ctrl-C to stop the recovery process\n");
    // We dont care about the shutdown signal here, so we just create one
    let shutdown = Shutdown::new();
    let shutdown_signal = shutdown.to_signal();
    let peer_public_keys = base_node_config
        .get_all_peers()
        .iter()
        .map(|peer| peer.public_key.clone())
        .collect();
    let mut recovery_task = UtxoScannerService::<WalletSqliteDatabase>::builder()
        .with_peers(peer_public_keys)
        .with_retry_limit(10)
        .build_with_wallet(wallet, shutdown_signal);
    let mut event_stream = recovery_task.get_event_receiver().fuse();
    let recovery_join_handle = tokio::spawn(recovery_task.run()).fuse();
    // Read recovery task events. The event stream will end once recovery has completed.
    while let Some(event) = event_stream.next().await {
        match event {
            Ok(UtxoScannerEvent::ConnectingToBaseNode(peer)) => {
                print!("Connecting to base node {}... ", peer);
            },
            Ok(UtxoScannerEvent::ConnectedToBaseNode(_, latency)) => {
                println!("OK (latency = {:.2?})", latency);
            },
            Ok(UtxoScannerEvent::Progress {
                current_block: current,
                current_chain_height: total,
            }) => {
                let percentage_progress = ((current as f32) * 100f32 / (total as f32)).round() as u32;
                debug!(
                    target: LOG_TARGET,
                    "{}: Recovery process {}% complete ({} of {} utxos).",
                    Local::now(),
                    percentage_progress,
                    current,
                    total
                );
                println!(
                    "{}: Recovery process {}% complete ({} of {} utxos).",
                    Local::now(),
                    percentage_progress,
                    current,
                    total
                );
            },
            Ok(UtxoScannerEvent::ScanningRoundFailed {
                num_retries,
                retry_limit,
            }) => {
                let s = format!("Failed to sync. Attempt {} of {}", num_retries, retry_limit);
                println!("{}", s);
                warn!(target: LOG_TARGET, "{}", s);
            },
            Ok(UtxoScannerEvent::ConnectionFailedToBaseNode {
                peer,
                num_retries,
                retry_limit,
                error,
            }) => {
                let s = format!(
                    "Base node connection error to {} (retries {} of {}: {})",
                    peer, num_retries, retry_limit, error
                );
                println!("{}", s);
                warn!(target: LOG_TARGET, "{}", s);
            },
            Ok(UtxoScannerEvent::Completed {
                number_scanned: num_scanned,
                number_received: num_utxos,
                value_received: total_amount,
                time_taken: elapsed,
            }) => {
                let rate = (num_scanned as f32) * 1000f32 / (elapsed.as_millis() as f32);
                let stats = format!(
                    "Recovery complete! Scanned = {} in {:.2?} ({:.2?} utxos/s), Recovered {} worth {}",
                    num_scanned, elapsed, rate, num_utxos, total_amount
                );
                info!(target: LOG_TARGET, "{}", stats);
                println!("{}", stats);
            },
            Err(e) => {
                // Can occur if we read events too slowly (lagging/slow subscriber)
                debug!(target: LOG_TARGET, "Error receiving Wallet recovery events: {}", e);
                continue;
            },
            Ok(UtxoScannerEvent::ScanningFailed) => {
                error!(target: LOG_TARGET, "Wallet Recovery process failed and is exiting");
            },
        }
    }
    recovery_join_handle
        .await
        .map_err(|e| ExitCodes::RecoveryError(format!("{}", e)))?
        .map_err(|e| ExitCodes::RecoveryError(format!("{}", e)))
}
pub async fn wallet_recovery ( wallet : & WalletSqlite , base_node_config : & PeerConfig ) -> Result < ( ) , ExitCodes > { println ! ( " \n \n " ) ; // We dont care about the shutdown signal here, so we just create one let shutdown = Shutdown :: new ( ) ; let shutdown_signal = shutdown . to_signal ( ) ; let peer_public_keys = base_node_config . get_all_peers ( ) . iter ( ) . map ( | peer | peer . public_key . clone ( ) ) . collect ( ) ; let mut recovery_task = UtxoScannerService :: < WalletSqliteDatabase > :: builder ( ) . with_peers ( peer_public_keys ) . with_retry_limit ( 10 ) . build_with_wallet ( wallet , shutdown_signal ) ; let mut event_stream = recovery_task . get_event_receiver ( ) . fuse ( ) ; let recovery_join_handle = tokio :: spawn ( recovery_task . run ( ) ) . fuse ( ) ; // Read recovery task events. The event stream will end once recovery has completed. while let Some ( event ) = event_stream . next ( ) . await { match event { Ok ( UtxoScannerEvent :: ConnectingToBaseNode ( peer ) ) => { print ! ( " " peer ) ; } , Ok ( UtxoScannerEvent :: ConnectedToBaseNode ( _ , latency ) ) => { println ! ( " " latency ) ; } , Ok ( UtxoScannerEvent :: Progress { current_block : current , current_chain_height : total , } ) => { let percentage_progress = ( ( current as f32 ) * 100f32 / ( total as f32 ) ) . round ( ) as u32 ; debug ! ( target LOG_TARGET " " Local now ( ) percentage_progress current total ) ; println ! ( " " Local now ( ) percentage_progress current total ) ; } , Ok ( UtxoScannerEvent :: ScanningRoundFailed { num_retries , retry_limit , } ) => { let s = format ! ( " " num_retries retry_limit ) ; println ! ( " " s ) ; warn ! ( target LOG_TARGET " " s ) ; } , Ok ( UtxoScannerEvent :: ConnectionFailedToBaseNode { peer , num_retries , retry_limit , error , } ) => { let s = format ! ( " " peer num_retries retry_limit error ) ; println ! ( " " s ) ; warn ! ( target LOG_TARGET " " s ) ; } , Ok ( UtxoScannerEvent :: Completed { number_scanned : num_scanned , number_received : num_utxos , value_received : total_amount , time_taken : elapsed , } ) => { let rate = ( num_scanned as f32 ) * 1000f32 / ( elapsed . as_millis ( ) as f32 ) ; let stats = format ! ( " " num_scanned elapsed rate num_utxos total_amount ) ; info ! ( target LOG_TARGET " " stats ) ; println ! ( " " stats ) ; } , Err ( e ) => { // Can occur if we read events too slowly (lagging/slow subscriber) debug ! ( target LOG_TARGET " " e ) ; continue ; } , Ok ( UtxoScannerEvent :: ScanningFailed ) => { error ! ( target LOG_TARGET " " ) ; } , } } recovery_join_handle . await . map_err ( | e | ExitCodes :: RecoveryError ( format ! ( " " e ) ) ) ? . map_err ( | e | ExitCodes :: RecoveryError ( format ! ( " " e ) ) ) }
Recovers wallet funds by connecting to a given base node peer, downloading the transaction outputs stored in the
blockchain, and attempting to rewind them.
Recovers wallet funds by connecting to a given base node peer downloading the transaction outputs stored in the blockchain and attempting to rewind them .
wallet
&WalletSqlite
base_node_config
&PeerConfig
wallet
&WalletSqlite
base_node_config
&PeerConfig