/// Handle the input from the terminal on a separate thread, using the shared `blockchain` and
/// server `data`.
Handle the input from the terminal on a separate thread, using the shared `blockchain` and
server `data`.
Handle the input from the terminal on a separate thread using the shared ` blockchain ` and server ` data ` .
fn handle_input(blockchain: Arc<RwLock<BlockChain>>, data: Arc<ServerData>) {
    println!("Available commands:");
    println!("   update:   Add a new block to the blockchain.");
    println!("   show:     Show the blockchain.");
    println!("   quit:     Quit program.\n");
    loop {
        let mut input = String::new();
        std::io::stdin()
            .read_line(&mut input)
            .expect("Reading from stdin should always work.");
        match input.to_ascii_lowercase().trim() {
            "update" | "u" => {
                let mut blockchain = blockchain.write().unwrap();
                blockchain
                    .refresh(data.clone())
                    .expect("Trees should not be full.");
                println!("New block successfully created.\n");
            }
            "show" | "s" => {
                let blockchain = blockchain.read().unwrap();
                println!("{}", blockchain);
            }
            "quit" | "q" | "exit" | "e" => {
                let blockchain = blockchain.write().unwrap();
                blockchain
                    .write(data.name)
                    .expect("Writing the blockchain on quit should succeed.");
                println!("Bye!");
                break;
            }
            _ => println!("Unknown command."),
        }
    }
}
fn handle_input ( blockchain : Arc < RwLock < BlockChain > > , data : Arc < ServerData > ) { println ! ( " " ) ; println ! ( " " ) ; println ! ( " " ) ; println ! ( " \n " ) ; loop { let mut input = String :: new ( ) ; std :: io :: stdin ( ) . read_line ( & mut input ) . expect ( " " ) ; match input . to_ascii_lowercase ( ) . trim ( ) { " " | " " => { let mut blockchain = blockchain . write ( ) . unwrap ( ) ; blockchain . refresh ( data . clone ( ) ) . expect ( " " ) ; println ! ( " \n " ) ; } " " | " " => { let blockchain = blockchain . read ( ) . unwrap ( ) ; println ! ( " " blockchain ) ; } " " | " " | " " | " " => { let blockchain = blockchain . write ( ) . unwrap ( ) ; blockchain . write ( data . name ) . expect ( " " ) ; println ! ( " " ) ; break ; } _ => println ! ( " " ) , } } }
Handle the input from the terminal on a separate thread, using the shared `blockchain` and
server `data`.
Handle the input from the terminal on a separate thread using the shared ` blockchain ` and server ` data ` .
blockchain
Arc<RwLock<BlockChain>>
data
Arc<ServerData>