refactor: use BlockId as block type

This commit is contained in:
Quertyy
2025-09-19 12:41:14 +07:00
parent 458f506ad2
commit 4896e4f0ea
2 changed files with 9 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use crate::{
node::{evm::apply_precompiles, types::HlExtras}, node::{evm::apply_precompiles, types::HlExtras},
HlBlock, HlPrimitives, HlBlock, HlPrimitives,
}; };
use alloy_eips::BlockHashOrNumber; use alloy_eips::BlockId;
use alloy_evm::Evm; use alloy_evm::Evm;
use alloy_network::Ethereum; use alloy_network::Ethereum;
use alloy_primitives::U256; use alloy_primitives::U256;
@ -27,7 +27,9 @@ use reth::{
}; };
use reth_evm::{ConfigureEvm, Database, EvmEnvFor, HaltReasonFor, InspectorFor, TxEnvFor}; use reth_evm::{ConfigureEvm, Database, EvmEnvFor, HaltReasonFor, InspectorFor, TxEnvFor};
use reth_primitives::NodePrimitives; use reth_primitives::NodePrimitives;
use reth_provider::{BlockReader, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx}; use reth_provider::{
BlockReaderIdExt, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx,
};
use reth_rpc::RpcTypes; use reth_rpc::RpcTypes;
use reth_rpc_eth_api::{ use reth_rpc_eth_api::{
helpers::{ helpers::{
@ -247,10 +249,10 @@ where
N: HlRpcNodeCore, N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>, Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{ {
fn get_hl_extras(&self, block: BlockHashOrNumber) -> Result<HlExtras, ProviderError> { fn get_hl_extras(&self, block: BlockId) -> Result<HlExtras, ProviderError> {
Ok(self Ok(self
.provider() .provider()
.block(block)? .block_by_id(block)?
.map(|block| HlExtras { .map(|block| HlExtras {
read_precompile_calls: block.body.read_precompile_calls.clone(), read_precompile_calls: block.body.read_precompile_calls.clone(),
highest_precompile_address: block.body.highest_precompile_address, highest_precompile_address: block.body.highest_precompile_address,

View File

@ -1,4 +1,4 @@
use alloy_eips::BlockHashOrNumber; use alloy_eips::BlockId;
use jsonrpsee::proc_macros::rpc; use jsonrpsee::proc_macros::rpc;
use jsonrpsee_core::{async_trait, RpcResult}; use jsonrpsee_core::{async_trait, RpcResult};
use reth_rpc_convert::RpcConvert; use reth_rpc_convert::RpcConvert;
@ -16,7 +16,7 @@ use crate::node::{
pub trait HlBlockPrecompileApi { pub trait HlBlockPrecompileApi {
/// Fetches precompile data for a given block. /// Fetches precompile data for a given block.
#[method(name = "blockPrecompileData")] #[method(name = "blockPrecompileData")]
async fn block_precompile_data(&self, block: BlockHashOrNumber) -> RpcResult<HlExtras>; async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras>;
} }
pub struct HlBlockPrecompileExt<N: HlRpcNodeCore, Rpc: RpcConvert> { pub struct HlBlockPrecompileExt<N: HlRpcNodeCore, Rpc: RpcConvert> {
@ -36,7 +36,7 @@ where
N: HlRpcNodeCore, N: HlRpcNodeCore,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>, Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{ {
async fn block_precompile_data(&self, block: BlockHashOrNumber) -> RpcResult<HlExtras> { async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras> {
trace!(target: "rpc::eth", ?block, "Serving eth_blockPrecompileData"); trace!(target: "rpc::eth", ?block, "Serving eth_blockPrecompileData");
let hl_extras = self.eth_api.get_hl_extras(block).map_err(|e| EthApiError::from(e))?; let hl_extras = self.eth_api.get_hl_extras(block).map_err(|e| EthApiError::from(e))?;
Ok(hl_extras) Ok(hl_extras)