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.
|
/// Returns the hash of the transaction.
|
||||||
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
|
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);
|
let pool_transaction = <Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
|
||||||
|
|
||||||
// On optimism, transactions are forwarded directly to the sequencer to be included in
|
// 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,
|
tx: Bytes,
|
||||||
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
|
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
|
||||||
async move {
|
async move {
|
||||||
let recovered = recover_raw_transaction(tx)?;
|
let recovered = recover_raw_transaction(&tx)?;
|
||||||
let pool_transaction =
|
let pool_transaction =
|
||||||
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
|
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
//! Commonly used code snippets
|
//! Commonly used code snippets
|
||||||
|
|
||||||
use alloy_primitives::Bytes;
|
use super::{EthApiError, EthResult};
|
||||||
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredTx};
|
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredTx};
|
||||||
use reth_primitives_traits::SignedTransaction;
|
use reth_primitives_traits::SignedTransaction;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
use super::{EthApiError, EthResult};
|
|
||||||
|
|
||||||
/// Recovers a [`SignedTransaction`] from an enveloped encoded byte stream.
|
/// 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`]
|
/// 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() {
|
if data.is_empty() {
|
||||||
return Err(EthApiError::EmptyRawTransactionData)
|
return Err(EthApiError::EmptyRawTransactionData)
|
||||||
}
|
}
|
||||||
|
|
||||||
let transaction = T::decode_2718(&mut data.as_ref())
|
let transaction =
|
||||||
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
|
T::decode_2718(&mut data).map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
|
||||||
|
|
||||||
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
|
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,7 +90,7 @@ where
|
|||||||
|
|
||||||
let transactions = txs
|
let transactions = txs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(recover_raw_transaction::<PoolPooledTx<Eth::Pool>>)
|
.map(|tx| recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx))
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
.collect::<Result<Vec<_>, _>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tx| tx.to_components())
|
.map(|tx| tx.to_components())
|
||||||
|
|||||||
@ -171,9 +171,8 @@ where
|
|||||||
while idx < body.len() {
|
while idx < body.len() {
|
||||||
match &body[idx] {
|
match &body[idx] {
|
||||||
BundleItem::Tx { tx, can_revert } => {
|
BundleItem::Tx { tx, can_revert } => {
|
||||||
let recovered_tx =
|
let recovered_tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)
|
||||||
recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx.clone())
|
.map_err(EthApiError::from)?;
|
||||||
.map_err(EthApiError::from)?;
|
|
||||||
let (tx, signer) = recovered_tx.to_components();
|
let (tx, signer) = recovered_tx.to_components();
|
||||||
let tx: PoolConsensusTx<Eth::Pool> =
|
let tx: PoolConsensusTx<Eth::Pool> =
|
||||||
<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx);
|
<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx);
|
||||||
|
|||||||
@ -117,7 +117,7 @@ where
|
|||||||
trace_types: HashSet<TraceType>,
|
trace_types: HashSet<TraceType>,
|
||||||
block_id: Option<BlockId>,
|
block_id: Option<BlockId>,
|
||||||
) -> Result<TraceResults, Eth::Error> {
|
) -> 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);
|
.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?;
|
let (cfg, block, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user