From ff0b65df3b95e55a9fa831907ec63311cfc35037 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 14 Feb 2024 07:35:12 +0200 Subject: [PATCH] feat: add `alloy` prelude crate (#203) * feat: add `alloy` prelude crate * docs * chore: unused attribute * update --- .github/workflows/ci.yml | 2 +- Cargo.toml | 53 +++---- README.md | 11 +- crates/alloy/Cargo.toml | 131 +++++++++++++++++ crates/alloy/README.md | 1 + crates/alloy/src/lib.rs | 178 +++++++++++++++++++++++ crates/contract/Cargo.toml | 2 +- crates/contract/README.md | 2 +- crates/contract/src/call.rs | 1 - crates/providers/Cargo.toml | 6 +- crates/providers/README.md | 9 +- crates/providers/src/lib.rs | 4 +- crates/pubsub/Cargo.toml | 2 +- crates/pubsub/README.md | 2 +- crates/pubsub/src/ix.rs | 1 - crates/pubsub/src/managers/active_sub.rs | 5 +- crates/pubsub/src/service.rs | 8 +- crates/pubsub/src/sub.rs | 2 +- crates/rpc-client/Cargo.toml | 4 +- crates/rpc-client/README.md | 2 +- crates/transport-http/Cargo.toml | 10 +- crates/transport-ipc/src/connect.rs | 1 - 22 files changed, 373 insertions(+), 64 deletions(-) create mode 100644 crates/alloy/Cargo.toml create mode 120000 crates/alloy/README.md create mode 100644 crates/alloy/src/lib.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6292a457cc5..5faad0d271a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: with: cache-on-failure: true - name: cargo hack - run: cargo hack check --feature-powerset --depth 2 + run: cargo hack check --feature-powerset --depth 1 clippy: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 75479d89985..bdbaa76ce43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,33 +17,34 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [workspace.dependencies] -alloy-consensus = { version = "0.1.0", path = "crates/consensus" } -alloy-dyn-contract = { version = "0.1.0", path = "crates/dyn-contract" } -alloy-eips = { version = "0.1.0", path = "crates/eips" } -alloy-genesis = { version = "0.1.0", path = "crates/genesis" } -alloy-json-rpc = { version = "0.1.0", path = "crates/json-rpc" } -alloy-network = { version = "0.1.0", path = "crates/network" } -alloy-node-bindings = { version = "0.1.0", path = "crates/node-bindings" } -alloy-providers = { version = "0.1.0", path = "crates/providers" } -alloy-pubsub = { version = "0.1.0", path = "crates/pubsub" } -alloy-rpc-client = { version = "0.1.0", path = "crates/rpc-client" } -alloy-rpc-engine-types = { version = "0.1.0", path = "crates/rpc-engine-types" } -alloy-rpc-trace-types = { version = "0.1.0", path = "crates/rpc-trace-types" } -alloy-rpc-types = { version = "0.1.0", path = "crates/rpc-types" } -alloy-signer = { version = "0.1.0", path = "crates/signer" } -alloy-signer-aws = { version = "0.1.0", path = "crates/signer-aws" } -alloy-signer-gcp = { version = "0.1.0", path = "crates/signer-gcp" } -alloy-signer-ledger = { version = "0.1.0", path = "crates/signer-ledger" } -alloy-signer-trezor = { version = "0.1.0", path = "crates/signer-trezor" } -alloy-transport = { version = "0.1.0", path = "crates/transport" } -alloy-transport-http = { version = "0.1.0", path = "crates/transport-http" } -alloy-transport-ipc = { version = "0.1.0", path = "crates/transport-ipc" } -alloy-transport-ws = { version = "0.1.0", path = "crates/transport-ws" } +alloy-consensus = { version = "0.1.0", default-features = false, path = "crates/consensus" } +alloy-contract = { version = "0.1.0", default-features = false, path = "crates/contract" } +alloy-eips = { version = "0.1.0", default-features = false, path = "crates/eips" } +alloy-genesis = { version = "0.1.0", default-features = false, path = "crates/genesis" } +alloy-json-rpc = { version = "0.1.0", default-features = false, path = "crates/json-rpc" } +alloy-network = { version = "0.1.0", default-features = false, path = "crates/network" } +alloy-node-bindings = { version = "0.1.0", default-features = false, path = "crates/node-bindings" } +alloy-providers = { version = "0.1.0", default-features = false, path = "crates/providers" } +alloy-pubsub = { version = "0.1.0", default-features = false, path = "crates/pubsub" } +alloy-rpc-client = { version = "0.1.0", default-features = false, path = "crates/rpc-client" } +alloy-rpc-engine-types = { version = "0.1.0", default-features = false, path = "crates/rpc-engine-types" } +alloy-rpc-trace-types = { version = "0.1.0", default-features = false, path = "crates/rpc-trace-types" } +alloy-rpc-types = { version = "0.1.0", default-features = false, path = "crates/rpc-types" } +alloy-signer = { version = "0.1.0", default-features = false, path = "crates/signer" } +alloy-signer-aws = { version = "0.1.0", default-features = false, path = "crates/signer-aws" } +alloy-signer-gcp = { version = "0.1.0", default-features = false, path = "crates/signer-gcp" } +alloy-signer-ledger = { version = "0.1.0", default-features = false, path = "crates/signer-ledger" } +alloy-signer-trezor = { version = "0.1.0", default-features = false, path = "crates/signer-trezor" } +alloy-transport = { version = "0.1.0", default-features = false, path = "crates/transport" } +alloy-transport-http = { version = "0.1.0", default-features = false, path = "crates/transport-http" } +alloy-transport-ipc = { version = "0.1.0", default-features = false, path = "crates/transport-ipc" } +alloy-transport-ws = { version = "0.1.0", default-features = false, path = "crates/transport-ws" } -alloy-primitives = "0.6" -alloy-sol-types = "0.6" -alloy-dyn-abi = "0.6" -alloy-json-abi = "0.6" +alloy-core = { version = "0.6", default-features = false, features = ["std"] } +alloy-dyn-abi = { version = "0.6", default-features = false, features = ["std"] } +alloy-json-abi = { version = "0.6", default-features = false, features = ["std"] } +alloy-primitives = { version = "0.6", default-features = false, features = ["std"] } +alloy-sol-types = { version = "0.6", default-features = false, features = ["std"] } alloy-rlp = "0.3" diff --git a/README.md b/README.md index 7000887cd15..daf33a91787 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,17 @@ feature-parity in Alloy. No action is currently needed from devs. This repository contains the following crates: +- [`alloy`]: Meta-crate for the entire project, including [`alloy-core`] - [`alloy-consensus`] - Ethereum consensus interface +- [`alloy-contract`] - Interact with on-chain contracts - [`alloy-eips`] - Ethereum Improvement Proprosal (EIP) implementations - [`alloy-genesis`] - Ethereum genesis file definitions - [`alloy-json-rpc`] - Core data types for JSON-RPC 2.0 clients - [`alloy-network`] - Network abstraction for RPC types - [`alloy-node-bindings`] - Ethereum execution-layer client bindings -- [`alloy-providers`] - Client trait for interacting with Ethereum-like RPC endpoints -- [`alloy-pubsub`] - Ethereum JSON-RPC [publish-subscribe] provider -- [`alloy-rpc-client`] - High-level Ethereum JSON-RPC client implementation +- [`alloy-providers`] - Interface with an Ethereum blockchain +- [`alloy-pubsub`] - Ethereum JSON-RPC [publish-subscribe] tower service and type definitions +- [`alloy-rpc-client`] - Low-level Ethereum JSON-RPC client implementation - [`alloy-rpc-types`] - Ethereum JSON-RPC types - [`alloy-rpc-engine-types`] - Ethereum execution-consensus layer (engine) API RPC types - [`alloy-rpc-trace-types`] - Ethereum RPC trace types @@ -40,7 +42,9 @@ This repository contains the following crates: - [`alloy-transport-ipc`] - IPC transport implementation - [`alloy-transport-ws`] - WS transport implementation +[`alloy`]: crates/alloy [`alloy-consensus`]: crates/consensus +[`alloy-contract`]: crates/contract [`alloy-eips`]: crates/eips [`alloy-genesis`]: crates/genesis [`alloy-json-rpc`]: crates/json-rpc @@ -62,6 +66,7 @@ This repository contains the following crates: [`alloy-transport-ipc`]: crates/transport-ipc [`alloy-transport-ws`]: crates/transport-ws +[`alloy-core`]: https://docs.rs/alloy-core [publish-subscribe]: https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern [AWS KMS]: https://aws.amazon.com/kms [GCP KMS]: https://cloud.google.com/kms diff --git a/crates/alloy/Cargo.toml b/crates/alloy/Cargo.toml new file mode 100644 index 00000000000..1588a33857a --- /dev/null +++ b/crates/alloy/Cargo.toml @@ -0,0 +1,131 @@ +[package] +name = "alloy" +description = "Connect applications to blockchains" + +version.workspace = true +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +exclude.workspace = true + +[dependencies] +alloy-core = { workspace = true, default-features = false, features = ["std"] } + +alloy-consensus = { workspace = true, default-features = false, optional = true } +alloy-contract = { workspace = true, default-features = false, optional = true } +alloy-eips = { workspace = true, default-features = false, optional = true } +alloy-genesis = { workspace = true, default-features = false, optional = true } +alloy-network = { workspace = true, default-features = false, optional = true } +alloy-node-bindings = { workspace = true, default-features = false, optional = true } +alloy-providers = { workspace = true, default-features = false, optional = true } +alloy-pubsub = { workspace = true, default-features = false, optional = true } + +# rpc +alloy-json-rpc = { workspace = true, default-features = false, optional = true } +alloy-rpc-client = { workspace = true, default-features = false, optional = true } +alloy-rpc-engine-types = { workspace = true, default-features = false, optional = true } +alloy-rpc-trace-types = { workspace = true, default-features = false, optional = true } +alloy-rpc-types = { workspace = true, default-features = false, optional = true } + +# signer +alloy-signer = { workspace = true, default-features = false, optional = true } +alloy-signer-aws = { workspace = true, default-features = false, optional = true } +alloy-signer-gcp = { workspace = true, default-features = false, optional = true } +alloy-signer-ledger = { workspace = true, default-features = false, optional = true } +alloy-signer-trezor = { workspace = true, default-features = false, optional = true } + +# transport +alloy-transport = { workspace = true, default-features = false, optional = true } +alloy-transport-http = { workspace = true, default-features = false, optional = true } +reqwest = { workspace = true, default-features = false, optional = true } +alloy-transport-ipc = { workspace = true, default-features = false, optional = true } +alloy-transport-ws = { workspace = true, default-features = false, optional = true } + +[features] +default = ["transport-http-reqwest", "default-tls"] + +# alloy-core +dyn-abi = ["alloy-core/dyn-abi"] +json-abi = ["alloy-core/json-abi"] +json = ["alloy-core/json"] +sol-types = ["alloy-core/sol-types"] + +tiny-keccak = ["alloy-core/tiny-keccak"] +asm-keccak = ["alloy-core/asm-keccak"] + +postgres = ["alloy-core/postgres"] +getrandom = ["alloy-core/getrandom"] +rand = ["alloy-core/rand"] +rlp = ["alloy-core/rlp"] +serde = ["alloy-core/serde", "alloy-eips?/serde"] +ssz = ["alloy-core/ssz", "alloy-rpc-types?/ssz", "alloy-rpc-engine-types?/ssz"] +arbitrary = [ + "alloy-core/arbitrary", + "alloy-consensus?/arbitrary", + "alloy-eips?/arbitrary", + "alloy-rpc-types?/arbitrary", +] +k256 = ["alloy-core/k256", "alloy-consensus?/k256", "alloy-network?/k256"] +eip712 = [ + "alloy-core/eip712", + "alloy-signer?/eip712", + "alloy-signer-aws?/eip712", + "alloy-signer-gcp?/eip712", + "alloy-signer-ledger?/eip712", + # TODO: https://github.com/alloy-rs/alloy/issues/201 + # "alloy-signer-trezor?/eip712", +] + +# alloy +default-tls = ["reqwest?/default-tls"] +jsonrpsee-types = ["alloy-rpc-types?/jsonrpsee-types", "alloy-rpc-engine-types?/jsonrpsee-types"] + +consensus = ["dep:alloy-consensus"] +eips = ["dep:alloy-eips"] +network = ["dep:alloy-network"] +genesis = ["dep:alloy-genesis"] +node-bindings = ["dep:alloy-node-bindings"] + +contract = ["dep:alloy-contract", "dyn-abi", "json-abi", "json", "sol-types"] + +## providers +providers = ["dep:alloy-providers"] +provider-http = ["providers", "transport-http"] +provider-ws = ["providers", "transport-ws"] +provider-ipc = ["providers", "transport-ipc"] + +## pubsub +pubsub = ["dep:alloy-pubsub"] + +## rpc +rpc = [] +json-rpc = ["rpc", "dep:alloy-json-rpc"] +rpc-client = ["rpc", "dep:alloy-rpc-client"] +rpc-types = ["rpc"] +rpc-types-eth = ["rpc-types", "dep:alloy-rpc-types"] +rpc-types-engine = ["rpc-types", "dep:alloy-rpc-engine-types"] +rpc-types-trace = ["rpc-types", "dep:alloy-rpc-trace-types"] + +## signers +signers = ["dep:alloy-signer"] +### Default signer extensions +signer-keystore = ["signers", "alloy-signer?/keystore"] +signer-mnemonic = ["signers", "alloy-signer?/mnemonic"] +signer-yubihsm = ["signers", "alloy-signer?/yubihsm"] +### Signer implementations +signer-aws = ["signers", "dep:alloy-signer-aws"] +signer-gcp = ["signers", "dep:alloy-signer-gcp"] +signer-ledger = ["signers", "dep:alloy-signer-ledger"] +signer-trezor = ["signers", "dep:alloy-signer-trezor"] + +## transports +transports = ["dep:alloy-transport"] +transport-http = ["transports", "dep:alloy-transport-http"] +transport-http-reqwest = ["dep:reqwest", "alloy-transport-http?/reqwest"] +transport-http-hyper = ["alloy-transport-http?/hyper"] +transport-ipc = ["transports", "pubsub", "dep:alloy-transport-ipc"] +transport-ipc-mock = ["alloy-transport-ipc?/mock"] +transport-ws = ["transports", "pubsub", "dep:alloy-transport-ws"] diff --git a/crates/alloy/README.md b/crates/alloy/README.md new file mode 120000 index 00000000000..fe840054137 --- /dev/null +++ b/crates/alloy/README.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/crates/alloy/src/lib.rs b/crates/alloy/src/lib.rs new file mode 100644 index 00000000000..4ce7cabd05c --- /dev/null +++ b/crates/alloy/src/lib.rs @@ -0,0 +1,178 @@ +#![doc = include_str!("../README.md")] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg", + html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico" +)] +#![warn( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + unreachable_pub, + clippy::missing_const_for_fn, + rustdoc::all +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +// Just for features. +#[cfg(feature = "transport-http-reqwest")] +use reqwest as _; + +#[doc(inline)] +pub use alloy_core::*; + +#[cfg(feature = "contract")] +#[doc(inline)] +pub use alloy_contract as contract; + +#[cfg(feature = "consensus")] +#[doc(inline)] +pub use alloy_consensus as consensus; + +#[cfg(feature = "eips")] +#[doc(inline)] +pub use alloy_eips as eips; + +#[cfg(feature = "network")] +#[doc(inline)] +pub use alloy_network as network; + +#[cfg(feature = "genesis")] +#[doc(inline)] +pub use alloy_genesis as genesis; + +#[cfg(feature = "node-bindings")] +#[doc(inline)] +pub use alloy_node_bindings as node_bindings; + +/// Interface with an Ethereum blockchain. +/// +/// See [`alloy_providers`] for more details. +#[cfg(feature = "providers")] +pub mod providers { + #[doc(inline)] + pub use alloy_providers::*; + + // TODO: provider type aliases + // #[cfg(feature = "provider-http")] + // pub type HttpProvider = todo!(); + // #[cfg(feature = "provider-ws")] + // pub type WsProvider = todo!(); + // #[cfg(feature = "provider-ipc")] + // pub type WsProvider = todo!(); +} + +/// Ethereum JSON-RPC client and types. +#[cfg(feature = "rpc")] +pub mod rpc { + #[cfg(feature = "rpc-client")] + #[doc(inline)] + pub use alloy_rpc_client as client; + + #[cfg(feature = "json-rpc")] + #[doc(inline)] + pub use alloy_json_rpc as json_rpc; + + /// Ethereum JSON-RPC type definitions. + #[cfg(feature = "rpc-types")] + pub mod types { + #[cfg(feature = "rpc-types-eth")] + #[doc(inline)] + pub use alloy_rpc_types as eth; + + #[cfg(feature = "rpc-types-engine")] + #[doc(inline)] + pub use alloy_rpc_engine_types as engine; + + #[cfg(feature = "rpc-types-trace")] + #[doc(inline)] + pub use alloy_rpc_trace_types as trace; + } +} + +/// Ethereum signer abstraction and implementations. +/// +/// See [`alloy_signer`] for more details. +#[cfg(feature = "signers")] +pub mod signers { + #[doc(inline)] + pub use alloy_signer::*; + + #[cfg(feature = "signer-aws")] + #[doc(inline)] + pub use alloy_signer_aws as aws; + #[cfg(feature = "signer-gcp")] + #[doc(inline)] + pub use alloy_signer_gcp as gcp; + #[cfg(feature = "signer-ledger")] + #[doc(inline)] + pub use alloy_signer_ledger as ledger; + #[cfg(feature = "signer-trezor")] + #[doc(inline)] + pub use alloy_signer_trezor as trezor; +} + +/// Low-level Ethereum JSON-RPC transport abstraction and implementations. +/// +/// You will likely not need to use this module; +/// see the [`providers`] module for high-level usage of transports. +/// +/// See [`alloy_transport`] for more details. +#[doc = "\n"] // Empty doc line `///` gets deleted by rustfmt. +#[cfg_attr(feature = "providers", doc = "[`providers`]: crate::providers")] +#[cfg_attr( + not(feature = "providers"), + doc = "[`providers`]: https://github.com/alloy-rs/alloy/tree/main/crates/providers" +)] +#[cfg(feature = "transports")] +pub mod transports { + #[doc(inline)] + pub use alloy_transport::*; + + #[cfg(feature = "transport-http")] + #[doc(inline)] + pub use alloy_transport_http as http; + #[cfg(feature = "transport-ipc")] + #[doc(inline)] + pub use alloy_transport_ipc as ipc; + #[cfg(feature = "transport-ws")] + #[doc(inline)] + pub use alloy_transport_ws as ws; +} + +/// Ethereum JSON-RPC publish-subscribe tower service and type definitions. +/// +/// You will likely not need to use this module; +/// see the [`providers`] module for high-level usage of pubsub. +/// +/// See [`alloy_pubsub`] for more details. +#[doc = "\n"] // Empty doc line `///` gets deleted by rustfmt. +#[cfg_attr(feature = "providers", doc = "[`providers`]: crate::providers")] +#[cfg_attr( + not(feature = "providers"), + doc = "[`providers`]: https://github.com/alloy-rs/alloy/tree/main/crates/providers" +)] +#[cfg(feature = "pubsub")] +pub mod pubsub { + #[doc(inline)] + pub use alloy_pubsub::*; +} + +// TODO: Enable on next alloy-core release. +/* +/// [`sol!`](sol_types::sol!) macro wrapper to route imports to the correct crate. +/// +/// See [`sol!`](sol_types::sol!) for the actual macro documentation. +#[cfg(all(not(doc), feature = "sol-types"))] +#[doc(hidden)] +#[macro_export] +macro_rules! sol { + ($($t:tt)*) => { + $crate::sol_types::sol! { + #![sol(alloy_sol_types = $crate::sol_types, alloy_contract = $crate::contract)] + $($t)* + } + }; +} +*/ diff --git a/crates/contract/Cargo.toml b/crates/contract/Cargo.toml index bcc7089396d..23bb2f17f2c 100644 --- a/crates/contract/Cargo.toml +++ b/crates/contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alloy-contract" -description = "Helpers for interacting with on-chain contracts" +description = "Interact with on-chain contracts" version.workspace = true edition.workspace = true diff --git a/crates/contract/README.md b/crates/contract/README.md index 6ad0e5c7291..948b14ce1a1 100644 --- a/crates/contract/README.md +++ b/crates/contract/README.md @@ -1,6 +1,6 @@ # alloy-contract -Helpers for interacting with on-chain contracts. +Interact with on-chain contracts. The main type is `CallBuilder`, which is a builder for constructing calls to on-chain contracts. It provides a way to encode and decode data for on-chain calls, and to send those calls to the chain. diff --git a/crates/contract/src/call.rs b/crates/contract/src/call.rs index 9d59190ea23..085c49d7fd8 100644 --- a/crates/contract/src/call.rs +++ b/crates/contract/src/call.rs @@ -560,7 +560,6 @@ mod tests { ); } - #[allow(dead_code)] fn spawn_anvil() -> (HttpProvider, AnvilInstance) { let anvil = Anvil::new().spawn(); let provider = Provider::try_from(anvil.endpoint()).unwrap(); diff --git a/crates/providers/Cargo.toml b/crates/providers/Cargo.toml index 24aceeaa6f1..3009f71c98f 100644 --- a/crates/providers/Cargo.toml +++ b/crates/providers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alloy-providers" -description = "Ethereum JSON-RPC providers" +description = "Interface with an Ethereum blockchain" version.workspace = true edition.workspace = true @@ -14,10 +14,10 @@ exclude.workspace = true [dependencies] alloy-network.workspace = true alloy-primitives.workspace = true -alloy-rpc-client.workspace = true +alloy-rpc-client = { workspace = true, features = ["reqwest"] } alloy-rpc-types.workspace = true alloy-rpc-trace-types.workspace = true -alloy-transport-http.workspace = true +alloy-transport-http = { workspace = true, features = ["reqwest"] } alloy-transport.workspace = true async-trait.workspace = true serde.workspace = true diff --git a/crates/providers/README.md b/crates/providers/README.md index 42dfce29295..53efa430fef 100644 --- a/crates/providers/README.md +++ b/crates/providers/README.md @@ -2,13 +2,13 @@ -Client trait for interacting with Ethereum-like RPC endpoints. +Interface with an Ethereum blockchain. This crate contains the `Provider` trait, which exposes Ethereum JSON-RPC -methods. Providers in alloy are similar to ethers.js Providers. They manage an -`RpcClient` and allow other parts of the program to easily make RPC calls. +methods. Providers in alloy are similar to [`ethers.js`] providers. They manage +an `RpcClient` and allow other parts of the program to easily make RPC calls. -Unlike an ethers.js Provider, an alloy Provider is network-aware. It is +Unlike an [`ethers.js`] Provider, an alloy Provider is network-aware. It is parameterized with a `Network` from [`alloy-networks`]. This allows the Provider to expose a consistent interface to the rest of the program, while adjusting request and response types to match the underlying blockchain. @@ -23,6 +23,7 @@ The `ProviderBuilder` struct can quickly create a stacked provider, similar to [alloy-networks]: ../networks/ [`tower::ServiceBuilder`]: https://docs.rs/tower/latest/tower/struct.ServiceBuilder.html +[`ethers.js`]: https://docs.ethers.org/v6/ ## Usage diff --git a/crates/providers/src/lib.rs b/crates/providers/src/lib.rs index 9001de90dac..036cdb1c5a5 100644 --- a/crates/providers/src/lib.rs +++ b/crates/providers/src/lib.rs @@ -71,10 +71,10 @@ where } } -#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] -#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] /// Provider is parameterized with a network and a transport. The default /// transport is type-erased, but you can do `Provider`. +#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] +#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] pub trait Provider: Send + Sync { fn raw_client(&self) -> &RpcClient { &self.client().client diff --git a/crates/pubsub/Cargo.toml b/crates/pubsub/Cargo.toml index 264138c1d2c..273943147a5 100644 --- a/crates/pubsub/Cargo.toml +++ b/crates/pubsub/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alloy-pubsub" -description = "Publish-subscribe Alloy provider" +description = "Ethereum JSON-RPC publish-subscribe tower service and type definitions" version.workspace = true edition.workspace = true diff --git a/crates/pubsub/README.md b/crates/pubsub/README.md index ac38c986e5d..8da1275cf34 100644 --- a/crates/pubsub/README.md +++ b/crates/pubsub/README.md @@ -1,6 +1,6 @@ # alloy-pubsub -Ethereum JSON-RPC [publish-subscribe] provider. +Ethereum JSON-RPC [publish-subscribe] tower service and type definitions. [publish-subscribe]: https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern diff --git a/crates/pubsub/src/ix.rs b/crates/pubsub/src/ix.rs index 766060a316d..ee78d7ac713 100644 --- a/crates/pubsub/src/ix.rs +++ b/crates/pubsub/src/ix.rs @@ -1,5 +1,4 @@ use crate::{managers::InFlight, RawSubscription}; - use alloy_primitives::U256; use std::fmt; use tokio::sync::oneshot; diff --git a/crates/pubsub/src/managers/active_sub.rs b/crates/pubsub/src/managers/active_sub.rs index e1fadaa87a3..3984848db48 100644 --- a/crates/pubsub/src/managers/active_sub.rs +++ b/crates/pubsub/src/managers/active_sub.rs @@ -1,13 +1,12 @@ +use crate::RawSubscription; use alloy_json_rpc::SerializedRequest; use alloy_primitives::B256; use serde_json::value::RawValue; use std::{fmt, hash::Hash, usize}; use tokio::sync::broadcast; -use crate::RawSubscription; - -#[derive(Clone)] /// An active subscription. +#[derive(Clone)] pub(crate) struct ActiveSubscription { /// Cached hash of the request, used for sorting and equality. pub(crate) local_id: B256, diff --git a/crates/pubsub/src/service.rs b/crates/pubsub/src/service.rs index 81f79e4cac1..c4dcf50a218 100644 --- a/crates/pubsub/src/service.rs +++ b/crates/pubsub/src/service.rs @@ -4,7 +4,6 @@ use crate::{ managers::{InFlight, RequestManager, SubscriptionManager}, PubSubConnect, PubSubFrontend, RawSubscription, }; - use alloy_json_rpc::{Id, PubSubItem, Request, Response, ResponsePayload}; use alloy_primitives::U256; use alloy_transport::{ @@ -14,9 +13,9 @@ use alloy_transport::{ use serde_json::value::RawValue; use tokio::sync::{mpsc, oneshot}; -#[derive(Debug)] /// The service contains the backend handle, a subscription manager, and the /// configuration details required to reconnect. +#[derive(Debug)] pub(crate) struct PubSubService { /// The backend handle. pub(crate) handle: ConnectionHandle, @@ -34,10 +33,7 @@ pub(crate) struct PubSubService { pub(crate) in_flights: RequestManager, } -impl PubSubService -where - T: PubSubConnect, -{ +impl PubSubService { /// Create a new service from a connector. pub(crate) async fn connect(connector: T) -> Result { let handle = connector.connect().await?; diff --git a/crates/pubsub/src/sub.rs b/crates/pubsub/src/sub.rs index e01855a2569..119080882ce 100644 --- a/crates/pubsub/src/sub.rs +++ b/crates/pubsub/src/sub.rs @@ -74,9 +74,9 @@ impl RawSubscription { } } -#[derive(Debug)] /// An item in a typed [`Subscription`]. This is either the expected type, or /// some serialized value of another type. +#[derive(Debug)] pub enum SubscriptionItem { /// The expected item. Item(T), diff --git a/crates/rpc-client/Cargo.toml b/crates/rpc-client/Cargo.toml index add716b4b99..d66928548c7 100644 --- a/crates/rpc-client/Cargo.toml +++ b/crates/rpc-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alloy-rpc-client" -description = "High-level Ethereum JSON-RPC client implementation" +description = "Low-level Ethereum JSON-RPC client implementation" version.workspace = true edition.workspace = true @@ -29,7 +29,7 @@ hyper = { workspace = true, optional = true } reqwest = { workspace = true, optional = true } url = { workspace = true, optional = true } -serde = { workspace = true, optional = true } +serde = { workspace = true, optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] alloy-transport-ipc = { workspace = true, optional = true } diff --git a/crates/rpc-client/README.md b/crates/rpc-client/README.md index 5080e063a51..d2d19d6fe17 100644 --- a/crates/rpc-client/README.md +++ b/crates/rpc-client/README.md @@ -1,3 +1,3 @@ # alloy-rpc-client -High-level Ethereum JSON-RPC client implementation. +Low-level Ethereum JSON-RPC client implementation. diff --git a/crates/transport-http/Cargo.toml b/crates/transport-http/Cargo.toml index 0a03f2bdfab..2ef975ccbef 100644 --- a/crates/transport-http/Cargo.toml +++ b/crates/transport-http/Cargo.toml @@ -12,12 +12,12 @@ repository.workspace = true exclude.workspace = true [dependencies] -alloy-json-rpc.workspace = true +alloy-json-rpc = { workspace = true, optional = true } alloy-transport.workspace = true url.workspace = true -serde_json.workspace = true -tower.workspace = true +serde_json = { workspace = true, optional = true } +tower = { workspace = true, optional = true } reqwest = { workspace = true, features = ["serde_json", "json"], optional = true } @@ -26,5 +26,5 @@ hyper = { workspace = true, features = ["full"], optional = true } [features] default = ["reqwest"] -reqwest = ["dep:reqwest"] -hyper = ["dep:hyper"] +reqwest = ["dep:reqwest", "dep:alloy-json-rpc", "dep:serde_json", "dep:tower"] +hyper = ["dep:hyper", "dep:alloy-json-rpc", "dep:serde_json", "dep:tower"] diff --git a/crates/transport-ipc/src/connect.rs b/crates/transport-ipc/src/connect.rs index f905b76056e..7b5bfc5290e 100644 --- a/crates/transport-ipc/src/connect.rs +++ b/crates/transport-ipc/src/connect.rs @@ -6,7 +6,6 @@ use std::{ #[derive(Debug, Clone)] /// An IPC Connection object. pub struct IpcConnect { - /// inner: T, }