Skip to main content

dpp/block/extended_block_info/v0/
mod.rs

1use crate::block::block_info::BlockInfo;
2#[cfg(feature = "json-conversion")]
3use crate::serialization::json_safe_fields;
4
5use bincode::{Decode, Encode};
6use serde::{Deserialize, Serialize};
7
8/// Extended Block information
9#[cfg_attr(feature = "json-conversion", json_safe_fields)]
10#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct ExtendedBlockInfoV0 {
13    /// Basic block info
14    pub basic_info: BlockInfo,
15    /// App hash
16    pub app_hash: [u8; 32],
17    /// Quorum Hash
18    pub quorum_hash: [u8; 32],
19    /// The block id hash
20    pub block_id_hash: [u8; 32],
21    /// The proposer pro_tx_hash
22    pub proposer_pro_tx_hash: [u8; 32],
23    /// Signature
24    // serde has no built-in `Serialize`/`Deserialize` for `[u8; N]` when N > 32,
25    // so this 96-byte field needs an explicit byte serializer. `json_safe_fields`
26    // injects one for byte fields, but only under `json-conversion`; this struct
27    // derives serde unconditionally (no feature gate), so the annotation is written
28    // out here to keep it compiling whenever `json-conversion` is off.
29    #[serde(with = "crate::serialization::serde_bytes")]
30    pub signature: [u8; 96],
31    /// Round
32    pub round: u32,
33}
34
35/// Trait for getting values from `ExtendedBlockInfoV0`
36pub trait ExtendedBlockInfoV0Getters {
37    /// Returns a reference to the basic block info.
38    fn basic_info(&self) -> &BlockInfo;
39
40    /// Returns a mutable reference to the basic block info.
41    fn basic_info_mut(&mut self) -> &mut BlockInfo;
42
43    /// Returns an owned copy of the basic block info.
44    fn basic_info_owned(self) -> BlockInfo;
45
46    /// Returns the app hash.
47    fn app_hash(&self) -> &[u8; 32];
48
49    /// Returns the quorum hash.
50    fn quorum_hash(&self) -> &[u8; 32];
51    /// Proposer pro tx hash.
52    fn proposer_pro_tx_hash(&self) -> &[u8; 32];
53    /// The block id hash
54    fn block_id_hash(&self) -> &[u8; 32];
55
56    /// Returns the signature.
57    fn signature(&self) -> &[u8; 96];
58
59    /// Returns the round.
60    fn round(&self) -> u32;
61}
62
63/// Trait for setting values in `ExtendedBlockInfoV0`
64pub trait ExtendedBlockInfoV0Setters {
65    /// Sets the basic block info.
66    fn set_basic_info(&mut self, info: BlockInfo);
67
68    /// Sets the app hash.
69    fn set_app_hash(&mut self, hash: [u8; 32]);
70
71    /// Sets the quorum hash.
72    fn set_quorum_hash(&mut self, hash: [u8; 32]);
73
74    /// Sets the signature.
75    fn set_signature(&mut self, signature: [u8; 96]);
76
77    /// Sets the round.
78    fn set_round(&mut self, round: u32);
79}
80
81impl ExtendedBlockInfoV0Getters for ExtendedBlockInfoV0 {
82    fn basic_info(&self) -> &BlockInfo {
83        &self.basic_info
84    }
85
86    fn basic_info_mut(&mut self) -> &mut BlockInfo {
87        &mut self.basic_info
88    }
89
90    fn basic_info_owned(self) -> BlockInfo {
91        self.basic_info
92    }
93
94    fn app_hash(&self) -> &[u8; 32] {
95        &self.app_hash
96    }
97
98    fn quorum_hash(&self) -> &[u8; 32] {
99        &self.quorum_hash
100    }
101
102    fn proposer_pro_tx_hash(&self) -> &[u8; 32] {
103        &self.proposer_pro_tx_hash
104    }
105
106    fn block_id_hash(&self) -> &[u8; 32] {
107        &self.block_id_hash
108    }
109
110    fn signature(&self) -> &[u8; 96] {
111        &self.signature
112    }
113
114    fn round(&self) -> u32 {
115        self.round
116    }
117}
118
119impl ExtendedBlockInfoV0Setters for ExtendedBlockInfoV0 {
120    fn set_basic_info(&mut self, info: BlockInfo) {
121        self.basic_info = info;
122    }
123
124    fn set_app_hash(&mut self, hash: [u8; 32]) {
125        self.app_hash = hash;
126    }
127
128    fn set_quorum_hash(&mut self, hash: [u8; 32]) {
129        self.quorum_hash = hash;
130    }
131
132    fn set_signature(&mut self, signature: [u8; 96]) {
133        self.signature = signature;
134    }
135
136    fn set_round(&mut self, round: u32) {
137        self.round = round;
138    }
139}