fn process_toggle_mining(&mut self) {
        // 'enable_miner' should not be changed directly; this is done indirectly via miner instructions,
        // while 'mining_status' will reflect if mining is happening or not
        if self.wallet_output_service.is_some() {
            let enable_miner = self.enable_miner.clone();
            let mining_status = self.mining_status.clone();
            let miner_instructions = self.miner_instructions.clone();
            self.executor.spawn(async move {
                let new_state = !enable_miner.load(Ordering::SeqCst);
                // The event channel can interrupt the mining thread timeously to stop or start mining
                let _ = match new_state {
                    true => {
                        println!("Mining requested to be turned ON");
                        miner_instructions.send(MinerInstruction::StartMining).map_err(|e| {
                            error!(
                                target: LOG_TARGET,
                                "Could not send 'StartMining' instruction to miner. {:?}.", e
                            );
                            e
                        })
                    },
                    false => {
                        println!("Mining requested to be turned OFF");
                        miner_instructions.send(MinerInstruction::PauseMining).map_err(|e| {
                            error!(
                                target: LOG_TARGET,
                                "Could not send 'PauseMining' instruction to miner. {:?}.", e
                            );
                            e
                        })
                    },
                };
                debug!(
                    target: LOG_TARGET,
                    "Mining state requested to be switched to {}", new_state
                );

                // Verify the mining status
                let mut attempts = 0;
                const DELAY: u64 = 2500;
                const WAIT_CYCLES: usize = 50;
                loop {
                    tokio::time::delay_for(Duration::from_millis(DELAY)).await;
                    if new_state == mining_status.load(Ordering::SeqCst) {
                        match new_state {
                            true => println!("Mining is ON"),
                            false => println!("Mining is OFF"),
                        }
                        break;
                    }
                    attempts += 1;
                    if attempts > WAIT_CYCLES {
                        match new_state {
                            true => println!(
                                "Mining could not be turned ON in {:.1} s (mining enabled is set to {})",
                                DELAY as f32 * attempts as f32 / 1000.0,
                                enable_miner.load(Ordering::SeqCst)
                            ),
                            false => println!(
                                "Mining could not to be turned OFF in {:.1} s (mining enabled is set to {})",
                                DELAY as f32 * attempts as f32 / 1000.0,
                                enable_miner.load(Ordering::SeqCst)
                            ),
                        }
                        break;
                    }
                }
            });
        } else {
            println!("Cannot complete command, Wallet is disabled so Mining is also disabled");
        }
    }
/// Function to process the toggle-mining command
Function to process the toggle-mining command
Function to process the toggle - mining command
fn process_toggle_mining(&mut self) {
        // 'enable_miner' should not be changed directly; this is done indirectly via miner instructions,
        // while 'mining_status' will reflect if mining is happening or not
        if self.wallet_output_service.is_some() {
            let enable_miner = self.enable_miner.clone();
            let mining_status = self.mining_status.clone();
            let miner_instructions = self.miner_instructions.clone();
            self.executor.spawn(async move {
                let new_state = !enable_miner.load(Ordering::SeqCst);
                // The event channel can interrupt the mining thread timeously to stop or start mining
                let _ = match new_state {
                    true => {
                        println!("Mining requested to be turned ON");
                        miner_instructions.send(MinerInstruction::StartMining).map_err(|e| {
                            error!(
                                target: LOG_TARGET,
                                "Could not send 'StartMining' instruction to miner. {:?}.", e
                            );
                            e
                        })
                    },
                    false => {
                        println!("Mining requested to be turned OFF");
                        miner_instructions.send(MinerInstruction::PauseMining).map_err(|e| {
                            error!(
                                target: LOG_TARGET,
                                "Could not send 'PauseMining' instruction to miner. {:?}.", e
                            );
                            e
                        })
                    },
                };
                debug!(
                    target: LOG_TARGET,
                    "Mining state requested to be switched to {}", new_state
                );
                // Verify the mining status
                let mut attempts = 0;
                const DELAY: u64 = 2500;
                const WAIT_CYCLES: usize = 50;
                loop {
                    tokio::time::delay_for(Duration::from_millis(DELAY)).await;
                    if new_state == mining_status.load(Ordering::SeqCst) {
                        match new_state {
                            true => println!("Mining is ON"),
                            false => println!("Mining is OFF"),
                        }
                        break;
                    }
                    attempts += 1;
                    if attempts > WAIT_CYCLES {
                        match new_state {
                            true => println!(
                                "Mining could not be turned ON in {:.1} s (mining enabled is set to {})",
                                DELAY as f32 * attempts as f32 / 1000.0,
                                enable_miner.load(Ordering::SeqCst)
                            ),
                            false => println!(
                                "Mining could not to be turned OFF in {:.1} s (mining enabled is set to {})",
                                DELAY as f32 * attempts as f32 / 1000.0,
                                enable_miner.load(Ordering::SeqCst)
                            ),
                        }
                        break;
                    }
                }
            });
        } else {
            println!("Cannot complete command, Wallet is disabled so Mining is also disabled");
        }
    }
fn process_toggle_mining ( & mut self ) { // 'enable_miner' should not be changed directly; this is done indirectly via miner instructions, // while 'mining_status' will reflect if mining is happening or not if self . wallet_output_service . is_some ( ) { let enable_miner = self . enable_miner . clone ( ) ; let mining_status = self . mining_status . clone ( ) ; let miner_instructions = self . miner_instructions . clone ( ) ; self . executor . spawn ( async move { let new_state = ! enable_miner . load ( Ordering :: SeqCst ) ; // The event channel can interrupt the mining thread timeously to stop or start mining let _ = match new_state { true => { println ! ( " " ) ; miner_instructions . send ( MinerInstruction :: StartMining ) . map_err ( | e | { error ! ( target LOG_TARGET " " e ) ; e } ) } , false => { println ! ( " " ) ; miner_instructions . send ( MinerInstruction :: PauseMining ) . map_err ( | e | { error ! ( target LOG_TARGET " " e ) ; e } ) } , } ; debug ! ( target LOG_TARGET " " new_state ) ; // Verify the mining status let mut attempts = 0 ; const DELAY : u64 = 2500 ; const WAIT_CYCLES : usize = 50 ; loop { tokio :: time :: delay_for ( Duration :: from_millis ( DELAY ) ) . await ; if new_state == mining_status . load ( Ordering :: SeqCst ) { match new_state { true => println ! ( " " ) , false => println ! ( " " ) , } break ; } attempts += 1 ; if attempts > WAIT_CYCLES { match new_state { true => println ! ( " " DELAY as f32 attempts as f32 1000.0 enable_miner load ( Ordering SeqCst ) ) , false => println ! ( " " DELAY as f32 attempts as f32 1000.0 enable_miner load ( Ordering SeqCst ) ) , } break ; } } } ) ; } else { println ! ( " " ) ; } }
Function to process the toggle-mining command
Function to process the toggle - mining command
&mut self
&mut self