Skip to content

Commit

Permalink
mv RethDbLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-atreya committed Sep 26, 2024
1 parent b095099 commit 9c84bbf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 18 additions & 0 deletions examples/advanced/examples/reth_db_layer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::path::PathBuf;

/// We use the tower-like layering functionality that has been baked into the alloy-provider to
/// intercept the requests and redirect to the `RethDbProvider`.
pub struct RethDBLayer {
db_path: PathBuf,
}

/// Initialize the `RethDBLayer` with the path to the reth datadir.
impl RethDBLayer {
pub const fn new(db_path: PathBuf) -> Self {
Self { db_path }
}

pub const fn db_path(&self) -> &PathBuf {
&self.db_path
}
}
16 changes: 3 additions & 13 deletions examples/advanced/examples/reth_db_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,8 @@ async fn main() -> Result<()> {
Ok(())
}

/// We use the tower-like layering functionality that has been baked into the alloy-provider to
/// intercept the requests and redirect to the `RethDbProvider`.
struct RethDBLayer {
db_path: PathBuf,
}

/// Initialize the `RethDBLayer` with the path to the reth datadir.
impl RethDBLayer {
const fn new(db_path: PathBuf) -> Self {
Self { db_path }
}
}
mod reth_db_layer;
use reth_db_layer::RethDBLayer;

/// Implement the `ProviderLayer` trait for the `RethDBLayer` struct.
impl<P, T> ProviderLayer<P, T> for RethDBLayer
Expand All @@ -115,7 +105,7 @@ where
type Provider = RethDbProvider<P, T>;

fn layer(&self, inner: P) -> Self::Provider {
RethDbProvider::new(inner, self.db_path.clone())
RethDbProvider::new(inner, self.db_path().clone())
}
}

Expand Down

0 comments on commit 9c84bbf

Please sign in to comment.