mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): add HlBlockPrecompile rpc API
This commit is contained in:
@ -12,6 +12,7 @@ use reth_hl::{
|
|||||||
chainspec::{parser::HlChainSpecParser, HlChainSpec},
|
chainspec::{parser::HlChainSpecParser, HlChainSpec},
|
||||||
node::{
|
node::{
|
||||||
cli::{Cli, HlNodeArgs},
|
cli::{Cli, HlNodeArgs},
|
||||||
|
rpc::precompile::{HlBlockPrecompileApiServer, HlBlockPrecompileExt},
|
||||||
storage::tables::Tables,
|
storage::tables::Tables,
|
||||||
HlNode,
|
HlNode,
|
||||||
},
|
},
|
||||||
@ -72,6 +73,10 @@ fn main() -> eyre::Result<()> {
|
|||||||
info!("eth_getProof is disabled by default");
|
info!("eth_getProof is disabled by default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.modules.merge_configured(
|
||||||
|
HlBlockPrecompileExt::new(ctx.registry.eth_api().clone()).into_rpc(),
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.apply(|builder| {
|
.apply(|builder| {
|
||||||
|
|||||||
@ -43,6 +43,7 @@ mod block;
|
|||||||
mod call;
|
mod call;
|
||||||
pub mod engine_api;
|
pub mod engine_api;
|
||||||
mod estimate;
|
mod estimate;
|
||||||
|
pub mod precompile;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
|
|
||||||
pub trait HlRpcNodeCore: RpcNodeCore<Primitives: NodePrimitives<Block = HlBlock>> {}
|
pub trait HlRpcNodeCore: RpcNodeCore<Primitives: NodePrimitives<Block = HlBlock>> {}
|
||||||
|
|||||||
44
src/node/rpc/precompile.rs
Normal file
44
src/node/rpc/precompile.rs
Normal file
@ -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<HlExtras>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HlBlockPrecompileExt<N: HlRpcNodeCore, Rpc: RpcConvert> {
|
||||||
|
eth_api: HlEthApi<N, Rpc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<N: HlRpcNodeCore, Rpc: RpcConvert> HlBlockPrecompileExt<N, Rpc> {
|
||||||
|
/// Creates a new instance of the [`HlBlockPrecompileExt`].
|
||||||
|
pub fn new(eth_api: HlEthApi<N, Rpc>) -> Self {
|
||||||
|
Self { eth_api }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<N, Rpc> HlBlockPrecompileApiServer for HlBlockPrecompileExt<N, Rpc>
|
||||||
|
where
|
||||||
|
N: HlRpcNodeCore,
|
||||||
|
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
|
||||||
|
{
|
||||||
|
async fn block_precompile_data(&self, block_number: u64) -> RpcResult<HlExtras> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user