-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forrestrie-examples): add example on how to retreieve an executi…
…on layer block and generate proofs for it's receipts
- Loading branch information
Showing
5 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! # Receipts proof given an EL block's `receipt_root`` | ||
//! | ||
//! This example shows how to generate an inclusion proof for a set of receipts of a EL block; | ||
//! | ||
//! | ||
use firehose_client::client::{Chain, FirehoseClient}; | ||
use firehose_protos::ethereum_v2::{self, eth_block::FullReceipt, Block}; | ||
use forrestrie::execution_layer::build_trie_with_proofs; | ||
use reth_primitives::ReceiptWithBloom; | ||
|
||
const EXECUTION_BLOCK_NUMBER: u64 = 20759937; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut eth1_client = FirehoseClient::new(Chain::Ethereum); | ||
let response = eth1_client | ||
.fetch_block(EXECUTION_BLOCK_NUMBER) | ||
.await | ||
.unwrap() | ||
.unwrap(); | ||
let eth1_block: Block = ethereum_v2::Block::try_from(response.into_inner()).unwrap(); | ||
|
||
let receipts: Vec<FullReceipt> = eth1_block | ||
.transaction_traces | ||
.iter() | ||
.filter_map(|trace| { | ||
// Attempt to convert each trace into a FullReceipt | ||
FullReceipt::try_from(trace).ok() // Collect only successful conversions | ||
}) | ||
.collect(); | ||
|
||
let receipts_with_bloom: Vec<ReceiptWithBloom> = receipts | ||
.iter() | ||
.map(|full_receipt| full_receipt.receipt.clone()) | ||
.collect(); | ||
|
||
let mut hb = build_trie_with_proofs(&receipts_with_bloom, &[1, 2, 3]); | ||
|
||
let _root = hb.root(); | ||
} |