1pub mod serialization;
5
6use crate::byron::delegation::{
7 ByronDelegation, ByronDelegationSignature, LightWeightDelegationSignature,
8};
9use crate::byron::mpc::{Ssc, SscProof};
10use crate::byron::transaction::{ByronAttributes, ByronTx, ByronTxProof, ByronTxWitness};
11use crate::byron::update::{ByronBlockVersion, ByronSoftwareVersion, ByronUpdate};
12use crate::byron::{Blake2b256, ByronBlockId, ByronPubKey, ByronSignature, ByronSlotId, EpochId};
13
14use cml_chain::byron::StakeholderId;
15
16use std::collections::BTreeMap;
17
18#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
19pub struct BlockHeaderExtraData {
20 pub block_version: ByronBlockVersion,
21 pub software_version: ByronSoftwareVersion,
22 pub byron_attributes: ByronAttributes,
23 pub extra_proof: Blake2b256,
24}
25
26impl BlockHeaderExtraData {
27 pub fn new(
28 block_version: ByronBlockVersion,
29 software_version: ByronSoftwareVersion,
30 byron_attributes: ByronAttributes,
31 extra_proof: Blake2b256,
32 ) -> Self {
33 Self {
34 block_version,
35 software_version,
36 byron_attributes,
37 extra_proof,
38 }
39 }
40}
41
42#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
43pub enum ByronBlock {
44 EpochBoundary(ByronEbBlock),
45 Main(ByronMainBlock),
46}
47
48impl ByronBlock {
49 pub fn new_epoch_boundary(epoch_boundary: ByronEbBlock) -> Self {
50 Self::EpochBoundary(epoch_boundary)
51 }
52
53 pub fn new_main(main: ByronMainBlock) -> Self {
54 Self::Main(main)
55 }
56}
57
58#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
59pub struct ByronBlockBody {
60 pub tx_payload: TxPayload,
61 pub ssc_payload: Ssc,
62 pub dlg_payload: Vec<ByronDelegation>,
63 pub upd_payload: ByronUpdate,
64}
65
66impl ByronBlockBody {
67 pub fn new(
68 tx_payload: TxPayload,
69 ssc_payload: Ssc,
70 dlg_payload: Vec<ByronDelegation>,
71 upd_payload: ByronUpdate,
72 ) -> Self {
73 Self {
74 tx_payload,
75 ssc_payload,
76 dlg_payload,
77 upd_payload,
78 }
79 }
80}
81
82#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
83pub struct ByronBlockConsensusData {
84 pub byron_slot_id: ByronSlotId,
85 pub byron_pub_key: ByronPubKey,
86 pub byron_difficulty: ByronDifficulty,
87 pub byron_block_signature: ByronBlockSignature,
88}
89
90impl ByronBlockConsensusData {
91 pub fn new(
92 byron_slot_id: ByronSlotId,
93 byron_pub_key: ByronPubKey,
94 byron_difficulty: ByronDifficulty,
95 byron_block_signature: ByronBlockSignature,
96 ) -> Self {
97 Self {
98 byron_slot_id,
99 byron_pub_key,
100 byron_difficulty,
101 byron_block_signature,
102 }
103 }
104}
105
106#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
107pub struct ByronBlockHeader {
108 pub protocol_magic: u32,
109 pub prev_block: ByronBlockId,
110 pub body_proof: ByronBodyProof,
111 pub consensus_data: ByronBlockConsensusData,
112 pub extra_data: BlockHeaderExtraData,
113}
114
115impl ByronBlockHeader {
116 pub fn new(
117 protocol_magic: u32,
118 prev_block: ByronBlockId,
119 body_proof: ByronBodyProof,
120 consensus_data: ByronBlockConsensusData,
121 extra_data: BlockHeaderExtraData,
122 ) -> Self {
123 Self {
124 protocol_magic,
125 prev_block,
126 body_proof,
127 consensus_data,
128 extra_data,
129 }
130 }
131}
132
133#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
134pub enum ByronBlockSignature {
135 Signature(ByronBlockSignatureNormal),
136 ProxyLight(ByronBlockSignatureProxyLight),
137 ProxyHeavy(ByronBlockSignatureProxyHeavy),
138}
139
140impl ByronBlockSignature {
141 pub fn new_signature(signature: ByronBlockSignatureNormal) -> Self {
142 Self::Signature(signature)
143 }
144
145 pub fn new_proxy_light(proxy_light: ByronBlockSignatureProxyLight) -> Self {
146 Self::ProxyLight(proxy_light)
147 }
148
149 pub fn new_proxy_heavy(proxy_heavy: ByronBlockSignatureProxyHeavy) -> Self {
150 Self::ProxyHeavy(proxy_heavy)
151 }
152}
153
154#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
155pub struct ByronBlockSignatureNormal {
156 pub signature: ByronSignature,
157}
158
159impl ByronBlockSignatureNormal {
160 pub fn new(signature: ByronSignature) -> Self {
161 Self { signature }
162 }
163}
164
165#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
166pub struct ByronBlockSignatureProxyHeavy {
167 pub signature: ByronDelegationSignature,
168}
169
170impl ByronBlockSignatureProxyHeavy {
171 pub fn new(signature: ByronDelegationSignature) -> Self {
172 Self { signature }
173 }
174}
175
176#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
177pub struct ByronBlockSignatureProxyLight {
178 pub signature: LightWeightDelegationSignature,
179}
180
181impl ByronBlockSignatureProxyLight {
182 pub fn new(signature: LightWeightDelegationSignature) -> Self {
183 Self { signature }
184 }
185}
186
187#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
188pub struct ByronBodyProof {
189 pub tx_proof: ByronTxProof,
190 pub ssc_proof: SscProof,
191 pub dlg_proof: Blake2b256,
192 pub upd_proof: Blake2b256,
193}
194
195impl ByronBodyProof {
196 pub fn new(
197 tx_proof: ByronTxProof,
198 ssc_proof: SscProof,
199 dlg_proof: Blake2b256,
200 upd_proof: Blake2b256,
201 ) -> Self {
202 Self {
203 tx_proof,
204 ssc_proof,
205 dlg_proof,
206 upd_proof,
207 }
208 }
209}
210
211#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
212pub struct ByronDifficulty {
213 pub u64: u64,
214}
215
216impl ByronDifficulty {
217 pub fn new(u64: u64) -> Self {
218 Self { u64 }
219 }
220}
221
222#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
223pub struct ByronEbBlock {
224 pub header: EbbHead,
225 pub body: Vec<StakeholderId>,
226 pub extra: Vec<ByronAttributes>,
227}
228
229impl ByronEbBlock {
230 pub fn new(header: EbbHead, body: Vec<StakeholderId>, extra: Vec<ByronAttributes>) -> Self {
231 Self {
232 header,
233 body,
234 extra,
235 }
236 }
237}
238
239#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
240pub struct ByronMainBlock {
241 pub header: ByronBlockHeader,
242 pub body: ByronBlockBody,
243 pub extra: Vec<ByronAttributes>,
244}
245
246impl ByronMainBlock {
247 pub fn new(
248 header: ByronBlockHeader,
249 body: ByronBlockBody,
250 extra: Vec<ByronAttributes>,
251 ) -> Self {
252 Self {
253 header,
254 body,
255 extra,
256 }
257 }
258}
259
260#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
261pub struct EbbConsensusData {
262 pub epoch_id: EpochId,
263 pub byron_difficulty: ByronDifficulty,
264}
265
266impl EbbConsensusData {
267 pub fn new(epoch_id: EpochId, byron_difficulty: ByronDifficulty) -> Self {
268 Self {
269 epoch_id,
270 byron_difficulty,
271 }
272 }
273}
274
275#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
276pub struct EbbHead {
277 pub protocol_magic: u32,
278 pub prev_block: ByronBlockId,
279 pub body_proof: Blake2b256,
280 pub consensus_data: EbbConsensusData,
281 pub extra_data: Vec<ByronAttributes>,
282}
283
284impl EbbHead {
285 pub fn new(
286 protocol_magic: u32,
287 prev_block: ByronBlockId,
288 body_proof: Blake2b256,
289 consensus_data: EbbConsensusData,
290 extra_data: Vec<ByronAttributes>,
291 ) -> Self {
292 Self {
293 protocol_magic,
294 prev_block,
295 body_proof,
296 consensus_data,
297 extra_data,
298 }
299 }
300}
301
302#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
303pub struct TxAux {
304 pub byron_tx: ByronTx,
305 pub byron_tx_witnesss: Vec<ByronTxWitness>,
306}
307
308impl TxAux {
309 pub fn new(byron_tx: ByronTx, byron_tx_witnesss: Vec<ByronTxWitness>) -> Self {
310 Self {
311 byron_tx,
312 byron_tx_witnesss,
313 }
314 }
315}
316
317pub type TxPayload = Vec<TxAux>;