diff --git a/crates/firehose-client/examples/stream_ethereum.rs b/crates/firehose-client/examples/stream_ethereum.rs new file mode 100644 index 00000000..a0370d73 --- /dev/null +++ b/crates/firehose-client/examples/stream_ethereum.rs @@ -0,0 +1,30 @@ +//! # Example: Stream Ethereum Blocks +//! +//! This example demonstrates how to stream Ethereum blocks using the Firehose client. +use firehose_client::{Chain, FirehoseClient}; +use futures::StreamExt; +use sf_protos::ethereum::r#type::v2::Block as FirehoseEthBlock; + +#[tokio::main] +async fn main() { + // Testing this so far without proper benchmarking, the time taken to fetch the blocks + // grows linearly with the number of TOTAL_BLOCKS requested, to around 20 minutes for 8192 blocks! + const TOTAL_BLOCKS: u64 = 100; + const START_BLOCK: u64 = 19581798; + + let mut client = FirehoseClient::new(Chain::Ethereum); + let stream = client + .stream_ethereum_with_retry(START_BLOCK, TOTAL_BLOCKS) + .await; + + tokio::pin!(stream); + + let mut blocks: Vec = Vec::with_capacity(TOTAL_BLOCKS as usize); + + while let Some(block) = stream.next().await { + blocks.push(block); + } + + // For now, just using this to signal that the test has completed + assert_eq!(blocks.len(), TOTAL_BLOCKS as usize); +} diff --git a/crates/firehose-client/src/lib.rs b/crates/firehose-client/src/lib.rs index 94ff32a7..5147c35a 100644 --- a/crates/firehose-client/src/lib.rs +++ b/crates/firehose-client/src/lib.rs @@ -376,4 +376,3 @@ mod tests { assert_eq!(blocks.len(), TOTAL_SLOTS as usize); } } - \ No newline at end of file