dpp/block/extended_block_info/v0/
mod.rs1use 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#[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 pub basic_info: BlockInfo,
15 pub app_hash: [u8; 32],
17 pub quorum_hash: [u8; 32],
19 pub block_id_hash: [u8; 32],
21 pub proposer_pro_tx_hash: [u8; 32],
23 #[serde(with = "signature_serializer")]
25 pub signature: [u8; 96],
26 pub round: u32,
28}
29
30pub trait ExtendedBlockInfoV0Getters {
32 fn basic_info(&self) -> &BlockInfo;
34
35 fn basic_info_mut(&mut self) -> &mut BlockInfo;
37
38 fn basic_info_owned(self) -> BlockInfo;
40
41 fn app_hash(&self) -> &[u8; 32];
43
44 fn quorum_hash(&self) -> &[u8; 32];
46 fn proposer_pro_tx_hash(&self) -> &[u8; 32];
48 fn block_id_hash(&self) -> &[u8; 32];
50
51 fn signature(&self) -> &[u8; 96];
53
54 fn round(&self) -> u32;
56}
57
58pub trait ExtendedBlockInfoV0Setters {
60 fn set_basic_info(&mut self, info: BlockInfo);
62
63 fn set_app_hash(&mut self, hash: [u8; 32]);
65
66 fn set_quorum_hash(&mut self, hash: [u8; 32]);
68
69 fn set_signature(&mut self, signature: [u8; 96]);
71
72 fn set_round(&mut self, round: u32);
74}
75
76impl ExtendedBlockInfoV0Getters for ExtendedBlockInfoV0 {
77 fn basic_info(&self) -> &BlockInfo {
78 &self.basic_info
79 }
80
81 fn basic_info_mut(&mut self) -> &mut BlockInfo {
82 &mut self.basic_info
83 }
84
85 fn basic_info_owned(self) -> BlockInfo {
86 self.basic_info
87 }
88
89 fn app_hash(&self) -> &[u8; 32] {
90 &self.app_hash
91 }
92
93 fn quorum_hash(&self) -> &[u8; 32] {
94 &self.quorum_hash
95 }
96
97 fn proposer_pro_tx_hash(&self) -> &[u8; 32] {
98 &self.proposer_pro_tx_hash
99 }
100
101 fn block_id_hash(&self) -> &[u8; 32] {
102 &self.block_id_hash
103 }
104
105 fn signature(&self) -> &[u8; 96] {
106 &self.signature
107 }
108
109 fn round(&self) -> u32 {
110 self.round
111 }
112}
113
114impl ExtendedBlockInfoV0Setters for ExtendedBlockInfoV0 {
115 fn set_basic_info(&mut self, info: BlockInfo) {
116 self.basic_info = info;
117 }
118
119 fn set_app_hash(&mut self, hash: [u8; 32]) {
120 self.app_hash = hash;
121 }
122
123 fn set_quorum_hash(&mut self, hash: [u8; 32]) {
124 self.quorum_hash = hash;
125 }
126
127 fn set_signature(&mut self, signature: [u8; 96]) {
128 self.signature = signature;
129 }
130
131 fn set_round(&mut self, round: u32) {
132 self.round = round;
133 }
134}
135
136mod signature_serializer {
137 use super::*;
138 use serde::de::Error;
139 use serde::{Deserializer, Serializer};
140
141 pub fn serialize<S>(signature: &[u8; 96], serializer: S) -> Result<S::Ok, S::Error>
142 where
143 S: Serializer,
144 {
145 serializer.serialize_bytes(signature)
146 }
147
148 pub fn deserialize<'de, D>(deserializer: D) -> Result<[u8; 96], D::Error>
149 where
150 D: Deserializer<'de>,
151 {
152 let buf: Vec<u8> = Deserialize::deserialize(deserializer)?;
153 if buf.len() != 96 {
154 return Err(Error::invalid_length(buf.len(), &"array of length 96"));
155 }
156 let mut arr = [0u8; 96];
157 arr.copy_from_slice(&buf);
158 Ok(arr)
159 }
160}