/// Request any blocks from the blockchain, to update the local blockchain state.
/// Scans the blockchain for transactions that are sent to this user, accordingly updating `data`.
Request any blocks from the blockchain, to update the local blockchain state.
Scans the blockchain for transactions that are sent to this user, accordingly updating `data`.
Request any blocks from the blockchain to update the local blockchain state . Scans the blockchain for transactions that are sent to this user accordingly updating ` data ` .
pub fn update(data: &mut UserData) -> std::io::Result<()> {
    let mut stream = TcpStream::connect(format!("{}:{}", constants::HOST, constants::PORT))?;
    send(&mut stream, Command::Update)?;
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let chain_size = data.blockchain.blocks.len();
    stream_writer.write_all(&u64_array_to_u8_vector(&[chain_size as u64]))?;
    stream_writer.flush()?;
    let mut block_amount = [0; 8];
    stream_reader.read_exact(&mut block_amount)?;
    let block_amount = u8_array_to_u64(&block_amount);
    for _ in 0..block_amount {
        let new_block = Block::read(stream_reader.by_ref())?;
        scan(&new_block, data);
        data.blockchain.blocks.push(new_block)
    }
    Ok(())
}
pub fn update ( data : & mut UserData ) -> std :: io :: Result < ( ) > { let mut stream = TcpStream :: connect ( format ! ( " " constants HOST constants PORT ) ) ? ; send ( & mut stream , Command :: Update ) ? ; let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; let chain_size = data . blockchain . blocks . len ( ) ; stream_writer . write_all ( & u64_array_to_u8_vector ( & [ chain_size as u64 ] ) ) ? ; stream_writer . flush ( ) ? ; let mut block_amount = [ 0 ; 8 ] ; stream_reader . read_exact ( & mut block_amount ) ? ; let block_amount = u8_array_to_u64 ( & block_amount ) ; for _ in 0 .. block_amount { let new_block = Block :: read ( stream_reader . by_ref ( ) ) ? ; scan ( & new_block , data ) ; data . blockchain . blocks . push ( new_block ) } Ok ( ( ) ) }
Request any blocks from the blockchain, to update the local blockchain state.
Request any blocks from the blockchain to update the local blockchain state .
data
&mut UserData