reth_seismic_rpc/eth/
block.rs

1//! Loads and formats Seismic block RPC response.
2
3use super::receipt::SeismicReceiptBuilder;
4use crate::{eth::SeismicNodeCore, SeismicEthApi};
5use alloy_consensus::{transaction::TransactionMeta, BlockHeader};
6use alloy_rpc_types_eth::BlockId;
7use reth_chainspec::{ChainSpec, ChainSpecProvider, EthChainSpec};
8use reth_node_api::BlockBody;
9use reth_primitives_traits::SignedTransaction;
10use reth_rpc_eth_api::{
11    helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
12    types::RpcTypes,
13    RpcNodeCore, RpcReceipt,
14};
15use reth_rpc_eth_types::EthApiError;
16use reth_seismic_primitives::{SeismicReceipt, SeismicTransactionSigned};
17use reth_storage_api::{BlockReader, HeaderProvider, ProviderTx};
18use reth_transaction_pool::{PoolTransaction, TransactionPool};
19use seismic_alloy_rpc_types::SeismicTransactionReceipt;
20
21impl<N> EthBlocks for SeismicEthApi<N>
22where
23    Self: LoadBlock<
24        Error = EthApiError,
25        NetworkTypes: RpcTypes<Receipt = SeismicTransactionReceipt>,
26        Provider: BlockReader<Receipt = SeismicReceipt, Transaction = SeismicTransactionSigned>,
27    >,
28    N: SeismicNodeCore<
29        Provider: BlockReader + ChainSpecProvider<ChainSpec = ChainSpec> + HeaderProvider,
30    >,
31{
32    async fn block_receipts(
33        &self,
34        block_id: BlockId,
35    ) -> Result<Option<Vec<RpcReceipt<Self::NetworkTypes>>>, Self::Error>
36    where
37        Self: LoadReceipt,
38    {
39        if let Some((block, receipts)) = self.load_block_and_receipts(block_id).await? {
40            let block_number = block.number();
41            let base_fee = block.base_fee_per_gas();
42            let block_hash = block.hash();
43            let excess_blob_gas = block.excess_blob_gas();
44            let timestamp = block.timestamp();
45            let blob_params = self.provider().chain_spec().blob_params_at_timestamp(timestamp);
46
47            return block
48                .body()
49                .transactions()
50                .iter()
51                .zip(receipts.iter())
52                .enumerate()
53                .map(|(idx, (tx, receipt))| {
54                    let meta = TransactionMeta {
55                        tx_hash: *tx.tx_hash(),
56                        index: idx as u64,
57                        block_hash,
58                        block_number,
59                        base_fee,
60                        excess_blob_gas,
61                        timestamp,
62                    };
63                    SeismicReceiptBuilder::new(tx, meta, receipt, &receipts, blob_params)
64                        .map(|builder| builder.build())
65                })
66                .collect::<Result<Vec<_>, Self::Error>>()
67                .map(Some)
68        }
69
70        Ok(None)
71    }
72}
73
74impl<N> LoadBlock for SeismicEthApi<N>
75where
76    Self: LoadPendingBlock<
77            Pool: TransactionPool<
78                Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
79            >,
80        > + SpawnBlocking,
81    N: SeismicNodeCore,
82{
83}