pub(crate) fn from_commit<B, E, RA>(
		client: &Client<B, E, Block, RA>,
		round: u64,
		commit: Commit<Block>,
	) -> Result<GrandpaJustification<Block>, Error> where
		B: Backend<Block, Blake2Hasher>,
		E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
		RA: Send + Sync,
	{
		let mut votes_ancestries_hashes = HashSet::new();
		let mut votes_ancestries = Vec::new();

		let error = || {
			let msg = "invalid precommits for target commit".to_string();
			Err(Error::Client(ClientErrorKind::BadJustification(msg).into()))
		};

		for signed in commit.precommits.iter() {
			let mut current_hash = signed.precommit.target_hash.clone();
			loop {
				if current_hash == commit.target_hash { break; }

				match client.backend().blockchain().header(BlockId::Hash(current_hash))? {
					Some(current_header) => {
						if *current_header.number() <= commit.target_number {
							return error();
						}

						let parent_hash = current_header.parent_hash().clone();
						if votes_ancestries_hashes.insert(current_hash) {
							votes_ancestries.push(current_header);
						}
						current_hash = parent_hash;
					},
					_ => return error(),
				}
			}
		}

		Ok(GrandpaJustification { round, commit, votes_ancestries })
	}
/// Create a GRANDPA justification from the given commit. This method
/// assumes the commit is valid and well-formed.
Create a GRANDPA justification from the given commit. This method
assumes the commit is valid and well-formed.
Create a GRANDPA justification from the given commit . This method assumes the commit is valid and well - formed .
pub(crate) fn from_commit<B, E, RA>(
		client: &Client<B, E, Block, RA>,
		round: u64,
		commit: Commit<Block>,
	) -> Result<GrandpaJustification<Block>, Error> where
		B: Backend<Block, Blake2Hasher>,
		E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
		RA: Send + Sync,
	{
		let mut votes_ancestries_hashes = HashSet::new();
		let mut votes_ancestries = Vec::new();
		let error = || {
			let msg = "invalid precommits for target commit".to_string();
			Err(Error::Client(ClientErrorKind::BadJustification(msg).into()))
		};
		for signed in commit.precommits.iter() {
			let mut current_hash = signed.precommit.target_hash.clone();
			loop {
				if current_hash == commit.target_hash { break; }
				match client.backend().blockchain().header(BlockId::Hash(current_hash))? {
					Some(current_header) => {
						if *current_header.number() <= commit.target_number {
							return error();
						}
						let parent_hash = current_header.parent_hash().clone();
						if votes_ancestries_hashes.insert(current_hash) {
							votes_ancestries.push(current_header);
						}
						current_hash = parent_hash;
					},
					_ => return error(),
				}
			}
		}
		Ok(GrandpaJustification { round, commit, votes_ancestries })
	}
pub ( crate ) fn from_commit < B , E , RA > ( client : & Client < B , E , Block , RA > , round : u64 , commit : Commit < Block > , ) -> Result < GrandpaJustification < Block > , Error > where B : Backend < Block , Blake2Hasher > , E : CallExecutor < Block , Blake2Hasher > + Send + Sync , RA : Send + Sync , { let mut votes_ancestries_hashes = HashSet :: new ( ) ; let mut votes_ancestries = Vec :: new ( ) ; let error = | | { let msg = " " . to_string ( ) ; Err ( Error :: Client ( ClientErrorKind :: BadJustification ( msg ) . into ( ) ) ) } ; for signed in commit . precommits . iter ( ) { let mut current_hash = signed . precommit . target_hash . clone ( ) ; loop { if current_hash == commit . target_hash { break ; } match client . backend ( ) . blockchain ( ) . header ( BlockId :: Hash ( current_hash ) ) ? { Some ( current_header ) => { if * current_header . number ( ) <= commit . target_number { return error ( ) ; } let parent_hash = current_header . parent_hash ( ) . clone ( ) ; if votes_ancestries_hashes . insert ( current_hash ) { votes_ancestries . push ( current_header ) ; } current_hash = parent_hash ; } , _ => return error ( ) , } } } Ok ( GrandpaJustification { round , commit , votes_ancestries } ) }
Create a GRANDPA justification from the given commit.
Create a GRANDPA justification from the given commit .
client
&Client<B, E, Block, RA>
round
u64
commit
Commit<Block>
client
&Client<B, E, Block, RA>
round
u64
commit
Commit<Block>