1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::common::Round;
use anyhow::Context;
use diem_types::{ledger_info::LedgerInfoWithSignatures, validator_verifier::ValidatorVerifier};
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter};
#[derive(Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct CommitDecision {
ledger_info: LedgerInfoWithSignatures,
}
impl Debug for CommitDecision {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{}", self)
}
}
impl Display for CommitDecision {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "CommitDecision: [{}]", self.ledger_info)
}
}
impl CommitDecision {
pub fn new(ledger_info: LedgerInfoWithSignatures) -> Self {
Self { ledger_info }
}
pub fn round(&self) -> Round {
self.ledger_info.ledger_info().round()
}
pub fn epoch(&self) -> u64 {
self.ledger_info.ledger_info().epoch()
}
pub fn ledger_info(&self) -> &LedgerInfoWithSignatures {
&self.ledger_info
}
pub fn verify(&self, validator: &ValidatorVerifier) -> anyhow::Result<()> {
self.ledger_info
.verify_signatures(validator)
.context("Failed to verify Commit Decision")
}
}