/// This function handles the server side of an `Update` command.
This function handles the server side of an `Update` command.
This function handles the server side of an ` Update ` command .
pub fn update(stream: TcpStream, blockchain: Arc<RwLock<BlockChain>>) -> std::io::Result<()> {
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let mut client_chain_size = [0; 8];
    stream_reader.read_exact(&mut client_chain_size)?;
    let mut index = u8_array_to_u64(&client_chain_size) as usize;
    let blockchain = blockchain.read().unwrap();
    let block_amount = blockchain.blocks.len() - index;
    stream_writer.write_all(&u64_array_to_u8_vector(&[block_amount as u64]))?;
    while index < blockchain.blocks.len() {
        blockchain.blocks[index].write(stream_writer.by_ref())?;
        index += 1
    }
    stream_writer.flush()?;
    Ok(())
}
pub fn update ( stream : TcpStream , blockchain : Arc < RwLock < BlockChain > > ) -> std :: io :: Result < ( ) > { let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; let mut client_chain_size = [ 0 ; 8 ] ; stream_reader . read_exact ( & mut client_chain_size ) ? ; let mut index = u8_array_to_u64 ( & client_chain_size ) as usize ; let blockchain = blockchain . read ( ) . unwrap ( ) ; let block_amount = blockchain . blocks . len ( ) - index ; stream_writer . write_all ( & u64_array_to_u8_vector ( & [ block_amount as u64 ] ) ) ? ; while index < blockchain . blocks . len ( ) { blockchain . blocks [ index ] . write ( stream_writer . by_ref ( ) ) ? ; index += 1 } stream_writer . flush ( ) ? ; Ok ( ( ) ) }
This function handles the server side of an `Update` command.
This function handles the server side of an ` Update ` command .
stream
TcpStream
blockchain
Arc<RwLock<BlockChain>>