pub fn sign_message<B: Block + Clone>(
	message: RhdMessage<B, B::Hash>,
	key: &ed25519::Pair,
	parent_hash: B::Hash
) -> LocalizedMessage<B> {
	let signer = key.public();

	let sign_action = |action: Action<B, B::Hash>| {
		let to_sign = localized_encode(parent_hash.clone(), action);

		LocalizedSignature {
			signer: signer.clone(),
			signature: key.sign(&to_sign),
		}
	};

	match message {
		RhdMessage::Propose(r, proposal) => {
			let header_hash = proposal.hash();
			let action_header = Action::ProposeHeader(r as u32, header_hash.clone());
			let action_propose = Action::Propose(r as u32, proposal.clone());

			rhododendron::LocalizedMessage::Propose(rhododendron::LocalizedProposal {
				round_number: r,
				proposal,
				digest: header_hash,
				sender: signer.clone().into(),
				digest_signature: sign_action(action_header),
				full_signature: sign_action(action_propose),
			})
		}
		RhdMessage::Vote(vote) => rhododendron::LocalizedMessage::Vote({
			let action = match vote {
				RhdMessageVote::Prepare(r, h) => Action::Prepare(r as u32, h),
				RhdMessageVote::Commit(r, h) => Action::Commit(r as u32, h),
				RhdMessageVote::AdvanceRound(r) => Action::AdvanceRound(r as u32),
			};

			rhododendron::LocalizedVote {
				vote: vote,
				sender: signer.clone().into(),
				signature: sign_action(action),
			}
		})
	}
}
/// Sign a BFT message with the given key.
Sign a BFT message with the given key.
Sign a BFT message with the given key .
pub fn sign_message<B: Block + Clone>(
	message: RhdMessage<B, B::Hash>,
	key: &ed25519::Pair,
	parent_hash: B::Hash
) -> LocalizedMessage<B> {
	let signer = key.public();
	let sign_action = |action: Action<B, B::Hash>| {
		let to_sign = localized_encode(parent_hash.clone(), action);
		LocalizedSignature {
			signer: signer.clone(),
			signature: key.sign(&to_sign),
		}
	};
	match message {
		RhdMessage::Propose(r, proposal) => {
			let header_hash = proposal.hash();
			let action_header = Action::ProposeHeader(r as u32, header_hash.clone());
			let action_propose = Action::Propose(r as u32, proposal.clone());
			rhododendron::LocalizedMessage::Propose(rhododendron::LocalizedProposal {
				round_number: r,
				proposal,
				digest: header_hash,
				sender: signer.clone().into(),
				digest_signature: sign_action(action_header),
				full_signature: sign_action(action_propose),
			})
		}
		RhdMessage::Vote(vote) => rhododendron::LocalizedMessage::Vote({
			let action = match vote {
				RhdMessageVote::Prepare(r, h) => Action::Prepare(r as u32, h),
				RhdMessageVote::Commit(r, h) => Action::Commit(r as u32, h),
				RhdMessageVote::AdvanceRound(r) => Action::AdvanceRound(r as u32),
			};
			rhododendron::LocalizedVote {
				vote: vote,
				sender: signer.clone().into(),
				signature: sign_action(action),
			}
		})
	}
}
pub fn sign_message < B : Block + Clone > ( message : RhdMessage < B , B :: Hash > , key : & ed25519 :: Pair , parent_hash : B :: Hash ) -> LocalizedMessage < B > { let signer = key . public ( ) ; let sign_action = | action : Action < B , B :: Hash > | { let to_sign = localized_encode ( parent_hash . clone ( ) , action ) ; LocalizedSignature { signer : signer . clone ( ) , signature : key . sign ( & to_sign ) , } } ; match message { RhdMessage :: Propose ( r , proposal ) => { let header_hash = proposal . hash ( ) ; let action_header = Action :: ProposeHeader ( r as u32 , header_hash . clone ( ) ) ; let action_propose = Action :: Propose ( r as u32 , proposal . clone ( ) ) ; rhododendron :: LocalizedMessage :: Propose ( rhododendron :: LocalizedProposal { round_number : r , proposal , digest : header_hash , sender : signer . clone ( ) . into ( ) , digest_signature : sign_action ( action_header ) , full_signature : sign_action ( action_propose ) , } ) } RhdMessage :: Vote ( vote ) => rhododendron :: LocalizedMessage :: Vote ( { let action = match vote { RhdMessageVote :: Prepare ( r , h ) => Action :: Prepare ( r as u32 , h ) , RhdMessageVote :: Commit ( r , h ) => Action :: Commit ( r as u32 , h ) , RhdMessageVote :: AdvanceRound ( r ) => Action :: AdvanceRound ( r as u32 ) , } ; rhododendron :: LocalizedVote { vote : vote , sender : signer . clone ( ) . into ( ) , signature : sign_action ( action ) , } } ) } }
Sign a BFT message with the given key.
Sign a BFT message with the given key .
message
RhdMessage<B, B::Hash>
key
&ed25519::Pair
parent_hash
B::Hash
message
RhdMessage<B, B::Hash>
key
&ed25519::Pair
parent_hash
B::Hash