diem_types/
block_metadata.rs1use crate::{
9 account_address::AccountAddress, account_config::diem_root_address,
10 event::EventKey,
11};
12use diem_crypto::HashValue;
13use serde::{Deserialize, Serialize};
14
15#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
29pub struct BlockMetadata {
30 id: HashValue,
31 round: u64,
32 timestamp_usecs: u64,
33 previous_block_votes: Vec<AccountAddress>,
35 proposer: AccountAddress,
36}
37
38impl BlockMetadata {
39 pub fn new(
40 id: HashValue, round: u64, timestamp_usecs: u64,
41 previous_block_votes: Vec<AccountAddress>, proposer: AccountAddress,
42 ) -> Self {
43 Self {
44 id,
45 round,
46 timestamp_usecs,
47 previous_block_votes,
48 proposer,
49 }
50 }
51
52 pub fn id(&self) -> HashValue { self.id }
53
54 pub fn into_inner(self) -> (u64, u64, Vec<AccountAddress>, AccountAddress) {
55 (
56 self.round,
57 self.timestamp_usecs,
58 self.previous_block_votes.clone(),
59 self.proposer,
60 )
61 }
62
63 pub fn timestamp_usec(&self) -> u64 { self.timestamp_usecs }
64
65 pub fn proposer(&self) -> AccountAddress { self.proposer }
66}
67
68pub fn new_block_event_key() -> EventKey {
69 EventKey::new_from_address(&diem_root_address(), 17)
70}
71
72#[derive(Clone, Deserialize, Serialize)]
73pub struct NewBlockEvent {
74 round: u64,
75 proposer: AccountAddress,
76 votes: Vec<AccountAddress>,
77 timestamp: u64,
78}
79
80impl NewBlockEvent {
81 pub fn new(
82 round: u64, proposer: AccountAddress, votes: Vec<AccountAddress>,
83 timestamp: u64,
84 ) -> Self {
85 Self {
86 round,
87 proposer,
88 votes,
89 timestamp,
90 }
91 }
92
93 pub fn round(&self) -> u64 { self.round }
94
95 pub fn proposer(&self) -> AccountAddress { self.proposer }
96
97 pub fn votes(&self) -> Vec<AccountAddress> { self.votes.clone() }
98}