Skip to content

Commit

Permalink
refactor(sf-protos): create beacon module
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Oct 21, 2024
1 parent e0bd5af commit 778a3ad
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/firehose-client/examples/fetch_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use firehose_client::client::{Chain, FirehoseClient};
use sf_protos::{
beacon::r#type::v1::{block::Body, Block as FirehoseBeaconBlock},
beacon_v1::{block::Body, Block as FirehoseBeaconBlock},
ethereum_v2::Block as FirehoseEthBlock,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/firehose-client/examples/stream_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use firehose_client::client::{Chain, FirehoseClient};
use futures::StreamExt;
use sf_protos::beacon::r#type::v1::Block as FirehoseBeaconBlock;
use sf_protos::beacon_v1::Block as FirehoseBeaconBlock;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion crates/firehose-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::error::ClientError;
use dotenvy::{dotenv, var};
use sf_protos::firehose::v2::SingleBlockResponse;
use sf_protos::{
beacon::r#type::v1::Block as FirehoseBeaconBlock,
beacon_v1::Block as FirehoseBeaconBlock,
ethereum_v2::Block as FirehoseEthBlock,
firehose::v2::{
fetch_client::FetchClient,
Expand Down
2 changes: 1 addition & 1 deletion crates/forrestrie/examples/fetch_and_verify_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! ```
//!
use firehose_client::client::{Chain, FirehoseClient};
use sf_protos::beacon::r#type::v1::Block as FirehoseBeaconBlock;
use sf_protos::beacon_v1::Block as FirehoseBeaconBlock;
use tree_hash::TreeHash;
use types::{BeaconBlock, MainnetEthSpec};

Expand Down
6 changes: 3 additions & 3 deletions crates/forrestrie/examples/single_execution_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use forrestrie::{
};
use futures::StreamExt;
use merkle_proof::verify_merkle_proof;
use sf_protos::{beacon, ethereum_v2};
use sf_protos::{beacon_v1, ethereum_v2};
use tree_hash::TreeHash;
use types::{
historical_summary::HistoricalSummary, light_client_update::EXECUTION_PAYLOAD_INDEX,
Expand Down Expand Up @@ -82,7 +82,7 @@ async fn main() {
.await
.unwrap()
.unwrap();
let beacon_block = beacon::r#type::v1::Block::try_from(response.into_inner()).unwrap();
let beacon_block = beacon_v1::Block::try_from(response.into_inner()).unwrap();
assert_eq!(beacon_block.slot, BEACON_SLOT_NUMBER);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -108,7 +108,7 @@ async fn main() {
lighthouse_beacon_block_root.as_bytes(),
beacon_block.root.as_slice()
);
let Some(beacon::r#type::v1::block::Body::Deneb(body)) = beacon_block.body else {
let Some(beacon_v1::block::Body::Deneb(body)) = beacon_block.body else {
panic!("Unsupported block version!");
};
let block_body: BeaconBlockBodyDeneb<MainnetEthSpec> = body.try_into().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/forrestrie/examples/verify_block_inclusion_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use forrestrie::beacon_block::{
HistoricalDataProofs, BEACON_BLOCK_BODY_PROOF_DEPTH, EXECUTION_PAYLOAD_FIELD_INDEX,
};
use merkle_proof::verify_merkle_proof;
use sf_protos::beacon::r#type::v1::Block as FirehoseBeaconBlock;
use sf_protos::beacon_v1::Block as FirehoseBeaconBlock;
use tree_hash::TreeHash;
use types::{
light_client_update::EXECUTION_PAYLOAD_INDEX, BeaconBlock, BeaconBlockBody, MainnetEthSpec,
Expand Down
4 changes: 2 additions & 2 deletions crates/forrestrie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub mod beacon_state;

pub struct BlockRoot(pub H256);

impl TryFrom<sf_protos::beacon::r#type::v1::Block> for BlockRoot {
impl TryFrom<sf_protos::beacon_v1::Block> for BlockRoot {
type Error = ProtosError;

fn try_from(beacon_block: sf_protos::beacon::r#type::v1::Block) -> Result<Self, Self::Error> {
fn try_from(beacon_block: sf_protos::beacon_v1::Block) -> Result<Self, Self::Error> {
let lighthouse_beacon_block = BeaconBlock::<MainnetEthSpec>::try_from(beacon_block)?;
Ok(Self(lighthouse_beacon_block.canonical_root()))
}
Expand Down
Loading

0 comments on commit 778a3ad

Please sign in to comment.