Skip to content

Commit

Permalink
feat(rpc): Split off eth namespace in alloy-rpc-types to `alloy-r…
Browse files Browse the repository at this point in the history
…pc-types-eth` (#847)

* start with eth namespace split

* continue

* move with_other to rpc-types

* add back WithOtherFields into `rpc-types-eth` due to circular dependency in request / receipt

* avoid defaulting features in meta-crate

* re-add feature flags

* use metacrate

* add rpc-types-eth as enabled flag as default-features are disabled in alloy metacrate

* export as *

* trim rpc-types- prefix
  • Loading branch information
zerosnacks authored Jun 10, 2024
1 parent a81f9e1 commit 5814686
Show file tree
Hide file tree
Showing 67 changed files with 241 additions and 179 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ alloy-node-bindings = { version = "0.1.0", default-features = false, path = "cra
alloy-provider = { version = "0.1.0", default-features = false, path = "crates/provider" }
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-types-eth = { version = "0.1.0", default-features = false, path = "crates/rpc-types-eth" }
alloy-rpc-types-engine = { version = "0.1.0", default-features = false, path = "crates/rpc-types-engine" }
alloy-rpc-types-anvil = { version = "0.1.0", default-features = false, path = "crates/rpc-types-anvil" }
alloy-rpc-types-beacon = { version = "0.1.0", default-features = false, path = "crates/rpc-types-beacon" }
Expand Down Expand Up @@ -119,7 +120,10 @@ url = "2.5"
derive_more = "0.99.17"

## serde
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde = { version = "1.0", default-features = false, features = [
"derive",
"alloc",
] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
serde_with = "3.3.0"

Expand Down
32 changes: 15 additions & 17 deletions crates/alloy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ 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-types-anvil = { workspace = true, default-features = false, optional = true }
alloy-rpc-types-beacon = { workspace = true, default-features = false, optional = true }
alloy-rpc-types-engine = { workspace = true, default-features = false, optional = true }
alloy-rpc-types-trace = { workspace = true, default-features = false, optional = true }
alloy-rpc-types = { workspace = true, default-features = false, optional = true }

# serde
Expand Down Expand Up @@ -121,16 +117,13 @@ json-rpc = ["rpc", "dep:alloy-json-rpc"]
rpc-client = ["rpc", "dep:alloy-rpc-client"]
rpc-client-ws = ["rpc", "alloy-rpc-client?/ws"]
rpc-client-ipc = ["rpc", "alloy-rpc-client?/ipc"]
rpc-types = ["rpc"]
rpc-types-anvil = ["rpc-types", "dep:alloy-rpc-types-anvil"]
rpc-types-eth = ["rpc-types", "dep:alloy-rpc-types"]
rpc-types-beacon = ["rpc-types", "dep:alloy-rpc-types-beacon"]
rpc-types-engine = ["rpc-types", "dep:alloy-rpc-types-engine"]
rpc-types-json = [
"alloy-rpc-types?/jsonrpsee-types",
"alloy-rpc-types-engine?/jsonrpsee-types",
]
rpc-types-trace = ["rpc-types", "dep:alloy-rpc-types-trace"]
rpc-types = ["rpc", "dep:alloy-rpc-types", "alloy-rpc-types?/eth"]
rpc-types-anvil = ["rpc-types", "alloy-rpc-types?/anvil"]
rpc-types-beacon = ["rpc-types", "alloy-rpc-types?/beacon"]
rpc-types-engine = ["rpc-types", "alloy-rpc-types?/engine"]
rpc-types-eth = ["rpc-types", "alloy-rpc-types?/eth"]
rpc-types-json = ["rpc-types", "alloy-rpc-types?/jsonrpsee-types"]
rpc-types-trace = ["rpc-types", "alloy-rpc-types?/trace"]

# signers
signers = ["dep:alloy-signer"]
Expand Down Expand Up @@ -172,15 +165,20 @@ getrandom = ["alloy-core/getrandom"]
rand = ["alloy-core/rand"]
rlp = ["alloy-core/rlp"]
serde = ["alloy-core/serde", "alloy-eips?/serde", "alloy-serde"]
ssz = ["alloy-core/ssz", "alloy-rpc-types?/ssz", "alloy-rpc-types-engine?/ssz"]
ssz = ["alloy-core/ssz", "alloy-rpc-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"]
kzg = ["alloy-consensus?/kzg"]
k256 = [
"alloy-core/k256",
"alloy-consensus?/k256",
"alloy-network?/k256",
"alloy-rpc-types?/k256",
]
kzg = ["alloy-consensus?/kzg", "alloy-rpc-types?/kzg"]
eip712 = [
"alloy-core/eip712",
"alloy-signer?/eip712",
Expand Down
23 changes: 2 additions & 21 deletions crates/alloy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,8 @@ pub mod rpc {

/// Ethereum JSON-RPC type definitions.
#[cfg(feature = "rpc-types")]
pub mod types {
#[cfg(feature = "rpc-types-anvil")]
#[doc(inline)]
pub use alloy_rpc_types_anvil as anvil;

#[cfg(feature = "rpc-types-beacon")]
#[doc(inline)]
pub use alloy_rpc_types_beacon as beacon;

#[cfg(feature = "rpc-types-engine")]
#[doc(inline)]
pub use alloy_rpc_types_engine as engine;

#[cfg(feature = "rpc-types-eth")]
#[doc(inline)]
pub use alloy_rpc_types as eth;

#[cfg(feature = "rpc-types-trace")]
#[doc(inline)]
pub use alloy_rpc_types_trace as trace;
}
#[doc(inline)]
pub use alloy_rpc_types as types;
}

#[cfg(feature = "serde")]
Expand Down
2 changes: 1 addition & 1 deletion crates/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspace = true
[dependencies]
alloy-network.workspace = true
alloy-provider.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-transport.workspace = true

alloy-dyn-abi = { workspace = true, features = ["std"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_json_abi::Function;
use alloy_network::{Ethereum, Network, ReceiptResponse, TransactionBuilder};
use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256};
use alloy_provider::{PendingTransactionBuilder, Provider};
use alloy_rpc_types::{state::StateOverride, AccessList, BlobTransactionSidecar, BlockId};
use alloy_rpc_types_eth::{state::StateOverride, AccessList, BlobTransactionSidecar, BlockId};
use alloy_sol_types::SolCall;
use alloy_transport::Transport;
use std::{
Expand Down Expand Up @@ -546,7 +546,7 @@ mod tests {
use alloy_provider::{
layers::AnvilProvider, Provider, ProviderBuilder, RootProvider, WalletProvider,
};
use alloy_rpc_types::AccessListItem;
use alloy_rpc_types_eth::AccessListItem;
use alloy_sol_types::sol;
use alloy_transport_http::Http;
use reqwest::Client;
Expand Down
2 changes: 1 addition & 1 deletion crates/contract/src/eth_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_dyn_abi::{DynSolValue, FunctionExt};
use alloy_json_abi::Function;
use alloy_network::Network;
use alloy_primitives::Bytes;
use alloy_rpc_types::{state::StateOverride, BlockId};
use alloy_rpc_types_eth::{state::StateOverride, BlockId};
use alloy_sol_types::SolCall;
use alloy_transport::Transport;

Expand Down
2 changes: 1 addition & 1 deletion crates/contract/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::Error;
use alloy_network::Ethereum;
use alloy_primitives::{Address, LogData};
use alloy_provider::{FilterPollerBuilder, Network, Provider};
use alloy_rpc_types::{Filter, Log};
use alloy_rpc_types_eth::{Filter, Log};
use alloy_sol_types::SolEvent;
use alloy_transport::{Transport, TransportResult};
use futures::Stream;
Expand Down
2 changes: 1 addition & 1 deletion crates/contract/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_json_abi::{Function, JsonAbi};
use alloy_network::{Ethereum, Network};
use alloy_primitives::{Address, Selector};
use alloy_provider::Provider;
use alloy_rpc_types::Filter;
use alloy_rpc_types_eth::Filter;
use alloy_sol_types::SolEvent;
use alloy_transport::Transport;
use std::marker::PhantomData;
Expand Down
2 changes: 1 addition & 1 deletion crates/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ alloy-consensus = { workspace = true, features = ["std"] }
alloy-eips = { workspace = true, features = ["serde"] }
alloy-json-rpc.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-signer.workspace = true
alloy-sol-types.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};

use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::Bytes;
use alloy_rpc_types::{AccessList, TransactionRequest, WithOtherFields};
use alloy_rpc_types_eth::{AccessList, TransactionRequest, WithOtherFields};

use crate::{any::AnyNetwork, BuildResult, Network, TransactionBuilder, TransactionBuilderError};

Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt;
use crate::{Network, ReceiptResponse, TransactionResponse};
use alloy_consensus::TxType;
use alloy_eips::eip2718::Eip2718Error;
use alloy_rpc_types::{
use alloy_rpc_types_eth::{
AnyTransactionReceipt, Header, Transaction, TransactionRequest, WithOtherFields,
};

Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
};
use alloy_consensus::{BlobTransactionSidecar, TxType, TypedTransaction};
use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256};
use alloy_rpc_types::{request::TransactionRequest, AccessList};
use alloy_rpc_types_eth::{request::TransactionRequest, AccessList};

impl TransactionBuilder<Ethereum> for TransactionRequest {
fn chain_id(&self) -> Option<ChainId> {
Expand Down Expand Up @@ -186,7 +186,7 @@ mod tests {
use crate::{TransactionBuilder, TransactionBuilderError};
use alloy_consensus::{BlobTransactionSidecar, TxEip1559, TxType, TypedTransaction};
use alloy_primitives::Address;
use alloy_rpc_types::{AccessList, TransactionRequest};
use alloy_rpc_types_eth::{AccessList, TransactionRequest};

#[test]
fn from_eip1559_to_tx_req() {
Expand Down
12 changes: 6 additions & 6 deletions crates/network/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ impl Network for Ethereum {

type Header = alloy_consensus::Header;

type TransactionRequest = alloy_rpc_types::transaction::TransactionRequest;
type TransactionRequest = alloy_rpc_types_eth::transaction::TransactionRequest;

type TransactionResponse = alloy_rpc_types::Transaction;
type TransactionResponse = alloy_rpc_types_eth::Transaction;

type ReceiptResponse = alloy_rpc_types::TransactionReceipt;
type ReceiptResponse = alloy_rpc_types_eth::TransactionReceipt;

type HeaderResponse = alloy_rpc_types::Header;
type HeaderResponse = alloy_rpc_types_eth::Header;
}

impl ReceiptResponse for alloy_rpc_types::TransactionReceipt {
impl ReceiptResponse for alloy_rpc_types_eth::TransactionReceipt {
fn contract_address(&self) -> Option<alloy_primitives::Address> {
self.contract_address
}
}

impl TransactionResponse for alloy_rpc_types::Transaction {
impl TransactionResponse for alloy_rpc_types_eth::Transaction {
#[doc(alias = "transaction_hash")]
fn tx_hash(&self) -> alloy_primitives::B256 {
self.hash
Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/ethereum/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl EthereumSigner {
/// [`TransactionRequest`] and [`TypedTransaction`] object that specify the
/// signer's address in the `from` field.
///
/// [`TransactionRequest`]: alloy_rpc_types::TransactionRequest
/// [`TransactionRequest`]: alloy_rpc_types_eth::TransactionRequest
pub fn register_signer<S>(&mut self, signer: S)
where
S: TxSigner<Signature> + Send + Sync + 'static,
Expand All @@ -58,7 +58,7 @@ impl EthereumSigner {
/// [`TypedTransaction`] objects that do not specify a signer address in the
/// `from` field.
///
/// [`TransactionRequest`]: alloy_rpc_types::TransactionRequest
/// [`TransactionRequest`]: alloy_rpc_types_eth::TransactionRequest
pub fn register_default_signer<S>(&mut self, signer: S)
where
S: TxSigner<Signature> + Send + Sync + 'static,
Expand Down
2 changes: 1 addition & 1 deletion crates/network/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::signer::NetworkSigner;
use crate::Network;
use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256};
use alloy_rpc_types::AccessList;
use alloy_rpc_types_eth::AccessList;
use alloy_sol_types::SolCall;
use futures_utils_wasm::impl_future;

Expand Down
2 changes: 1 addition & 1 deletion crates/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ alloy-node-bindings = { workspace = true, optional = true }
alloy-signer-wallet = { workspace = true, optional = true }
alloy-rpc-client.workspace = true
alloy-rpc-types-anvil = { workspace = true, optional = true }
alloy-rpc-types-eth.workspace = true
alloy-rpc-types-trace.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-engine = { workspace = true, optional = true }
alloy-transport-http = { workspace = true, optional = true }
alloy-transport-ipc = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Provider, RootProvider};
use alloy_network::{Ethereum, Network};
use alloy_primitives::{BlockNumber, U64};
use alloy_rpc_client::{PollerBuilder, WeakClient};
use alloy_rpc_types::Block;
use alloy_rpc_types_eth::Block;
use alloy_transport::{RpcError, Transport};
use async_stream::stream;
use futures::{Stream, StreamExt};
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/ext/admin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module extends the Ethereum JSON-RPC provider with the Admin namespace's RPC methods.
use crate::Provider;
use alloy_network::Network;
use alloy_rpc_types::admin::{NodeInfo, PeerInfo};
use alloy_rpc_types_eth::admin::{NodeInfo, PeerInfo};
use alloy_transport::{Transport, TransportResult};

/// Admin namespace rpc interface that gives access to several non-standard RPC methods.
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/ext/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::{Address, Bytes, TxHash, B256, U256};
use alloy_rpc_types::{Block, TransactionRequest, WithOtherFields};
use alloy_rpc_types_anvil::{Forking, Metadata, MineOptions, NodeInfo};
use alloy_rpc_types_eth::{Block, TransactionRequest, WithOtherFields};
use alloy_transport::{Transport, TransportResult};

/// Anvil namespace rpc interface that gives access to several non-standard RPC methods.
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/ext/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::{TxHash, B256};
use alloy_rpc_types::{BlockNumberOrTag, TransactionRequest};
use alloy_rpc_types_eth::{BlockNumberOrTag, TransactionRequest};
use alloy_rpc_types_trace::geth::{
GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/ext/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::Provider;
use alloy_network::{Ethereum, Network};
use alloy_primitives::Address;
use alloy_rpc_types::txpool::{TxpoolContent, TxpoolContentFrom, TxpoolInspect, TxpoolStatus};
use alloy_rpc_types_eth::txpool::{TxpoolContent, TxpoolContentFrom, TxpoolInspect, TxpoolStatus};
use alloy_transport::{Transport, TransportResult};

/// Txpool namespace rpc interface.
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
///
/// ```
/// # use alloy_network::{NetworkSigner, EthereumSigner, Ethereum};
/// # use alloy_rpc_types::TransactionRequest;
/// # use alloy_rpc_types_eth::TransactionRequest;
/// # use alloy_provider::{ProviderBuilder, RootProvider, Provider};
/// # async fn test<S: NetworkSigner<Ethereum> + Clone>(url: url::Url, signer: S) -> Result<(), Box<dyn std::error::Error>> {
/// let provider = ProviderBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions crates/provider/src/fillers/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use alloy_json_rpc::RpcError;
use alloy_network::{Network, TransactionBuilder};
use alloy_rpc_types::BlockNumberOrTag;
use alloy_rpc_types_eth::BlockNumberOrTag;
use alloy_transport::{Transport, TransportResult};
use futures::FutureExt;

Expand Down Expand Up @@ -50,7 +50,7 @@ pub enum GasFillable {
///
/// ```
/// # use alloy_network::{NetworkSigner, EthereumSigner, Ethereum};
/// # use alloy_rpc_types::TransactionRequest;
/// # use alloy_rpc_types_eth::TransactionRequest;
/// # use alloy_provider::{ProviderBuilder, RootProvider, Provider};
/// # async fn test<S: NetworkSigner<Ethereum> + Clone>(url: url::Url, signer: S) -> Result<(), Box<dyn std::error::Error>> {
/// let provider = ProviderBuilder::new()
Expand Down Expand Up @@ -256,7 +256,7 @@ mod tests {
use super::*;
use crate::{ProviderBuilder, WalletProvider};
use alloy_primitives::{address, U256};
use alloy_rpc_types::TransactionRequest;
use alloy_rpc_types_eth::TransactionRequest;

#[tokio::test]
async fn no_gas_price_or_limit() {
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/fillers/join_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use futures::try_join;
/// information by joining two [`TxFiller`]s. This struct is itself a
/// [`TxFiller`], and can be nested to compose any number of fill layers.
///
/// [`TransactionRequest`]: alloy_rpc_types::TransactionRequest
/// [`TransactionRequest`]: alloy_rpc_types_eth::TransactionRequest
#[derive(Clone, Copy, Debug)]
pub struct JoinFill<L, R> {
left: L,
Expand Down
4 changes: 2 additions & 2 deletions crates/provider/src/fillers/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use tokio::sync::Mutex;
///
/// ```
/// # use alloy_network::{NetworkSigner, EthereumSigner, Ethereum};
/// # use alloy_rpc_types::TransactionRequest;
/// # use alloy_rpc_types_eth::TransactionRequest;
/// # use alloy_provider::{ProviderBuilder, RootProvider, Provider};
/// # async fn test<S: NetworkSigner<Ethereum> + Clone>(url: url::Url, signer: S) -> Result<(), Box<dyn std::error::Error>> {
/// let provider = ProviderBuilder::new()
Expand Down Expand Up @@ -118,7 +118,7 @@ mod tests {
use super::*;
use crate::{ProviderBuilder, WalletProvider};
use alloy_primitives::{address, U256};
use alloy_rpc_types::TransactionRequest;
use alloy_rpc_types_eth::TransactionRequest;

#[tokio::test]
async fn no_nonce_if_sender_unset() {
Expand Down
Loading

0 comments on commit 5814686

Please sign in to comment.