fn fetch_target_difficulties(
        &self,
        pow_algo: PowAlgorithm,
        height: u64,
        block_window: usize,
    ) -> Result<Vec<(EpochTime, Difficulty)>, ChainStorageError>
    {
        let mut target_difficulties = VecDeque::<(EpochTime, Difficulty)>::with_capacity(block_window);
        let tip_height = self.fetch_chain_height()?.ok_or_else(|| {
            ChainStorageError::InvalidQuery("Cannot retrieve chain height. Blockchain DB is empty".into())
        })?;
        if height <= tip_height {
            let db = self.db_access()?;
            for height in (0..=height).rev() {
                let header = db
                    .headers
                    .get(&height)
                    .ok_or_else(|| ChainStorageError::InvalidQuery("Cannot retrieve header.".into()))?;
                if header.pow.pow_algo == pow_algo {
                    target_difficulties.push_front((header.timestamp, header.pow.target_difficulty));
                    if target_difficulties.len() >= block_window {
                        break;
                    }
                }
            }
        }
        Ok(target_difficulties
            .into_iter()
            .collect::<Vec<(EpochTime, Difficulty)>>())
    }
/// Returns the set of target difficulties for the specified proof of work algorithm.
Returns the set of target difficulties for the specified proof of work algorithm.
Returns the set of target difficulties for the specified proof of work algorithm .
fn fetch_target_difficulties(
        &self,
        pow_algo: PowAlgorithm,
        height: u64,
        block_window: usize,
    ) -> Result<Vec<(EpochTime, Difficulty)>, ChainStorageError>
    {
        let mut target_difficulties = VecDeque::<(EpochTime, Difficulty)>::with_capacity(block_window);
        let tip_height = self.fetch_chain_height()?.ok_or_else(|| {
            ChainStorageError::InvalidQuery("Cannot retrieve chain height. Blockchain DB is empty".into())
        })?;
        if height <= tip_height {
            let db = self.db_access()?;
            for height in (0..=height).rev() {
                let header = db
                    .headers
                    .get(&height)
                    .ok_or_else(|| ChainStorageError::InvalidQuery("Cannot retrieve header.".into()))?;
                if header.pow.pow_algo == pow_algo {
                    target_difficulties.push_front((header.timestamp, header.pow.target_difficulty));
                    if target_difficulties.len() >= block_window {
                        break;
                    }
                }
            }
        }
        Ok(target_difficulties
            .into_iter()
            .collect::<Vec<(EpochTime, Difficulty)>>())
    }
fn fetch_target_difficulties ( & self , pow_algo : PowAlgorithm , height : u64 , block_window : usize , ) -> Result < Vec < ( EpochTime , Difficulty ) > , ChainStorageError > { let mut target_difficulties = VecDeque :: < ( EpochTime , Difficulty ) > :: with_capacity ( block_window ) ; let tip_height = self . fetch_chain_height ( ) ? . ok_or_else ( | | { ChainStorageError :: InvalidQuery ( " " . into ( ) ) } ) ? ; if height <= tip_height { let db = self . db_access ( ) ? ; for height in ( 0 ..= height ) . rev ( ) { let header = db . headers . get ( & height ) . ok_or_else ( | | ChainStorageError :: InvalidQuery ( " " . into ( ) ) ) ? ; if header . pow . pow_algo == pow_algo { target_difficulties . push_front ( ( header . timestamp , header . pow . target_difficulty ) ) ; if target_difficulties . len ( ) >= block_window { break ; } } } } Ok ( target_difficulties . into_iter ( ) . collect :: < Vec < ( EpochTime , Difficulty ) > > ( ) ) }
Returns the set of target difficulties for the specified proof of work algorithm.
Returns the set of target difficulties for the specified proof of work algorithm .
&self
pow_algo
PowAlgorithm
height
u64
block_window
usize
&self
pow_algo
PowAlgorithm
height
u64
block_window
usize