-
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.
chore(firehose-client): add stream ethereum blocks example
- Loading branch information
1 parent
26d14e1
commit a65ce84
Showing
2 changed files
with
30 additions
and
1 deletion.
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
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); | ||
} |
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 |
---|---|---|
|
@@ -376,4 +376,3 @@ mod tests { | |
assert_eq!(blocks.len(), TOTAL_SLOTS as usize); | ||
} | ||
} | ||
|