pub fn forks(&self, head: &str) -> Option<Vec<Block>> {
        let state = self
            .state
            .read()
            .expect("No lock holder should have poisoned the lock");

        match state.block_manager.ref_block(head) {
            Ok(_) => {}
            Err(BlockManagerError::UnknownBlock) => return None,
            Err(err) => {
                error!("Unexpected error occurred: {:?}", err);
                return None;
            }
        }

        let mut forks: Vec<Block> = state
            .fork_cache
            .forks()
            .into_iter()
            .flat_map(|fork_head: &String| {
                state
                    .block_manager
                    .branch_diff(fork_head, head)
                    .expect("Fork not found, but should be referenced")
            })
            .collect();

        forks.sort_by(|left, right| {
            left.block_num
                .cmp(&right.block_num)
                .then(left.header_signature.cmp(&right.header_signature))
        });
        forks.dedup_by(|left, right| left.header_signature == right.header_signature);

        Some(forks)
    }
// Returns all blocks in forks not on the chain with the given head. If head is None, uses the
// current chain head. If head is not found, returns None.
Returns all blocks in forks not on the chain with the given head. If head is None, uses the
current chain head. If head is not found, returns None.
Returns all blocks in forks not on the chain with the given head . If head is None uses the current chain head . If head is not found returns None .
pub fn forks(&self, head: &str) -> Option<Vec<Block>> {
        let state = self
            .state
            .read()
            .expect("No lock holder should have poisoned the lock");
        match state.block_manager.ref_block(head) {
            Ok(_) => {}
            Err(BlockManagerError::UnknownBlock) => return None,
            Err(err) => {
                error!("Unexpected error occurred: {:?}", err);
                return None;
            }
        }
        let mut forks: Vec<Block> = state
            .fork_cache
            .forks()
            .into_iter()
            .flat_map(|fork_head: &String| {
                state
                    .block_manager
                    .branch_diff(fork_head, head)
                    .expect("Fork not found, but should be referenced")
            })
            .collect();
        forks.sort_by(|left, right| {
            left.block_num
                .cmp(&right.block_num)
                .then(left.header_signature.cmp(&right.header_signature))
        });
        forks.dedup_by(|left, right| left.header_signature == right.header_signature);
        Some(forks)
    }
pub fn forks ( & self , head : & str ) -> Option < Vec < Block > > { let state = self . state . read ( ) . expect ( " " ) ; match state . block_manager . ref_block ( head ) { Ok ( _ ) => { } Err ( BlockManagerError :: UnknownBlock ) => return None , Err ( err ) => { error ! ( " " err ) ; return None ; } } let mut forks : Vec < Block > = state . fork_cache . forks ( ) . into_iter ( ) . flat_map ( | fork_head : & String | { state . block_manager . branch_diff ( fork_head , head ) . expect ( " " ) } ) . collect ( ) ; forks . sort_by ( | left , right | { left . block_num . cmp ( & right . block_num ) . then ( left . header_signature . cmp ( & right . header_signature ) ) } ) ; forks . dedup_by ( | left , right | left . header_signature == right . header_signature ) ; Some ( forks ) }
Returns all blocks in forks not on the chain with the given head.
Returns all blocks in forks not on the chain with the given head .
&self
head
&str
&self
head
&str