/// Add `block` to this `Blockchain` and update the Merkle Trees accordingly.
Add `block` to this `Blockchain` and update the Merkle Trees accordingly.
Add ` block ` to this ` Blockchain ` and update the Merkle Trees accordingly .
pub fn add_block(
        &mut self,
        mut block: Block,
        server_data: Option<Arc<ServerData>>,
    ) -> Result<(), ()> {
        let mut transaction_hashes = vec![];
        for (i, transaction) in block.transactions.iter().enumerate() {
            transaction_hashes.extend(transaction.as_u8().unwrap());
            transaction.update_trees(self)?;
            if let Some(server_data) = server_data.as_ref() {
                transaction.scan_server(server_data, self, &block.transactions[i..]);
            }
        }
        block.hash = *blake2s_simd::Params::new()
            .hash_length(32)
            .personal(constants::PERSONALISATION_BLOCK_HASH)
            .to_state()
            .update(&block.prev_hash)
            .update(&[block.index as u8])
            .update(&block.rt_cred.to_repr())
            .update(&block.rt_note.to_repr())
            .update(&block.rt_mem.to_repr())
            .update(&transaction_hashes)
            .finalize()
            .as_array();
        block.rt_cred = self.tree_cred.root_value();
        block.rt_mem = self.tree_mem.root_value();
        block.rt_note = self.tree_mem.root_value();
        self.new_block = Some(Block::new(&block));
        self.blocks.push(block);
        Ok(())
    }
pub fn add_block ( & mut self , mut block : Block , server_data : Option < Arc < ServerData > > , ) -> Result < ( ) , ( ) > { let mut transaction_hashes = vec ! [ ] ; for ( i , transaction ) in block . transactions . iter ( ) . enumerate ( ) { transaction_hashes . extend ( transaction . as_u8 ( ) . unwrap ( ) ) ; transaction . update_trees ( self ) ? ; if let Some ( server_data ) = server_data . as_ref ( ) { transaction . scan_server ( server_data , self , & block . transactions [ i .. ] ) ; } } block . hash = * blake2s_simd :: Params :: new ( ) . hash_length ( 32 ) . personal ( constants :: PERSONALISATION_BLOCK_HASH ) . to_state ( ) . update ( & block . prev_hash ) . update ( & [ block . index as u8 ] ) . update ( & block . rt_cred . to_repr ( ) ) . update ( & block . rt_note . to_repr ( ) ) . update ( & block . rt_mem . to_repr ( ) ) . update ( & transaction_hashes ) . finalize ( ) . as_array ( ) ; block . rt_cred = self . tree_cred . root_value ( ) ; block . rt_mem = self . tree_mem . root_value ( ) ; block . rt_note = self . tree_mem . root_value ( ) ; self . new_block = Some ( Block :: new ( & block ) ) ; self . blocks . push ( block ) ; Ok ( ( ) ) }
Add `block` to this `Blockchain` and update the Merkle Trees accordingly.
Add ` block ` to this ` Blockchain ` and update the Merkle Trees accordingly .
&mut self
block
Block
server_data
Option<Arc<ServerData>>