diff --git a/src/main.rs b/src/main.rs index a223874ea..0062a49cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use reth_hl::{ chainspec::{parser::HlChainSpecParser, HlChainSpec}, node::{ cli::{Cli, HlNodeArgs}, + rpc::precompile::{HlBlockPrecompileApiServer, HlBlockPrecompileExt}, storage::tables::Tables, HlNode, }, @@ -72,6 +73,10 @@ fn main() -> eyre::Result<()> { info!("eth_getProof is disabled by default"); } + ctx.modules.merge_configured( + HlBlockPrecompileExt::new(ctx.registry.eth_api().clone()).into_rpc(), + )?; + Ok(()) }) .apply(|builder| { diff --git a/src/node/rpc/mod.rs b/src/node/rpc/mod.rs index 30c8754f4..4fe7f3873 100644 --- a/src/node/rpc/mod.rs +++ b/src/node/rpc/mod.rs @@ -43,6 +43,7 @@ mod block; mod call; pub mod engine_api; mod estimate; +pub mod precompile; mod transaction; pub trait HlRpcNodeCore: RpcNodeCore> {} diff --git a/src/node/rpc/precompile.rs b/src/node/rpc/precompile.rs new file mode 100644 index 000000000..44a89d0c6 --- /dev/null +++ b/src/node/rpc/precompile.rs @@ -0,0 +1,44 @@ +use jsonrpsee::proc_macros::rpc; +use jsonrpsee_core::{async_trait, RpcResult}; +use reth_rpc_convert::RpcConvert; +use reth_rpc_eth_types::EthApiError; +use tracing::trace; + +use crate::node::{ + rpc::{HlEthApi, HlRpcNodeCore}, + types::HlExtras, +}; + +/// A custom RPC trait for fetching block precompile data. +#[rpc(server, namespace = "eth")] +#[async_trait] +pub trait HlBlockPrecompileApi { + /// Fetches precompile data for a given block number. + #[method(name = "blockPrecompileData")] + async fn block_precompile_data(&self, block_number: u64) -> RpcResult; +} + +pub struct HlBlockPrecompileExt { + eth_api: HlEthApi, +} + +impl HlBlockPrecompileExt { + /// Creates a new instance of the [`HlBlockPrecompileExt`]. + pub fn new(eth_api: HlEthApi) -> Self { + Self { eth_api } + } +} + +#[async_trait] +impl HlBlockPrecompileApiServer for HlBlockPrecompileExt +where + N: HlRpcNodeCore, + Rpc: RpcConvert, +{ + async fn block_precompile_data(&self, block_number: u64) -> RpcResult { + trace!(target: "rpc::eth", block_number, "Serving eth_blockPrecompileData"); + let hl_extras = + self.eth_api.get_hl_extras(block_number).map_err(|e| EthApiError::from(e))?; + Ok(hl_extras) + } +}