pub fn tree_route<Block: BlockT, Backend: HeaderBackend<Block>>(
	backend: &Backend,
	from: BlockId<Block>,
	to: BlockId<Block>,
) -> Result<TreeRoute<Block>> {
	use runtime_primitives::traits::Header;

	let load_header = |id: BlockId<Block>| {
		match backend.header(id) {
			Ok(Some(hdr)) => Ok(hdr),
			Ok(None) => Err(ErrorKind::UnknownBlock(format!("Unknown block {:?}", id)).into()),
			Err(e) => Err(e),
		}
	};

	let mut from = load_header(from)?;
	let mut to = load_header(to)?;

	let mut from_branch = Vec::new();
	let mut to_branch = Vec::new();

	while to.number() > from.number() {
		to_branch.push(RouteEntry {
			number: to.number().clone(),
			hash: to.hash(),
		});

		to = load_header(BlockId::Hash(*to.parent_hash()))?;
	}

	while from.number() > to.number() {
		from_branch.push(RouteEntry {
			number: from.number().clone(),
			hash: from.hash(),
		});
		from = load_header(BlockId::Hash(*from.parent_hash()))?;
	}

	// numbers are equal now. walk backwards until the block is the same

	while to != from {
		to_branch.push(RouteEntry {
			number: to.number().clone(),
			hash: to.hash(),
		});
		to = load_header(BlockId::Hash(*to.parent_hash()))?;

		from_branch.push(RouteEntry {
			number: from.number().clone(),
			hash: from.hash(),
		});
		from = load_header(BlockId::Hash(*from.parent_hash()))?;
	}

	// add the pivot block. and append the reversed to-branch (note that it's reverse order originalls)
	let pivot = from_branch.len();
	from_branch.push(RouteEntry {
		number: to.number().clone(),
		hash: to.hash(),
	});
	from_branch.extend(to_branch.into_iter().rev());

	Ok(TreeRoute {
		route: from_branch,
		pivot,
	})
}
/// Compute a tree-route between two blocks. See tree-route docs for more details.
Compute a tree-route between two blocks. See tree-route docs for more details.
Compute a tree - route between two blocks . See tree - route docs for more details .
pub fn tree_route<Block: BlockT, Backend: HeaderBackend<Block>>(
	backend: &Backend,
	from: BlockId<Block>,
	to: BlockId<Block>,
) -> Result<TreeRoute<Block>> {
	use runtime_primitives::traits::Header;
	let load_header = |id: BlockId<Block>| {
		match backend.header(id) {
			Ok(Some(hdr)) => Ok(hdr),
			Ok(None) => Err(ErrorKind::UnknownBlock(format!("Unknown block {:?}", id)).into()),
			Err(e) => Err(e),
		}
	};
	let mut from = load_header(from)?;
	let mut to = load_header(to)?;
	let mut from_branch = Vec::new();
	let mut to_branch = Vec::new();
	while to.number() > from.number() {
		to_branch.push(RouteEntry {
			number: to.number().clone(),
			hash: to.hash(),
		});
		to = load_header(BlockId::Hash(*to.parent_hash()))?;
	}
	while from.number() > to.number() {
		from_branch.push(RouteEntry {
			number: from.number().clone(),
			hash: from.hash(),
		});
		from = load_header(BlockId::Hash(*from.parent_hash()))?;
	}
	// numbers are equal now. walk backwards until the block is the same
	while to != from {
		to_branch.push(RouteEntry {
			number: to.number().clone(),
			hash: to.hash(),
		});
		to = load_header(BlockId::Hash(*to.parent_hash()))?;
		from_branch.push(RouteEntry {
			number: from.number().clone(),
			hash: from.hash(),
		});
		from = load_header(BlockId::Hash(*from.parent_hash()))?;
	}
	// add the pivot block. and append the reversed to-branch (note that it's reverse order originalls)
	let pivot = from_branch.len();
	from_branch.push(RouteEntry {
		number: to.number().clone(),
		hash: to.hash(),
	});
	from_branch.extend(to_branch.into_iter().rev());
	Ok(TreeRoute {
		route: from_branch,
		pivot,
	})
}
pub fn tree_route < Block : BlockT , Backend : HeaderBackend < Block > > ( backend : & Backend , from : BlockId < Block > , to : BlockId < Block > , ) -> Result < TreeRoute < Block > > { use runtime_primitives :: traits :: Header ; let load_header = | id : BlockId < Block > | { match backend . header ( id ) { Ok ( Some ( hdr ) ) => Ok ( hdr ) , Ok ( None ) => Err ( ErrorKind :: UnknownBlock ( format ! ( " " id ) ) . into ( ) ) , Err ( e ) => Err ( e ) , } } ; let mut from = load_header ( from ) ? ; let mut to = load_header ( to ) ? ; let mut from_branch = Vec :: new ( ) ; let mut to_branch = Vec :: new ( ) ; while to . number ( ) > from . number ( ) { to_branch . push ( RouteEntry { number : to . number ( ) . clone ( ) , hash : to . hash ( ) , } ) ; to = load_header ( BlockId :: Hash ( * to . parent_hash ( ) ) ) ? ; } while from . number ( ) > to . number ( ) { from_branch . push ( RouteEntry { number : from . number ( ) . clone ( ) , hash : from . hash ( ) , } ) ; from = load_header ( BlockId :: Hash ( * from . parent_hash ( ) ) ) ? ; } // numbers are equal now. walk backwards until the block is the same while to != from { to_branch . push ( RouteEntry { number : to . number ( ) . clone ( ) , hash : to . hash ( ) , } ) ; to = load_header ( BlockId :: Hash ( * to . parent_hash ( ) ) ) ? ; from_branch . push ( RouteEntry { number : from . number ( ) . clone ( ) , hash : from . hash ( ) , } ) ; from = load_header ( BlockId :: Hash ( * from . parent_hash ( ) ) ) ? ; } // add the pivot block. and append the reversed to-branch (note that it's reverse order originalls) let pivot = from_branch . len ( ) ; from_branch . push ( RouteEntry { number : to . number ( ) . clone ( ) , hash : to . hash ( ) , } ) ; from_branch . extend ( to_branch . into_iter ( ) . rev ( ) ) ; Ok ( TreeRoute { route : from_branch , pivot , } ) }
Compute a tree-route between two blocks.
Compute a tree - route between two blocks .
backend
&Backend
from
BlockId<Block>
to
BlockId<Block>
backend
&Backend
from
BlockId<Block>
to
BlockId<Block>