mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: op eth api scaffolding (#9324)
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -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"
|
||||
|
||||
@ -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
crates/optimism/rpc/src/eth/mod.rs
Normal file
56
crates/optimism/rpc/src/eth/mod.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user