Skip to content

Commit

Permalink
chore(firehose-client): add stream ethereum blocks example
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Oct 16, 2024
1 parent 26d14e1 commit a65ce84
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 30 additions & 0 deletions crates/firehose-client/examples/stream_ethereum.rs
Original file line number Diff line number Diff line change
@@ -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<FirehoseEthBlock> = 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);
}
1 change: 0 additions & 1 deletion crates/firehose-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,3 @@ mod tests {
assert_eq!(blocks.len(), TOTAL_SLOTS as usize);
}
}

0 comments on commit a65ce84

Please sign in to comment.