Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): wrapped provider #171

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,13 @@ serde = "1.0"
serde_json = "1.0"

[patch.crates-io]
# alloy = { git = "https://github.com/alloy-rs/alloy", rev = "65dfbe" }
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "d113d6e" }
alloy = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-serde = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", branch = "dani/rm-T-transport" }

foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", branch = "dani/alloy-0.10" }
10 changes: 5 additions & 5 deletions examples/advanced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ revm-primitives.workspace = true
revm.workspace = true

# reth
reth-db = { git = "https://github.com/paradigmxyz/reth", package = "reth-db", rev = "c0a8a7b" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", package = "reth-provider", rev = "c0a8a7b" }
reth-node-types = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-types", rev = "c0a8a7b" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", package = "reth-chainspec", rev = "c0a8a7b" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-ethereum", rev = "c0a8a7b" }
# reth-db = { git = "https://github.com/paradigmxyz/reth", package = "reth-db", rev = "c0a8a7b" }
# reth-provider = { git = "https://github.com/paradigmxyz/reth", package = "reth-provider", rev = "c0a8a7b" }
# reth-node-types = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-types", rev = "c0a8a7b" }
# reth-chainspec = { git = "https://github.com/paradigmxyz/reth", package = "reth-chainspec", rev = "c0a8a7b" }
# reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-ethereum", rev = "c0a8a7b" }

eyre.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Expand Down
24 changes: 0 additions & 24 deletions examples/advanced/examples/reth_db_layer.rs

This file was deleted.

227 changes: 0 additions & 227 deletions examples/advanced/examples/reth_db_provider.rs

This file was deleted.

41 changes: 41 additions & 0 deletions examples/providers/examples/wrapped_provider.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Example demonstrating how to wrap a provider in a custom type.

use alloy::{
providers::{Provider, ProviderBuilder},
transports::TransportResult,
};
use eyre::Result;

/// Simple free function to get the latest block number.
async fn get_block_number<P: Provider>(provider: &P) -> TransportResult<u64> {
provider.get_block_number().await
}

/// Wrapped provider type.
struct MyProvider<P: Provider> {
provider: P,
}

impl<P: Provider> MyProvider<P> {
/// Create a new instance of `MyProvider`.
fn new(provider: P) -> Self {
Self { provider }
}

async fn get_block_number(&self) -> TransportResult<u64> {
get_block_number(&self.provider).await
}
}

#[tokio::main]
async fn main() -> Result<()> {
let provider = ProviderBuilder::new().on_anvil();

let my_provider = MyProvider::new(provider);

let latest_block = my_provider.get_block_number().await?;

println!("Latest block number: {latest_block}");

Ok(())
}
Loading