pub async fn wallet_recovery(wallet: &mut WalletSqlite, base_node: &Peer) -> Result<(), ExitCodes> {
    let mut recovery_task = WalletRecoveryTask::new(wallet.clone(), base_node.public_key.clone());

    let mut event_stream = recovery_task
        .get_event_receiver()
        .ok_or_else(|| ExitCodes::RecoveryError("Unable to get recovery event stream".to_string()))?
        .fuse();

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

    loop {
        futures::select! {
            event = event_stream.select_next_some() => {
                match event {
                    WalletRecoveryEvent::ConnectedToBaseNode(pk) => {
                        println!("Connected to base node: {}", pk.to_hex());
                    },
                    WalletRecoveryEvent::Progress(current, total) => {
                        let percentage_progress = ((current as f32) * 100f32 / (total as f32)).round() as u32;
                        println!("{}: Recovery process {}% complete.", Local::now(), percentage_progress);
                    },
                    WalletRecoveryEvent::Completed(num_utxos, total_amount) => {
                        println!("Recovered {} outputs with a value of {}", num_utxos, total_amount);
                    },
                }
            },
            recovery_result = recovery_join_handle => {
               return recovery_result.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: &mut WalletSqlite, base_node: &Peer) -> Result<(), ExitCodes> {
    let mut recovery_task = WalletRecoveryTask::new(wallet.clone(), base_node.public_key.clone());
    let mut event_stream = recovery_task
        .get_event_receiver()
        .ok_or_else(|| ExitCodes::RecoveryError("Unable to get recovery event stream".to_string()))?
        .fuse();
    let mut recovery_join_handle = tokio::spawn(recovery_task.run()).fuse();
    loop {
        futures::select! {
            event = event_stream.select_next_some() => {
                match event {
                    WalletRecoveryEvent::ConnectedToBaseNode(pk) => {
                        println!("Connected to base node: {}", pk.to_hex());
                    },
                    WalletRecoveryEvent::Progress(current, total) => {
                        let percentage_progress = ((current as f32) * 100f32 / (total as f32)).round() as u32;
                        println!("{}: Recovery process {}% complete.", Local::now(), percentage_progress);
                    },
                    WalletRecoveryEvent::Completed(num_utxos, total_amount) => {
                        println!("Recovered {} outputs with a value of {}", num_utxos, total_amount);
                    },
                }
            },
            recovery_result = recovery_join_handle => {
               return recovery_result.map_err(|e| ExitCodes::RecoveryError(format!("{}", e)))?.map_err(|e| ExitCodes::RecoveryError(format!("{}", e)));
            }
        }
    }
}
pub async fn wallet_recovery ( wallet : & mut WalletSqlite , base_node : & Peer ) -> Result < ( ) , ExitCodes > { let mut recovery_task = WalletRecoveryTask :: new ( wallet . clone ( ) , base_node . public_key . clone ( ) ) ; let mut event_stream = recovery_task . get_event_receiver ( ) . ok_or_else ( | | ExitCodes :: RecoveryError ( " " . to_string ( ) ) ) ? . fuse ( ) ; let mut recovery_join_handle = tokio :: spawn ( recovery_task . run ( ) ) . fuse ( ) ; loop { futures :: select ! { event event_stream select_next_some ( ) { match event { WalletRecoveryEvent ConnectedToBaseNode ( pk ) { println ( " " pk to_hex ( ) ) } WalletRecoveryEvent Progress ( current total ) { let percentage_progress ( ( current as f32 ) 100f32 ( total as f32 ) ) round ( ) as u32 println ( " " Local now ( ) percentage_progress ) } WalletRecoveryEvent Completed ( num_utxos total_amount ) { println ( " " num_utxos total_amount ) } } } recovery_result recovery_join_handle { return recovery_result 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
&mut WalletSqlite
base_node
&Peer
wallet
&mut WalletSqlite
base_node
&Peer