mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use slice arg for tx decoding (#13181)
This commit is contained in:
@ -32,7 +32,7 @@ where
|
||||
///
|
||||
/// Returns the hash of the transaction.
|
||||
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
|
||||
let recovered = recover_raw_transaction(tx.clone())?;
|
||||
let recovered = recover_raw_transaction(&tx)?;
|
||||
let pool_transaction = <Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
|
||||
|
||||
// On optimism, transactions are forwarded directly to the sequencer to be included in
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -171,8 +171,7 @@ where
|
||||
while idx < body.len() {
|
||||
match &body[idx] {
|
||||
BundleItem::Tx { tx, can_revert } => {
|
||||
let recovered_tx =
|
||||
recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx.clone())
|
||||
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> =
|
||||
|
||||
@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user