1use serde::{Deserialize, Serialize};
4use super::primitives::*;
5use super::transaction::Transaction;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[serde(untagged)]
10pub enum Block {
11 EBB(BlockEBB),
13 BFT(BlockBFT),
15 Praos(BlockPraos),
17}
18
19impl Block {
20 pub fn slot(&self) -> Slot {
22 match self {
23 Block::EBB(b) => b.slot,
24 Block::BFT(b) => b.slot,
25 Block::Praos(b) => b.slot,
26 }
27 }
28
29 pub fn id(&self) -> &str {
31 match self {
32 Block::EBB(b) => &b.id,
33 Block::BFT(b) => &b.id,
34 Block::Praos(b) => &b.id,
35 }
36 }
37
38 pub fn height(&self) -> BlockHeight {
40 match self {
41 Block::EBB(b) => b.height,
42 Block::BFT(b) => b.height,
43 Block::Praos(b) => b.height,
44 }
45 }
46
47 pub fn ancestor(&self) -> &str {
49 match self {
50 Block::EBB(b) => &b.ancestor,
51 Block::BFT(b) => &b.ancestor,
52 Block::Praos(b) => &b.ancestor,
53 }
54 }
55
56 pub fn is_ebb(&self) -> bool {
58 matches!(self, Block::EBB(_))
59 }
60
61 pub fn is_bft(&self) -> bool {
63 matches!(self, Block::BFT(_))
64 }
65
66 pub fn is_praos(&self) -> bool {
68 matches!(self, Block::Praos(_))
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74#[serde(rename_all = "camelCase")]
75pub struct BlockEBB {
76 #[serde(rename = "type")]
78 pub block_type: String,
79 pub era: String,
81 pub id: DigestBlake2b256,
83 pub ancestor: DigestBlake2b256,
85 pub slot: Slot,
87 pub height: BlockHeight,
89}
90
91#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct BlockBFT {
95 #[serde(rename = "type")]
97 pub block_type: String,
98 pub era: String,
100 pub id: DigestBlake2b256,
102 pub ancestor: DigestBlake2b256,
104 pub slot: Slot,
106 pub height: BlockHeight,
108 pub size: BlockSize,
110 pub protocol: ProtocolVersionByron,
112 pub issuer: BlockIssuerByron,
114 #[serde(default)]
116 pub transactions: Vec<Transaction>,
117}
118
119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct BlockPraos {
123 #[serde(rename = "type")]
125 pub block_type: String,
126 pub era: String,
128 pub id: DigestBlake2b256,
130 pub ancestor: DigestBlake2b256,
132 pub slot: Slot,
134 pub height: BlockHeight,
136 pub size: BlockSize,
138 pub protocol: ProtocolVersionPraos,
140 pub issuer: BlockIssuerPraos,
142 #[serde(default)]
144 pub transactions: Vec<Transaction>,
145}
146
147#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct BlockSize {
151 pub bytes: NumberOfBytes,
153}
154
155#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
157#[serde(rename_all = "camelCase")]
158pub struct ProtocolVersionByron {
159 #[serde(default)]
161 pub software: Option<SoftwareVersion>,
162 #[serde(default)]
164 pub update: Option<serde_json::Value>,
165}
166
167#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
169#[serde(rename_all = "camelCase")]
170pub struct SoftwareVersion {
171 pub app_name: String,
173 pub number: u32,
175}
176
177#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
179#[serde(rename_all = "camelCase")]
180pub struct ProtocolVersionPraos {
181 pub major: u32,
183 pub minor: u32,
185 #[serde(default)]
187 pub patch: Option<u32>,
188}
189
190#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
192#[serde(rename_all = "camelCase")]
193pub struct BlockIssuerByron {
194 pub verification_key: VerificationKey,
196}
197
198#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
200#[serde(rename_all = "camelCase")]
201pub struct BlockIssuerPraos {
202 pub verification_key: VerificationKeyHash,
204 pub vrf_verification_key: VrfVerificationKey,
206 #[serde(default)]
208 pub leader_value: Option<CertifiedVrf>,
209 #[serde(default)]
211 pub operational_certificate: Option<OperationalCertificate>,
212}
213
214#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
216#[serde(rename_all = "camelCase")]
217pub struct CertifiedVrf {
218 pub output: String,
220 pub proof: String,
222}
223
224#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
226#[serde(rename_all = "camelCase")]
227pub struct OperationalCertificate {
228 pub kes_verification_key: KesVerificationKey,
230 pub count: u64,
232 #[serde(default)]
234 pub kes_period: Option<u64>,
235 #[serde(default)]
237 pub issue_number: Option<u64>,
238}