chore: use slice arg for tx decoding (#13181)

This commit is contained in:
Matthias Seitz
2024-12-06 17:21:04 +01:00
committed by GitHub
parent e29b4eec48
commit 806a1b1e88
6 changed files with 13 additions and 13 deletions

View File

@ -343,7 +343,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
tx: Bytes,
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
async move {
let recovered = recover_raw_transaction(tx)?;
let recovered = recover_raw_transaction(&tx)?;
let pool_transaction =
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

View File

@ -1,22 +1,23 @@
//! Commonly used code snippets
use alloy_primitives::Bytes;
use super::{EthApiError, EthResult};
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredTx};
use reth_primitives_traits::SignedTransaction;
use std::future::Future;
use super::{EthApiError, EthResult};
/// Recovers a [`SignedTransaction`] from an enveloped encoded byte stream.
///
/// This is a helper function that returns the appropriate RPC-specific error if the input data is
/// malformed.
///
/// See [`alloy_eips::eip2718::Decodable2718::decode_2718`]
pub fn recover_raw_transaction<T: SignedTransaction>(data: Bytes) -> EthResult<RecoveredTx<T>> {
pub fn recover_raw_transaction<T: SignedTransaction>(mut data: &[u8]) -> EthResult<RecoveredTx<T>> {
if data.is_empty() {
return Err(EthApiError::EmptyRawTransactionData)
}
let transaction = T::decode_2718(&mut data.as_ref())
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
let transaction =
T::decode_2718(&mut data).map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
}

View File

@ -90,7 +90,7 @@ where
let transactions = txs
.into_iter()
.map(recover_raw_transaction::<PoolPooledTx<Eth::Pool>>)
.map(|tx| recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|tx| tx.to_components())

View File

@ -171,9 +171,8 @@ where
while idx < body.len() {
match &body[idx] {
BundleItem::Tx { tx, can_revert } => {
let recovered_tx =
recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx.clone())
.map_err(EthApiError::from)?;
let recovered_tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)
.map_err(EthApiError::from)?;
let (tx, signer) = recovered_tx.to_components();
let tx: PoolConsensusTx<Eth::Pool> =
<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx);

View File

@ -117,7 +117,7 @@ where
trace_types: HashSet<TraceType>,
block_id: Option<BlockId>,
) -> Result<TraceResults, Eth::Error> {
let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)?
let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx)?
.map_transaction(<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus);
let (cfg, block, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?;