From f5d735c955392993dc53b3213b86b9576289d27e Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Tue, 6 Aug 2024 15:43:23 +0200 Subject: [PATCH] Feature gate `jsonrpsee` related things --- Makefile | 1 + crates/rpc/rpc-types/Cargo.toml | 14 ++++++++++---- crates/rpc/rpc-types/src/eth/error.rs | 10 +++++----- crates/rpc/rpc-types/src/eth/mod.rs | 1 + crates/rpc/rpc-types/src/lib.rs | 7 +++++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 102bd3c49b5f..119d1825048c 100644 --- a/Makefile +++ b/Makefile @@ -473,4 +473,5 @@ check-features: --package reth-codecs \ --package reth-primitives-traits \ --package reth-primitives \ + --package reth-rpc-types \ --feature-powerset \ No newline at end of file diff --git a/crates/rpc/rpc-types/Cargo.toml b/crates/rpc/rpc-types/Cargo.toml index df6128dbb04c..59937f55af02 100644 --- a/crates/rpc/rpc-types/Cargo.toml +++ b/crates/rpc/rpc-types/Cargo.toml @@ -15,15 +15,15 @@ workspace = true # ethereum alloy-primitives = { workspace = true, features = ["rand", "rlp", "serde"] } -alloy-rpc-types = { workspace = true, features = ["jsonrpsee-types"] } +alloy-rpc-types = { workspace = true } alloy-rpc-types-admin.workspace = true alloy-rpc-types-anvil.workspace = true -alloy-rpc-types-beacon.workspace = true +alloy-rpc-types-beacon = { workspace = true, optional = true } alloy-rpc-types-mev.workspace = true alloy-rpc-types-trace.workspace = true alloy-rpc-types-txpool.workspace = true alloy-serde.workspace = true -alloy-rpc-types-engine = { workspace = true, features = ["jsonrpsee-types"] } +alloy-rpc-types-engine = { workspace = true, features = ["jsonrpsee-types"], optional = true } # misc jsonrpsee-types = { workspace = true, optional = true } @@ -38,5 +38,11 @@ bytes.workspace = true serde_json.workspace = true [features] -default = ["jsonrpsee-types"] +default = [ + "dep:jsonrpsee-types", + "dep:alloy-rpc-types-beacon", + "dep:alloy-rpc-types-engine", + "alloy-rpc-types/jsonrpsee-types", + "alloy-rpc-types-engine/jsonrpsee-types" +] arbitrary = ["alloy-primitives/arbitrary", "alloy-rpc-types/arbitrary"] diff --git a/crates/rpc/rpc-types/src/eth/error.rs b/crates/rpc/rpc-types/src/eth/error.rs index f7a1c53b1485..459cac49e67e 100644 --- a/crates/rpc/rpc-types/src/eth/error.rs +++ b/crates/rpc/rpc-types/src/eth/error.rs @@ -1,15 +1,15 @@ //! Implementation specific Errors for the `eth_` namespace. -use jsonrpsee_types::ErrorObject; - /// A trait to convert an error to an RPC error. +#[cfg(feature = "default")] pub trait ToRpcError: std::error::Error + Send + Sync + 'static { /// Converts the error to a JSON-RPC error object. - fn to_rpc_error(&self) -> ErrorObject<'static>; + fn to_rpc_error(&self) -> jsonrpsee_types::ErrorObject<'static>; } -impl ToRpcError for ErrorObject<'static> { - fn to_rpc_error(&self) -> ErrorObject<'static> { +#[cfg(feature = "default")] +impl ToRpcError for jsonrpsee_types::ErrorObject<'static> { + fn to_rpc_error(&self) -> jsonrpsee_types::ErrorObject<'static> { self.clone() } } diff --git a/crates/rpc/rpc-types/src/eth/mod.rs b/crates/rpc/rpc-types/src/eth/mod.rs index 6313dbeedb29..55dd4fe9c216 100644 --- a/crates/rpc/rpc-types/src/eth/mod.rs +++ b/crates/rpc/rpc-types/src/eth/mod.rs @@ -4,4 +4,5 @@ pub(crate) mod error; pub mod transaction; // re-export +#[cfg(feature = "default")] pub use alloy_rpc_types_engine as engine; diff --git a/crates/rpc/rpc-types/src/lib.rs b/crates/rpc/rpc-types/src/lib.rs index 47c10e881579..afc51b88a5d1 100644 --- a/crates/rpc/rpc-types/src/lib.rs +++ b/crates/rpc/rpc-types/src/lib.rs @@ -40,17 +40,20 @@ pub use alloy_rpc_types_anvil as anvil; pub use alloy_rpc_types_mev as mev; // re-export beacon +#[cfg(feature = "default")] pub use alloy_rpc_types_beacon as beacon; // re-export txpool pub use alloy_rpc_types_txpool as txpool; // Ethereum specific rpc types related to typed transaction requests and the engine API. +#[cfg(feature = "default")] +pub use eth::error::ToRpcError; +pub use eth::transaction::{self, TransactionRequest, TypedTransactionRequest}; +#[cfg(feature = "default")] pub use eth::{ engine, engine::{ ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, PayloadError, }, - error::ToRpcError, - transaction::{self, TransactionRequest, TypedTransactionRequest}, };