/// Read this `Block` from a `reader` and return the created object.
Read this `Block` from a `reader` and return the created object.
Read this ` Block ` from a ` reader ` and return the created object .
pub fn read<R: Read>(mut reader: R) -> std::io::Result<Block> {
        let mut hash = [0; 32];
        let mut prev_hash = [0; 32];
        let mut index = [0; 8];
        let mut rt_cred = [0; 32];
        let mut rt_note = [0; 32];
        let mut rt_mem = [0; 32];
        let mut transaction_amount = [0; 8];
        reader.read_exact(&mut hash)?;
        reader.read_exact(&mut prev_hash)?;
        reader.read_exact(&mut index)?;
        let index = u8_array_to_u64(&index) as usize;
        reader.read_exact(&mut rt_cred)?;
        let rt_cred = fr_from_repr(rt_cred)?;
        reader.read_exact(&mut rt_note)?;
        let rt_note = fr_from_repr(rt_note)?;
        reader.read_exact(&mut rt_mem)?;
        let rt_mem = fr_from_repr(rt_mem)?;
        reader.read_exact(&mut transaction_amount)?;
        let mut block = Block {
            hash,
            prev_hash,
            index,
            rt_cred,
            rt_note,
            rt_mem,
            transactions: vec![],
        };
        let transaction_amount = u8_array_to_u64(&transaction_amount);
        for _ in 0..transaction_amount {
            let mut transaction_type = [0; 1];
            reader.read_exact(&mut transaction_type)?;
            match transaction_type[0] {
                t if t == Command::Cred as u8 => {
                    block.add_transaction(Box::new(CredTransaction::from_u8(reader.by_ref())?));
                }
                t if t == Command::CTo as u8 => {
                    block.add_transaction(Box::new(CToTransaction::<[u8; 32]>::from_u8(
                        reader.by_ref(),
                    )?));
                }
                t if t == Command::CFrom as u8 => {
                    block.add_transaction(Box::new(CFromTransaction::from_u8(reader.by_ref())?));
                }
                t if t == Command::Transfer as u8 => {
                    block.add_transaction(Box::new(TransferTransaction::<[u8; 32]>::from_u8(
                        reader.by_ref(),
                    )?));
                }
                _ => {
                    return Err(std::io::Error::new(
                        std::io::ErrorKind::Other,
                        "Unknown transaction type.",
                    ));
                }
            }
        }
        Ok(block)
    }
pub fn read < R : Read > ( mut reader : R ) -> std :: io :: Result < Block > { let mut hash = [ 0 ; 32 ] ; let mut prev_hash = [ 0 ; 32 ] ; let mut index = [ 0 ; 8 ] ; let mut rt_cred = [ 0 ; 32 ] ; let mut rt_note = [ 0 ; 32 ] ; let mut rt_mem = [ 0 ; 32 ] ; let mut transaction_amount = [ 0 ; 8 ] ; reader . read_exact ( & mut hash ) ? ; reader . read_exact ( & mut prev_hash ) ? ; reader . read_exact ( & mut index ) ? ; let index = u8_array_to_u64 ( & index ) as usize ; reader . read_exact ( & mut rt_cred ) ? ; let rt_cred = fr_from_repr ( rt_cred ) ? ; reader . read_exact ( & mut rt_note ) ? ; let rt_note = fr_from_repr ( rt_note ) ? ; reader . read_exact ( & mut rt_mem ) ? ; let rt_mem = fr_from_repr ( rt_mem ) ? ; reader . read_exact ( & mut transaction_amount ) ? ; let mut block = Block { hash , prev_hash , index , rt_cred , rt_note , rt_mem , transactions : vec ! [ ] , } ; let transaction_amount = u8_array_to_u64 ( & transaction_amount ) ; for _ in 0 .. transaction_amount { let mut transaction_type = [ 0 ; 1 ] ; reader . read_exact ( & mut transaction_type ) ? ; match transaction_type [ 0 ] { t if t == Command :: Cred as u8 => { block . add_transaction ( Box :: new ( CredTransaction :: from_u8 ( reader . by_ref ( ) ) ? ) ) ; } t if t == Command :: CTo as u8 => { block . add_transaction ( Box :: new ( CToTransaction :: < [ u8 ; 32 ] > :: from_u8 ( reader . by_ref ( ) , ) ? ) ) ; } t if t == Command :: CFrom as u8 => { block . add_transaction ( Box :: new ( CFromTransaction :: from_u8 ( reader . by_ref ( ) ) ? ) ) ; } t if t == Command :: Transfer as u8 => { block . add_transaction ( Box :: new ( TransferTransaction :: < [ u8 ; 32 ] > :: from_u8 ( reader . by_ref ( ) , ) ? ) ) ; } _ => { return Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , " " , ) ) ; } } } Ok ( block ) }
Read this `Block` from a `reader` and return the created object.
Read this ` Block ` from a ` reader ` and return the created object .
reader
R