mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 15:28:01 -05:00
Merge pull request #69 from okx/lucas/fb-get-block-tx-count
fix: update according to review
This commit is contained in:
@@ -1,54 +1,17 @@
|
||||
//! Loads and formats OP block RPC response.
|
||||
|
||||
use crate::{eth::RpcNodeCore, OpEthApi, OpEthApiError};
|
||||
use reth_node_api::BlockBody;
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{EthBlocks, LoadBlock},
|
||||
FromEthApiError, FromEvmError, RpcConvert, RpcNodeCoreExt,
|
||||
FromEvmError, RpcConvert,
|
||||
};
|
||||
use reth_storage_api::{BlockIdReader, BlockReader};
|
||||
|
||||
impl<N, Rpc> EthBlocks for OpEthApi<N, Rpc>
|
||||
where
|
||||
N: RpcNodeCore,
|
||||
OpEthApiError: FromEvmError<N::Evm>,
|
||||
Rpc: RpcConvert<Primitives = N::Primitives, Error = OpEthApiError>,
|
||||
{
|
||||
fn block_transaction_count(
|
||||
&self,
|
||||
block_id: alloy_eips::BlockId,
|
||||
) -> impl std::future::Future<Output = Result<Option<usize>, Self::Error>> + Send {
|
||||
async move {
|
||||
if block_id.is_pending() {
|
||||
if let Ok(Some(pending)) = self.pending_flashblock().await {
|
||||
return Ok(Some(pending.block().body().transaction_count()));
|
||||
}
|
||||
|
||||
if let Some(pending_block) =
|
||||
self.provider().pending_block().map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
return Ok(Some(pending_block.body().transaction_count()));
|
||||
}
|
||||
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let block_hash = match self
|
||||
.provider()
|
||||
.block_hash_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
Some(block_hash) => block_hash,
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
Ok(self
|
||||
.cache()
|
||||
.get_recovered_block(block_hash)
|
||||
.await
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.map(|b| b.body().transaction_count()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, Rpc> LoadBlock for OpEthApi<N, Rpc>
|
||||
|
||||
@@ -74,13 +74,9 @@ pub trait EthBlocks: LoadBlock<RpcConvert: RpcConvert<Primitives = Self::Primiti
|
||||
block_id: BlockId,
|
||||
) -> impl Future<Output = Result<Option<usize>, Self::Error>> + Send {
|
||||
async move {
|
||||
if block_id.is_pending() {
|
||||
// Pending block can be fetched directly without need for caching
|
||||
return Ok(self
|
||||
.provider()
|
||||
.pending_block()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.map(|block| block.body().transaction_count()));
|
||||
// If no pending block from provider, build the pending block locally.
|
||||
if let Some(pending) = self.local_pending_block().await? {
|
||||
return Ok(Some(pending.block.body().transaction_count()));
|
||||
}
|
||||
|
||||
let block_hash = match self
|
||||
|
||||
Reference in New Issue
Block a user