mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: rakita <rakita@users.noreply.github.com>
86 lines
2.7 KiB
Rust
86 lines
2.7 KiB
Rust
//! Loads and formats OP block RPC response.
|
|
|
|
use alloy_consensus::{transaction::TransactionMeta, BlockHeader};
|
|
use alloy_rpc_types_eth::BlockId;
|
|
use op_alloy_rpc_types::OpTransactionReceipt;
|
|
use reth_chainspec::ChainSpecProvider;
|
|
use reth_node_api::BlockBody;
|
|
use reth_optimism_chainspec::OpChainSpec;
|
|
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
|
|
use reth_primitives_traits::SignedTransaction;
|
|
use reth_provider::{BlockReader, HeaderProvider};
|
|
use reth_rpc_eth_api::{
|
|
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
|
|
types::RpcTypes,
|
|
RpcReceipt,
|
|
};
|
|
|
|
use crate::{eth::OpNodeCore, OpEthApi, OpEthApiError, OpReceiptBuilder};
|
|
|
|
impl<N> EthBlocks for OpEthApi<N>
|
|
where
|
|
Self: LoadBlock<
|
|
Error = OpEthApiError,
|
|
NetworkTypes: RpcTypes<Receipt = OpTransactionReceipt>,
|
|
Provider: BlockReader<Receipt = OpReceipt, Transaction = OpTransactionSigned>,
|
|
>,
|
|
N: OpNodeCore<Provider: ChainSpecProvider<ChainSpec = OpChainSpec> + HeaderProvider>,
|
|
{
|
|
async fn block_receipts(
|
|
&self,
|
|
block_id: BlockId,
|
|
) -> Result<Option<Vec<RpcReceipt<Self::NetworkTypes>>>, Self::Error>
|
|
where
|
|
Self: LoadReceipt,
|
|
{
|
|
if let Some((block, receipts)) = self.load_block_and_receipts(block_id).await? {
|
|
let block_number = block.number();
|
|
let base_fee = block.base_fee_per_gas();
|
|
let block_hash = block.hash();
|
|
let excess_blob_gas = block.excess_blob_gas();
|
|
let timestamp = block.timestamp();
|
|
|
|
let mut l1_block_info = reth_optimism_evm::extract_l1_info(block.body())?;
|
|
|
|
return block
|
|
.body()
|
|
.transactions()
|
|
.iter()
|
|
.zip(receipts.iter())
|
|
.enumerate()
|
|
.map(|(idx, (tx, receipt))| -> Result<_, _> {
|
|
let meta = TransactionMeta {
|
|
tx_hash: *tx.tx_hash(),
|
|
index: idx as u64,
|
|
block_hash,
|
|
block_number,
|
|
base_fee,
|
|
excess_blob_gas,
|
|
timestamp,
|
|
};
|
|
|
|
Ok(OpReceiptBuilder::new(
|
|
&self.inner.eth_api.provider().chain_spec(),
|
|
tx,
|
|
meta,
|
|
receipt,
|
|
&receipts,
|
|
&mut l1_block_info,
|
|
)?
|
|
.build())
|
|
})
|
|
.collect::<Result<Vec<_>, Self::Error>>()
|
|
.map(Some)
|
|
}
|
|
|
|
Ok(None)
|
|
}
|
|
}
|
|
|
|
impl<N> LoadBlock for OpEthApi<N>
|
|
where
|
|
Self: LoadPendingBlock + SpawnBlocking,
|
|
N: OpNodeCore,
|
|
{
|
|
}
|