Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

implement conversion from firehose to Lighthouse Beacon block #18

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ pub mod beacon {
gas_limit,
gas_used,
timestamp: timestamp
.map(|ts| ts.seconds as u64 * 1_000_000_000 + ts.nanos as u64)
.unwrap_or_default(),
.as_ref()
.ok_or(ProtosError::BlockConversionError)?
.seconds as u64,
extra_data: extra_data.into(),
base_fee_per_gas: U256::from_big_endian(base_fee_per_gas.as_slice()),
block_hash: ExecutionBlockHash(H256::from_slice(block_hash.as_slice())),
Expand Down Expand Up @@ -682,6 +683,46 @@ pub mod beacon {
Ok(beacon_block_body)
}
}

impl TryFrom<crate::beacon::r#type::v1::block::Body>
for types::BeaconBlockBodyDeneb<MainnetEthSpec>
{
type Error = ProtosError;

fn try_from(
body: crate::beacon::r#type::v1::block::Body,
) -> Result<Self, Self::Error> {
match body {
crate::beacon::r#type::v1::block::Body::Deneb(deneb) => {
Ok(deneb.try_into()?)
}
_ => panic!("Invalid body type"),
}
}
}

impl TryFrom<Block> for types::BeaconBlock<MainnetEthSpec> {
type Error = ProtosError;

fn try_from(
Block {
slot,
proposer_index,
parent_root,
state_root,
body,
..
}: Block,
) -> Result<Self, Self::Error> {
Ok(Self::Deneb(types::BeaconBlockDeneb {
slot: slot.into(),
proposer_index,
parent_root: H256::from_slice(parent_root.as_slice()),
state_root: H256::from_slice(state_root.as_slice()),
body: body.ok_or(ProtosError::BlockConversionError)?.try_into()?,
}))
}
}
}
}
}
Expand Down
Loading