use crate::block::Block;
use diem_crypto::hash::TransactionAccumulatorHasher;
use diem_crypto_derive::{BCSCryptoHash, CryptoHasher};
use diem_types::{
block_info::PivotBlockDecision, epoch_state::EpochState,
proof::AccumulatorExtensionProof, validator_config::ConsensusSignature,
};
use serde::{Deserialize, Serialize};
use std::{
fmt::{Display, Formatter},
ops::Deref,
};
#[derive(Clone, Debug, CryptoHasher, Deserialize, BCSCryptoHash, Serialize)]
pub struct VoteProposal {
accumulator_extension_proof:
AccumulatorExtensionProof<TransactionAccumulatorHasher>,
#[serde(bound(deserialize = "Block: Deserialize<'de>"))]
block: Block,
next_epoch_state: Option<EpochState>,
pivot_decision: Option<PivotBlockDecision>,
}
impl VoteProposal {
pub fn new(
accumulator_extension_proof: AccumulatorExtensionProof<
TransactionAccumulatorHasher,
>,
block: Block, next_epoch_state: Option<EpochState>,
pivot_decision: Option<PivotBlockDecision>,
) -> Self {
Self {
accumulator_extension_proof,
block,
next_epoch_state,
pivot_decision,
}
}
pub fn accumulator_extension_proof(
&self,
) -> &AccumulatorExtensionProof<TransactionAccumulatorHasher> {
&self.accumulator_extension_proof
}
pub fn block(&self) -> &Block { &self.block }
pub fn next_epoch_state(&self) -> Option<&EpochState> {
self.next_epoch_state.as_ref()
}
pub fn pivot_decision(&self) -> &Option<PivotBlockDecision> {
&self.pivot_decision
}
}
impl Display for VoteProposal {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VoteProposal[block: {}]", self.block,)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MaybeSignedVoteProposal {
pub vote_proposal: VoteProposal,
pub signature: Option<ConsensusSignature>,
}
impl Deref for MaybeSignedVoteProposal {
type Target = VoteProposal;
fn deref(&self) -> &VoteProposal { &self.vote_proposal }
}