use crate::{
VersionedBlockPayload,
registry::RegistrationsPerTable,
};
use fuel_core_types::{
blockchain::{
header::{
ApplicationHeader,
BlockHeader,
ConsensusHeader,
PartialBlockHeader,
},
primitives::{
BlockId,
Empty,
},
},
fuel_tx::CompressedTransaction,
fuel_types::BlockHeight,
};
pub type RegistryRoot = fuel_core_types::fuel_tx::Bytes32;
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize,
)]
pub struct CompressedBlockHeader {
pub application: ApplicationHeader<Empty>,
pub consensus: ConsensusHeader<Empty>,
pub block_id: BlockId,
pub registry_root: RegistryRoot,
}
impl CompressedBlockHeader {
fn new(header: &BlockHeader, registry_root: RegistryRoot) -> Self {
let ConsensusHeader {
prev_root,
height,
time,
..
} = *header.consensus();
CompressedBlockHeader {
application: ApplicationHeader {
da_height: header.da_height(),
consensus_parameters_version: header.consensus_parameters_version(),
state_transition_bytecode_version: header
.state_transition_bytecode_version(),
generated: Empty {},
},
consensus: ConsensusHeader {
prev_root,
height,
time,
generated: Empty {},
},
block_id: header.id(),
registry_root,
}
}
}
impl From<&CompressedBlockHeader> for PartialBlockHeader {
fn from(value: &CompressedBlockHeader) -> Self {
PartialBlockHeader {
application: value.application,
consensus: value.consensus,
}
}
}
#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CompressedBlockPayloadV1 {
pub registrations: RegistrationsPerTable,
pub header: CompressedBlockHeader,
pub transactions: Vec<CompressedTransaction>,
}
impl VersionedBlockPayload for CompressedBlockPayloadV1 {
fn height(&self) -> &BlockHeight {
&self.header.consensus.height
}
fn consensus_header(&self) -> &ConsensusHeader<Empty> {
&self.header.consensus
}
fn application_header(&self) -> &ApplicationHeader<Empty> {
&self.header.application
}
fn registrations(&self) -> &RegistrationsPerTable {
&self.registrations
}
fn transactions(&self) -> Vec<CompressedTransaction> {
self.transactions.clone()
}
fn partial_block_header(&self) -> PartialBlockHeader {
PartialBlockHeader::from(&self.header)
}
}
impl CompressedBlockPayloadV1 {
#[allow(unused)]
pub(crate) fn new(
header: &BlockHeader,
registrations: RegistrationsPerTable,
transactions: Vec<CompressedTransaction>,
registry_root: RegistryRoot,
) -> Self {
Self {
header: CompressedBlockHeader::new(header, registry_root),
registrations,
transactions,
}
}
}