refactor(block): Inline from_block_with_transaction fn (#15788)

This commit is contained in:
0xMushow
2025-04-17 20:57:20 +02:00
committed by GitHub
parent 94ee821803
commit aee484ba82

View File

@@ -6,9 +6,7 @@ use alloy_primitives::U256;
use alloy_rpc_types_eth::{
Block, BlockTransactions, BlockTransactionsKind, Header, TransactionInfo,
};
use reth_primitives_traits::{
Block as BlockTrait, BlockBody, RecoveredBlock, SealedHeader, SignedTransaction,
};
use reth_primitives_traits::{Block as BlockTrait, BlockBody, RecoveredBlock, SignedTransaction};
/// Converts the given primitive block into a [`Block`] response with the given
/// [`BlockTransactionsKind`]
@@ -42,12 +40,16 @@ where
let transactions = block.body().transaction_hashes_iter().copied().collect();
let rlp_length = block.rlp_length();
let (header, body) = block.into_sealed_block().split_sealed_header_body();
from_block_with_transactions::<T, B>(
rlp_length,
header,
body,
BlockTransactions::Hashes(transactions),
)
let transactions = BlockTransactions::Hashes(transactions);
let withdrawals =
header.withdrawals_root().is_some().then(|| body.withdrawals().cloned()).flatten();
let uncles =
body.ommers().map(|o| o.iter().map(|h| h.hash_slow()).collect()).unwrap_or_default();
let header = Header::from_consensus(header.into(), None, Some(U256::from(rlp_length)));
Block { header, uncles, transactions, withdrawals }
}
/// Create a new [`Block`] response from a [`RecoveredBlock`], using the
@@ -86,21 +88,8 @@ where
.collect::<Result<Vec<_>, T::Error>>()?;
let (header, body) = block.into_sealed_block().split_sealed_header_body();
Ok(from_block_with_transactions::<_, B>(
block_length,
header,
body,
BlockTransactions::Full(transactions),
))
}
#[inline]
fn from_block_with_transactions<T, B: BlockTrait>(
block_length: usize,
header: SealedHeader<B::Header>,
body: B::Body,
transactions: BlockTransactions<T>,
) -> Block<T, Header<B::Header>> {
let transactions = BlockTransactions::Full(transactions);
let withdrawals =
header.withdrawals_root().is_some().then(|| body.withdrawals().cloned()).flatten();
@@ -108,5 +97,7 @@ fn from_block_with_transactions<T, B: BlockTrait>(
body.ommers().map(|o| o.iter().map(|h| h.hash_slow()).collect()).unwrap_or_default();
let header = Header::from_consensus(header.into(), None, Some(U256::from(block_length)));
Block { header, uncles, transactions, withdrawals }
let block = Block { header, uncles, transactions, withdrawals };
Ok(block)
}