feat: op eth api scaffolding (#9324)

This commit is contained in:
Matthias Seitz
2024-07-05 13:05:23 +02:00
committed by GitHub
parent 36d74400e6
commit 3b29ed74c0
5 changed files with 85 additions and 1 deletions

10
Cargo.lock generated
View File

@ -7962,6 +7962,16 @@ version = "1.0.0"
[[package]] [[package]]
name = "reth-optimism-rpc" name = "reth-optimism-rpc"
version = "1.0.0" 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]] [[package]]
name = "reth-payload-builder" name = "reth-payload-builder"

View File

@ -8,3 +8,17 @@ homepage.workspace = true
repository.workspace = true repository.workspace = true
[lints] [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

View File

@ -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()
}
}

View File

@ -5,5 +5,7 @@
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" 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))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
pub mod eth;

View File

@ -47,6 +47,8 @@ pub trait TraceExt:
impl<T> TraceExt for T where T: LoadTransaction + LoadBlock + LoadPendingBlock + Trace + Call {} 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. /// 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: pub trait FullEthApi:
EthApiSpec + EthTransactions + EthBlocks + EthState + EthCall + EthFees + Trace + LoadReceipt EthApiSpec + EthTransactions + EthBlocks + EthState + EthCall + EthFees + Trace + LoadReceipt
{ {