diff --git a/Cargo.lock b/Cargo.lock index 76b82e90f..e17cbbe10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7962,6 +7962,16 @@ version = "1.0.0" [[package]] name = "reth-optimism-rpc" version = "1.0.0" +dependencies = [ + "alloy-primitives", + "reth-chainspec", + "reth-errors", + "reth-rpc", + "reth-rpc-eth-api", + "reth-rpc-eth-types", + "reth-rpc-server-types", + "reth-rpc-types", +] [[package]] name = "reth-payload-builder" diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index f6645519e..9853e8f91 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -8,3 +8,17 @@ homepage.workspace = true repository.workspace = true [lints] +workspace = true + +[dependencies] +# reth +reth-rpc.workspace = true +reth-rpc-eth-api.workspace = true +reth-rpc-eth-types.workspace = true +reth-rpc-server-types.workspace = true +reth-rpc-types.workspace = true +reth-errors.workspace = true +reth-chainspec.workspace = true + +# ethereum +alloy-primitives.workspace = true \ No newline at end of file diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs new file mode 100644 index 000000000..b9836360a --- /dev/null +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -0,0 +1,56 @@ +//! OP-Reth `eth_` endpoint implementation. + +use alloy_primitives::{Address, U64}; +use reth_chainspec::ChainInfo; +use reth_errors::RethResult; +use reth_rpc_eth_api::helpers::EthApiSpec; +use reth_rpc_types::SyncStatus; +use std::future::Future; + +/// OP-Reth `Eth` API implementation. +/// +/// This type provides the functionality for handling `eth_` related requests. +/// +/// This wraps a default `Eth` implementation, and provides additional functionality where the +/// optimism spec deviates from the default (ethereum) spec, e.g. transaction forwarding to the +/// sequencer, receipts, additional RPC fields for transaction receipts. +/// +/// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented +/// all the `Eth` helper traits and prerequisite traits. +#[derive(Debug, Clone)] +pub struct OpEthApi { + inner: Eth, +} + +impl OpEthApi { + /// Creates a new `OpEthApi` from the provided `Eth` implementation. + pub const fn new(inner: Eth) -> Self { + Self { inner } + } +} + +impl EthApiSpec for OpEthApi { + fn protocol_version(&self) -> impl Future> + Send { + self.inner.protocol_version() + } + + fn chain_id(&self) -> U64 { + self.inner.chain_id() + } + + fn chain_info(&self) -> RethResult { + self.inner.chain_info() + } + + fn accounts(&self) -> Vec
{ + self.inner.accounts() + } + + fn is_syncing(&self) -> bool { + self.inner.is_syncing() + } + + fn sync_status(&self) -> RethResult { + self.inner.sync_status() + } +} diff --git a/crates/optimism/rpc/src/lib.rs b/crates/optimism/rpc/src/lib.rs index f263793af..f2059fac1 100644 --- a/crates/optimism/rpc/src/lib.rs +++ b/crates/optimism/rpc/src/lib.rs @@ -5,5 +5,7 @@ html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] -#![cfg_attr(not(test), warn(unused_crate_dependencies))] +// #![cfg_attr(not(test), warn(unused_crate_dependencies))] TODO: enable #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +pub mod eth; diff --git a/crates/rpc/rpc-eth-api/src/helpers/mod.rs b/crates/rpc/rpc-eth-api/src/helpers/mod.rs index d7d31320c..72e49077e 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/mod.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/mod.rs @@ -47,6 +47,8 @@ pub trait TraceExt: impl TraceExt for T where T: LoadTransaction + LoadBlock + LoadPendingBlock + Trace + Call {} /// Helper trait to unify all `eth` rpc server building block traits, for simplicity. +/// +/// This trait is automatically implemented for any type that implements all the `Eth` traits. pub trait FullEthApi: EthApiSpec + EthTransactions + EthBlocks + EthState + EthCall + EthFees + Trace + LoadReceipt {