Skip to content

Commit

Permalink
refactor(protos-examples): clean up rust doc landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Nov 10, 2024
1 parent 39e8fe7 commit 6103a38
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 0 additions & 3 deletions crates/firehose-protos-examples/examples/receipt_root.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! This example demonstrates how to calculate the receipts root of a block and
//! compare it to the receipts root in the block header.
//!
use alloy_primitives::FixedBytes;
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock as Block;
Expand Down
44 changes: 44 additions & 0 deletions crates/firehose-protos-examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! # Firehose Protos Examples
//!
//! Examples that use methods implemented on the Rust-compiled Firehose
//! protobuffer types from [Firehose Protos](../firehose_protos/index.html).
//!
//! ## Running Examples
//!
//! To run the examples, you need access to a Firehose provider for each chain from which you want
//! to extract data - an endpoint and an API key (if the latter is required).
//!
//! Add your endpoint and API key to a `.env` file in the root of the repository. See `.env.examples` for
//! a configuration template.
//!
//! To run individual examples, use the following command:
//!
//! ```bash
//! cargo run -p firehose-protos-examples --example <example_name>
//! ```
//!
//! ## Calculate a Block Receipts Root and Compare it to the Receipts Root in the Block Header
//!
//! ### Example name: `receipt_root`
//!
//! ```no_run
//! //! examples/receipt_root.rs
//!
//! # use alloy_primitives::FixedBytes;
//! # use firehose_client::{Chain, FirehoseClient};
//! # use firehose_protos::EthBlock as Block;
//! # const BLOCK_NUMBER: u64 = 20672593;
//! # #[tokio::main]
//! # async fn main() {
//! # let mut client = FirehoseClient::new(Chain::Ethereum);
//! # let response = client.fetch_block(BLOCK_NUMBER).await.unwrap().unwrap();
//! # let block = Block::try_from(response.into_inner()).unwrap();
//! let calculated_receipts_root = block.calculate_receipt_root().unwrap();
//! // Compare the calculated receipts root to the receipts root in the block header
//! assert_eq!(
//! FixedBytes::<32>::from_slice(block.header.as_ref().unwrap().receipt_root.as_slice()),
//! calculated_receipts_root
//! );
//! # }
//! ```
//!
5 changes: 3 additions & 2 deletions crates/forrestrie-examples/examples/receipts_proof.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! # Receipts proof given an EL block's `receipt_root``
//! # Receipts proof given an EL block's `receipt_root`
//!
//! This example shows how to generate an inclusion proof for a set of receipts of an EL block.
//!
//! This example shows how to generate an inclusion proof for a set of receipts of a EL block;
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::{EthBlock as Block, FullReceipt};
Expand Down

0 comments on commit 6103a38

Please sign in to comment.