Skip to content

Commit

Permalink
docs(client): clean up rust doc landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
suchapalaver committed Nov 9, 2024
1 parent fc2d453 commit d26efcf
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 16 deletions.
7 changes: 6 additions & 1 deletion crates/firehose-client/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Firehose Ethereum Rust Client
# Firehose Rust Client

Extract blocks from [StreamingFast Firehose](https://firehose.streamingfast.io/)
programatically in Rust.

## gRPC Endpoints

Expand All @@ -11,6 +14,8 @@ To do this, place a `.env` file in the root of `veemon`. See the
`.env.example` file in the root of this repository for what you'll need,
depending on your requirements.

See the `.env.example` file in the root the `veemon` repository.

## firehose-ethereum and firehose-beacon gRPC

### proto files
Expand Down
2 changes: 1 addition & 1 deletion crates/firehose-client/examples/fetch_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Demonstrates how to fetch a single block from Beacon Firehose, using the `Fetch` API.
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock;
use forrestrie::beacon_v1::{block::Body, Block as BeaconBlock};

Expand Down
2 changes: 1 addition & 1 deletion crates/firehose-client/examples/fetch_ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Demonstrates how to fetch a single block from Ethereum firehose.
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock as Block;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion crates/firehose-client/examples/stream_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Demonstrates how to stream a range of blocks from Firehose Beacon
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use forrestrie::beacon_v1::Block as FirehoseBeaconBlock;
use futures::StreamExt;

Expand Down
4 changes: 2 additions & 2 deletions crates/firehose-client/examples/stream_ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Example: Stream Ethereum Blocks
//!
//! This example demonstrates how to stream Ethereum blocks using the Firehose client.
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock as Block;
use futures::StreamExt;

Expand All @@ -14,7 +14,7 @@ async fn main() {

let mut client = FirehoseClient::new(Chain::Ethereum);
let mut stream = client
.stream_ethereum_with_retry(START_BLOCK, TOTAL_BLOCKS)
.stream_blocks(START_BLOCK, TOTAL_BLOCKS)
.await
.unwrap();

Expand Down
4 changes: 3 additions & 1 deletion crates/firehose-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tonic::{
};
use tracing::{error, info, trace};

/// Work with the fetch and streaming APIs supported by [StreamingFast Firehose](https://firehose.streamingfast.io/).
pub struct FirehoseClient {
chain: Chain,
fetch_client: Option<FetchClient<Channel>>,
Expand Down Expand Up @@ -127,7 +128,7 @@ impl FirehoseClient {
Ok(ReceiverStream::new(rx))
}

pub async fn stream_ethereum_with_retry(
pub async fn stream_blocks(
&mut self,
start: u64,
total: u64,
Expand Down Expand Up @@ -252,6 +253,7 @@ fn insert_api_key_if_provided<T>(request: &mut tonic::Request<T>, chain: Chain)
}
}

/// Extract blocks with [`FirehoseClient`] from an extendable union of chain variants.
#[derive(Clone, Copy, Debug)]
pub enum Chain {
Ethereum,
Expand Down
58 changes: 55 additions & 3 deletions crates/firehose-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
pub mod client;
pub mod error;
pub mod tls;
//! # Rust Firehose Client
//!
//! Rust implementation of a client for the [StreamingFast Firehose](https://firehose.streamingfast.io/)
//! gRPC Fetch `Block` and Stream `Block`s APIs.
//!
//! ## Example Fetching an Ethereum Block
//!
//! ```no_run
//! # use firehose_client::{Chain, FirehoseClient};
//! # use firehose_protos::EthBlock as Block;
//! # #[tokio::main]
//! # async fn main() -> Result<(), firehose_protos::ProtosError> {
//! let mut client = FirehoseClient::new(Chain::Ethereum);
//!
//! if let Some(response) = client.fetch_block(20672593).await.unwrap().ok() {
//! let block = Block::try_from(response.into_inner())?;
//! assert_eq!(block.number, 20672593);
//! assert_eq!(
//! format!("0x{}", hex::encode(block.hash)).as_str(),
//! "0xea48ba1c8e38ea586239e9c5ec62949ddd79404c6006c099bb02a8b22ddd18e4"
//! );
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Example Streaming Ethereum Blocks
//!
//! ```no_run
//! # use firehose_client::{Chain, FirehoseClient};
//! # use futures::StreamExt;
//! # #[tokio::main]
//! # async fn main() -> Result<(), firehose_protos::ProtosError> {
//! const TOTAL_BLOCKS: u64 = 8192;
//! const START_BLOCK: u64 = 19581798;
//!
//! let mut client = FirehoseClient::new(Chain::Ethereum);
//! let mut stream = client
//! .stream_blocks(START_BLOCK, TOTAL_BLOCKS)
//! .await
//! .unwrap();
//!
//! while let Some(block) = stream.next().await {
//! // Do Something with the extracted stream of blocks.
//! }
//! # Ok(())
//! # }
//! ```
//!
mod client;
mod error;
mod tls;

pub use crate::client::{Chain, FirehoseClient};
2 changes: 1 addition & 1 deletion crates/firehose-protos-examples/examples/receipt_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! compare it to the receipts root in the block header.
//!
use alloy_primitives::FixedBytes;
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock as Block;

const BLOCK_NUMBER: u64 = 20672593;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! assert_eq!(block_root, block_header_root);
//! ```
//!
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use forrestrie::beacon_v1::Block as FirehoseBeaconBlock;
use tree_hash::TreeHash;
use types::{BeaconBlock, MainnetEthSpec};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! comparison until the correct Beacon slot is found.
//!
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use forrestrie::{
beacon_state::ETHEREUM_BEACON_DENEB_OFFSET,
beacon_v1::{block, Block as FirehoseBeaconBlock},
Expand Down
2 changes: 1 addition & 1 deletion crates/forrestrie-examples/examples/receipts_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! 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_client::{Chain, FirehoseClient};
use firehose_protos::{EthBlock as Block, FullReceipt};
use forrestrie::execution_layer::{build_trie_with_proofs, TargetLeaves};
use reth_primitives::ReceiptWithBloom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! for the era.
//!
use ethportal_api::Header;
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use firehose_protos::EthBlock;
use forrestrie::{
beacon_block::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! let proof = body.compute_merkle_proof(EXECUTION_PAYLOAD_INDEX).unwrap();
//! ```
//!
use firehose_client::client::{Chain, FirehoseClient};
use firehose_client::{Chain, FirehoseClient};
use forrestrie::{
beacon_block::{
HistoricalDataProofs, BEACON_BLOCK_BODY_PROOF_DEPTH, EXECUTION_PAYLOAD_FIELD_INDEX,
Expand Down

0 comments on commit d26efcf

Please sign in to comment.