Skip to content

Commit

Permalink
[Debt] Improve alloy prelude crate exports and defaults (#39)
Browse files Browse the repository at this point in the history
* only import what is necessary

* repoint branch, still works after refactor

* repoint crate

* use modified core

* fix upstream regression

* remove patches

* fix link, do not use fork
  • Loading branch information
zerosnacks authored Apr 2, 2024
1 parent 49c40da commit 2f109ec
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 99 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,10 @@ jobs:
| grep refs/heads/main \
| cut -f 1)
# Fetch the latest commit hash of the `main` branch from the Alloy Core repository
export latest_alloy_core_commit=$(git ls-remote https://github.com/alloy-rs/core.git \
| grep refs/heads/main \
| cut -f 1)
# Use the commit hash to update the rev in Cargo.toml
sed -i 's/\(alloy = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
Cargo.toml
# Temporary patch until https://github.com/alloy-rs/alloy/pull/392 is resolved
sed -i 's/\(alloy-rpc-client = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
examples/providers/Cargo.toml
sed -i 's/\(alloy-provider = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
examples/providers/Cargo.toml
sed -i 's/\(alloy-rpc-client = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
examples/subscriptions/Cargo.toml
sed -i 's/\(alloy-provider = { git = "https:\/\/github.com\/alloy-rs\/alloy", rev = "\)[^"]*/\1'"$latest_alloy_commit"'/' \
examples/subscriptions/Cargo.toml
# Update to the latest commit
cargo update
Expand Down
27 changes: 6 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,26 @@ unnecessary_struct_initialization = "allow"
use_self = "allow"

[workspace.dependencies]
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af", features = [
# "dyn-abi",
# "json-abi",
# "json",
"sol-types",
# "rlp",
# "serde",
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "27d5ba9", features = [
"contract",
# "consensus",
# "eips",
"network",
# "genesis",
"node-bindings",
"providers",
"rpc",
# "json-rpc",
"provider-http",
"provider-ipc",
"provider-ws",
"rpc-client",
# "rpc-types",
"rpc-client-ipc",
"rpc-client-ws",
"rpc-types-eth",
# "rpc-types-engine",
"rpc-types-trace",
"signers",
# "signer-aws",
# "signer-gcp",
"signer-keystore",
"signer-ledger",
"signer-mnemonic",
"signer-trezor",
"signer-wallet",
"signer-yubihsm",
"transports",
"transport-http",
"transport-ipc",
"transport-ws",
"pubsub",
] }

# async
Expand Down
15 changes: 0 additions & 15 deletions examples/providers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,7 @@ workspace = true

[dev-dependencies]
alloy.workspace = true
# Temp dependency fix to enable relevant features - Ref: https://github.com/alloy-rs/examples/pull/3#discussion_r1537842062
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af", features = [
"pubsub",
"ipc",
"ws",
] }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af", features = [
"pubsub",
"ws",
"ipc",
] }

alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af" }

alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af" }
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af" }
eyre.workspace = true
futures-util = "0.3"
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
10 changes: 6 additions & 4 deletions examples/providers/examples/connect_builtin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Example of using the `RootProvider<N, T: BoxTransport>::connect_builtin` to create a provider
//! from a connection string. The connection string can be a HTTP, WS or IPC endpoint.
use alloy::node_bindings::Anvil;
use alloy_network::Ethereum;
use alloy_provider::{Provider, RootProvider};
use alloy_transport::BoxTransport;
use alloy::{
network::Ethereum,
node_bindings::Anvil,
providers::{Provider, RootProvider},
transports::BoxTransport,
};
use eyre::Result;
use futures_util::StreamExt;

Expand Down
10 changes: 6 additions & 4 deletions examples/providers/examples/ipc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Example of using the IPC provider to get the latest block number.
use alloy_network::Ethereum;
use alloy_provider::{Provider, RootProvider};
use alloy_rpc_client::RpcClient;
use alloy_transport_ipc::IpcConnect;
use alloy::{
network::Ethereum,
providers::{Provider, RootProvider},
rpc::client::RpcClient,
transports::ipc::IpcConnect,
};
use eyre::Result;

#[tokio::main]
Expand Down
10 changes: 5 additions & 5 deletions examples/providers/examples/ws.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Example of using the WS provider to subscribe to new blocks.
// Temp Fix
use alloy_network::Ethereum;
use alloy_provider::{Provider, RootProvider};
use alloy_rpc_client::{RpcClient, WsConnect};
//
use alloy::{
network::Ethereum,
providers::{Provider, RootProvider},
rpc::client::{RpcClient, WsConnect},
};
use eyre::Result;
use futures_util::StreamExt;

Expand Down
12 changes: 6 additions & 6 deletions examples/providers/examples/ws_with_auth.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Example of using the WS provider with auth to subscribe to new blocks.
// Temp Fix
use alloy_network::Ethereum;
use alloy_provider::{Provider, RootProvider};
use alloy_rpc_client::{RpcClient, WsConnect};
use alloy_transport::Authorization;
//
use alloy::{
network::Ethereum,
providers::{Provider, RootProvider},
rpc::client::{RpcClient, WsConnect},
transports::Authorization,
};
use eyre::Result;
use futures_util::StreamExt;

Expand Down
17 changes: 0 additions & 17 deletions examples/subscriptions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ workspace = true

[dev-dependencies]
alloy.workspace = true
# Temp fix for enabling features. Ref: https://github.com/alloy-rs/examples/pull/3/#discussion_r1537842062
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af", features = [
"pubsub",
"ws",
] }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "8acf6af", features = [
"pubsub",
] }
# alloy-contract.workspace = true
# alloy-network.workspace = true
# alloy-node-bindings.workspace = true
# alloy-provider = { workspace = true, features = ["pubsub", "ws"] }
# alloy-pubsub.workspace = true
# alloy-primitives.workspace = true
# alloy-rpc-client.workspace = true
# alloy-rpc-types.workspace = true
# alloy-sol-types = { workspace = true }

eyre.workspace = true
futures-util = "0.3"
Expand Down
11 changes: 8 additions & 3 deletions examples/subscriptions/examples/event_multiplexer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//! Example of multiplexing the watching of event logs.
use alloy::{node_bindings::Anvil, primitives::I256, sol, sol_types::SolEvent};
use alloy_provider::ProviderBuilder;
use alloy_rpc_client::{RpcClient, WsConnect};
use alloy::{
node_bindings::Anvil,
primitives::I256,
providers::ProviderBuilder,
rpc::client::{RpcClient, WsConnect},
sol,
sol_types::SolEvent,
};
use eyre::Result;
use futures_util::StreamExt;
use std::str::FromStr;
Expand Down
10 changes: 6 additions & 4 deletions examples/subscriptions/examples/subscribe_blocks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Example of subscribing to blocks and watching block headers by polling.
use alloy::node_bindings::Anvil;
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_client::RpcClient;
use alloy::{
node_bindings::Anvil,
providers::{Provider, ProviderBuilder},
rpc::client::{RpcClient, WsConnect},
};
use eyre::Result;
use futures_util::{stream, StreamExt};

Expand All @@ -13,7 +15,7 @@ async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).try_spawn()?;

// Create a provider.
let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint());
let ws = WsConnect::new(anvil.ws_endpoint());
let provider = ProviderBuilder::new().on_client(RpcClient::connect_pubsub(ws).await?);

// Subscribe to blocks.
Expand Down
12 changes: 7 additions & 5 deletions examples/subscriptions/examples/watch_contract_event.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Example of subscribing to blocks and watching contract events by WebSocket subscription.
use alloy::{node_bindings::Anvil, sol};
use alloy_provider::ProviderBuilder;
use alloy_rpc_client::RpcClient;
use alloy::{
node_bindings::Anvil,
providers::ProviderBuilder,
rpc::client::{RpcClient, WsConnect},
sol,
};
use eyre::Result;
use futures_util::StreamExt;

Expand Down Expand Up @@ -36,8 +39,7 @@ async fn main() -> Result<()> {
let anvil = Anvil::new().block_time(1).try_spawn()?;

// Create a WebSocket provider.
let ws_rpc_url = anvil.ws_endpoint();
let ws = alloy_rpc_client::WsConnect::new(ws_rpc_url);
let ws = WsConnect::new(anvil.ws_endpoint());
let provider = ProviderBuilder::new().on_client(RpcClient::connect_pubsub(ws).await?);

// Deploy the `Counter` contract.
Expand Down

0 comments on commit 2f109ec

Please sign in to comment.