consensus_types/
vote_proposal.rs1use crate::block::Block;
9use diem_crypto::hash::TransactionAccumulatorHasher;
10use diem_crypto_derive::{BCSCryptoHash, CryptoHasher};
11use diem_types::{
12 block_info::PivotBlockDecision, epoch_state::EpochState,
13 proof::AccumulatorExtensionProof, validator_config::ConsensusSignature,
14};
15use serde::{Deserialize, Serialize};
16use std::{
17 fmt::{Display, Formatter},
18 ops::Deref,
19};
20
21#[derive(Clone, Debug, CryptoHasher, Deserialize, BCSCryptoHash, Serialize)]
24pub struct VoteProposal {
25 accumulator_extension_proof:
28 AccumulatorExtensionProof<TransactionAccumulatorHasher>,
29 #[serde(bound(deserialize = "Block: Deserialize<'de>"))]
31 block: Block,
32 next_epoch_state: Option<EpochState>,
34 pivot_decision: Option<PivotBlockDecision>,
36}
37
38impl VoteProposal {
39 pub fn new(
40 accumulator_extension_proof: AccumulatorExtensionProof<
41 TransactionAccumulatorHasher,
42 >,
43 block: Block, next_epoch_state: Option<EpochState>,
44 pivot_decision: Option<PivotBlockDecision>,
45 ) -> Self {
46 Self {
47 accumulator_extension_proof,
48 block,
49 next_epoch_state,
50 pivot_decision,
51 }
52 }
53
54 pub fn accumulator_extension_proof(
55 &self,
56 ) -> &AccumulatorExtensionProof<TransactionAccumulatorHasher> {
57 &self.accumulator_extension_proof
58 }
59
60 pub fn block(&self) -> &Block { &self.block }
61
62 pub fn next_epoch_state(&self) -> Option<&EpochState> {
63 self.next_epoch_state.as_ref()
64 }
65
66 pub fn pivot_decision(&self) -> &Option<PivotBlockDecision> {
67 &self.pivot_decision
68 }
69}
70
71impl Display for VoteProposal {
72 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
73 write!(f, "VoteProposal[block: {}]", self.block,)
74 }
75}
76
77#[derive(Clone, Debug, Deserialize, Serialize)]
79pub struct MaybeSignedVoteProposal {
80 pub vote_proposal: VoteProposal,
82
83 pub signature: Option<ConsensusSignature>,
87}
88
89impl Deref for MaybeSignedVoteProposal {
90 type Target = VoteProposal;
91
92 fn deref(&self) -> &VoteProposal { &self.vote_proposal }
93}