Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
danyalprout committed Feb 4, 2025
1 parent 62104b4 commit 04634f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod rpc;

use crate::rpc::{BaseApiExt, BaseApiServer, EthApiExt, EthApiOverrideServer};
use clap::Parser;
use reth::builder::Node;
use reth::{
Expand All @@ -9,11 +10,9 @@ use reth::{
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
use reth_optimism_node::args::RollupArgs;
use reth_optimism_node::OpNode;
use crate::rpc::{BaseApiExt, BaseApiServer, EthApiExt, EthApiOverrideServer};
use tracing::info;

fn main() {

Cli::<OpChainSpecParser, RollupArgs>::parse()
.run(|builder, rollup_args| async move {
info!("Starting custom Base node");
Expand All @@ -27,11 +26,9 @@ fn main() {
.on_component_initialized(move |_ctx| Ok(()))
.extend_rpc_modules(move |ctx| {
let api_ext = EthApiExt::new(ctx.registry.eth_api().clone());
ctx.modules.replace_configured(
api_ext.into_rpc()
)?;
ctx.modules.replace_configured(api_ext.into_rpc())?;

let base_ext = BaseApiExt{};
let base_ext = BaseApiExt {};
ctx.modules.merge_http(base_ext.into_rpc())?;

Ok(())
Expand Down
27 changes: 18 additions & 9 deletions src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use jsonrpsee::{core::{async_trait, RpcResult}, proc_macros::rpc};
use reth_rpc_eth_api::{
helpers::{FullEthApi}, RpcBlock
};
use tracing::info;
use alloy_eips::BlockNumberOrTag;
use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
};
use op_alloy_network::Optimism;
use reth_rpc_eth_api::{helpers::FullEthApi, RpcBlock};
use serde::{Deserialize, Serialize};
use tracing::info;

#[cfg_attr(not(test), rpc(server, namespace = "eth"))]
#[cfg_attr(test, rpc(server, client, namespace = "eth"))]
pub trait EthApiOverride {
#[method(name = "getBlockByNumber")]
async fn block_by_number(&self, number: BlockNumberOrTag, full: bool) -> RpcResult<Option<RpcBlock<Optimism>>>;
async fn block_by_number(
&self,
number: BlockNumberOrTag,
full: bool,
) -> RpcResult<Option<RpcBlock<Optimism>>>;
}

#[derive(Debug)]
Expand All @@ -30,7 +35,11 @@ impl<Eth> EthApiOverrideServer for EthApiExt<Eth>
where
Eth: FullEthApi + Send + Sync + 'static,
{
async fn block_by_number(&self, number: BlockNumberOrTag, _full: bool) -> RpcResult<Option<RpcBlock<Optimism>>> {
async fn block_by_number(
&self,
number: BlockNumberOrTag,
_full: bool,
) -> RpcResult<Option<RpcBlock<Optimism>>> {
match number {
BlockNumberOrTag::Pending => {
info!("pending block by number, delegating to flashblocks");
Expand All @@ -46,7 +55,7 @@ where

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Status {
pub name: String
pub name: String,
}

#[cfg_attr(not(test), rpc(server, namespace = "base"))]
Expand All @@ -63,4 +72,4 @@ impl BaseApiServer for BaseApiExt {
async fn status(&self, name: String) -> RpcResult<Status> {
Ok(Status { name: name.into() })
}
}
}

0 comments on commit 04634f9

Please sign in to comment.