pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
	client: &Client<B, E, Block, RA>,
	base: (Block::Hash, NumberFor<Block>),
	base_is_canonical: bool,
	height: NumberFor<Block>,
) -> Result<Option<Block::Hash>, ClientError> where
	B: Backend<Block, Blake2Hasher>,
	E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
{
	use runtime_primitives::traits::{One, Zero, BlockNumberToHash};

	if height > base.1 {
		return Ok(None);
	}

	if height == base.1 {
		if base_is_canonical {
			return Ok(Some(base.0));
		} else {
			return Ok(client.block_number_to_hash(height));
		}
	} else if base_is_canonical {
		return Ok(client.block_number_to_hash(height));
	}

	let one = NumberFor::<Block>::one();

	// start by getting _canonical_ block with number at parent position and then iterating
	// backwards by hash.
	let mut current = match client.header(&BlockId::Number(base.1 - one))? {
		Some(header) => header,
		_ => return Ok(None),
	};

	// we've already checked that base > height above.
	let mut steps = base.1 - height - one;

	while steps > NumberFor::<Block>::zero() {
		current = match client.header(&BlockId::Hash(*current.parent_hash()))? {
			Some(header) => header,
			_ => return Ok(None),
		};

		steps -= one;
	}

	Ok(Some(current.hash()))
}
/// Using the given base get the block at the given height on this chain. The
/// target block must be an ancestor of base, therefore `height <= base.height`.
Using the given base get the block at the given height on this chain. The
target block must be an ancestor of base, therefore `height <= base.height`.
Using the given base get the block at the given height on this chain . The target block must be an ancestor of base therefore ` height < = base . height ` .
pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
	client: &Client<B, E, Block, RA>,
	base: (Block::Hash, NumberFor<Block>),
	base_is_canonical: bool,
	height: NumberFor<Block>,
) -> Result<Option<Block::Hash>, ClientError> where
	B: Backend<Block, Blake2Hasher>,
	E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
{
	use runtime_primitives::traits::{One, Zero, BlockNumberToHash};
	if height > base.1 {
		return Ok(None);
	}
	if height == base.1 {
		if base_is_canonical {
			return Ok(Some(base.0));
		} else {
			return Ok(client.block_number_to_hash(height));
		}
	} else if base_is_canonical {
		return Ok(client.block_number_to_hash(height));
	}
	let one = NumberFor::<Block>::one();
	// start by getting _canonical_ block with number at parent position and then iterating
	// backwards by hash.
	let mut current = match client.header(&BlockId::Number(base.1 - one))? {
		Some(header) => header,
		_ => return Ok(None),
	};
	// we've already checked that base > height above.
	let mut steps = base.1 - height - one;
	while steps > NumberFor::<Block>::zero() {
		current = match client.header(&BlockId::Hash(*current.parent_hash()))? {
			Some(header) => header,
			_ => return Ok(None),
		};
		steps -= one;
	}
	Ok(Some(current.hash()))
}
pub ( crate ) fn canonical_at_height < B , E , Block : BlockT < Hash = H256 > , RA > ( client : & Client < B , E , Block , RA > , base : ( Block :: Hash , NumberFor < Block > ) , base_is_canonical : bool , height : NumberFor < Block > , ) -> Result < Option < Block :: Hash > , ClientError > where B : Backend < Block , Blake2Hasher > , E : CallExecutor < Block , Blake2Hasher > + Send + Sync , { use runtime_primitives :: traits :: { One , Zero , BlockNumberToHash } ; if height > base . 1 { return Ok ( None ) ; } if height == base . 1 { if base_is_canonical { return Ok ( Some ( base . 0 ) ) ; } else { return Ok ( client . block_number_to_hash ( height ) ) ; } } else if base_is_canonical { return Ok ( client . block_number_to_hash ( height ) ) ; } let one = NumberFor :: < Block > :: one ( ) ; // start by getting _canonical_ block with number at parent position and then iterating // backwards by hash. let mut current = match client . header ( & BlockId :: Number ( base . 1 - one ) ) ? { Some ( header ) => header , _ => return Ok ( None ) , } ; // we've already checked that base > height above. let mut steps = base . 1 - height - one ; while steps > NumberFor :: < Block > :: zero ( ) { current = match client . header ( & BlockId :: Hash ( * current . parent_hash ( ) ) ) ? { Some ( header ) => header , _ => return Ok ( None ) , } ; steps -= one ; } Ok ( Some ( current . hash ( ) ) ) }
Using the given base get the block at the given height on this chain.
Using the given base get the block at the given height on this chain .
client
&Client<B, E, Block, RA>
base
(Block::Hash, NumberFor<Block>)
base_is_canonical
bool
height
NumberFor<Block>
client
&Client<B, E, Block, RA>
base
(Block::Hash, NumberFor<Block>)
base_is_canonical
bool
height
NumberFor<Block>