Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: op eth api scaffolding #9324

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 56 additions & 0 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Eth> {
inner: Eth,
}

impl<Eth> OpEthApi<Eth> {
/// Creates a new `OpEthApi` from the provided `Eth` implementation.
pub const fn new(inner: Eth) -> Self {
Self { inner }
}
}

impl<Eth: EthApiSpec> EthApiSpec for OpEthApi<Eth> {
fn protocol_version(&self) -> impl Future<Output = RethResult<U64>> + Send {
self.inner.protocol_version()
}

fn chain_id(&self) -> U64 {
self.inner.chain_id()
}

fn chain_info(&self) -> RethResult<ChainInfo> {
self.inner.chain_info()
}

fn accounts(&self) -> Vec<Address> {
self.inner.accounts()
}

fn is_syncing(&self) -> bool {
self.inner.is_syncing()
}

fn sync_status(&self) -> RethResult<SyncStatus> {
self.inner.sync_status()
}
}
4 changes: 3 additions & 1 deletion crates/optimism/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions crates/rpc/rpc-eth-api/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub trait TraceExt:
impl<T> 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
{
Expand Down
Loading