chore(rpc): LoadReceipt::build_transaction_receipt default impl to impl for EthApi (#10786)

This commit is contained in:
Emilia Hane
2024-09-11 11:06:29 +02:00
committed by GitHub
parent d9681ea729
commit bbaccc2a3a
2 changed files with 25 additions and 18 deletions

View File

@ -3,10 +3,10 @@
use futures::Future;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned};
use reth_rpc_eth_types::{EthApiError, EthStateCache, ReceiptBuilder};
use reth_rpc_eth_types::EthStateCache;
use reth_rpc_types::AnyTransactionReceipt;
use crate::{EthApiTypes, FromEthApiError};
use crate::EthApiTypes;
/// Assembles transaction receipt data w.r.t to network.
///
@ -23,18 +23,5 @@ pub trait LoadReceipt: EthApiTypes + Send + Sync {
tx: TransactionSigned,
meta: TransactionMeta,
receipt: Receipt,
) -> impl Future<Output = Result<AnyTransactionReceipt, Self::Error>> + Send {
async move {
let hash = meta.block_hash;
// get all receipts for the block
let all_receipts = self
.cache()
.get_receipts(hash)
.await
.map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(hash.into()))?;
Ok(ReceiptBuilder::new(&tx, meta, &receipt, &all_receipts)?.build())
}
}
) -> impl Future<Output = Result<AnyTransactionReceipt, Self::Error>> + Send;
}

View File

@ -1,7 +1,9 @@
//! Builds an RPC receipt response w.r.t. data layout of network.
use reth_rpc_eth_api::helpers::LoadReceipt;
use reth_rpc_eth_types::EthStateCache;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned};
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError};
use reth_rpc_eth_types::{EthApiError, EthStateCache, ReceiptBuilder};
use reth_rpc_types::AnyTransactionReceipt;
use crate::EthApi;
@ -13,4 +15,22 @@ where
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}
async fn build_transaction_receipt(
&self,
tx: TransactionSigned,
meta: TransactionMeta,
receipt: Receipt,
) -> Result<AnyTransactionReceipt, Self::Error> {
let hash = meta.block_hash;
// get all receipts for the block
let all_receipts = self
.cache()
.get_receipts(hash)
.await
.map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(hash.into()))?;
Ok(ReceiptBuilder::new(&tx, meta, &receipt, &all_receipts)?.build())
}
}