Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use generics for RecoveredTx #13650

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ mod tests {
}

let single_tx_cost = U256::from(INITIAL_BASE_FEE * MIN_TRANSACTION_GAS);
let mock_tx = |nonce: u64| -> RecoveredTx {
let mock_tx = |nonce: u64| -> RecoveredTx<_> {
TransactionSigned::new_unhashed(
Transaction::Eip1559(TxEip1559 {
chain_id: chain_spec.chain.id(),
Expand All @@ -1589,7 +1589,7 @@ mod tests {

let mock_block = |number: u64,
parent: Option<B256>,
body: Vec<RecoveredTx>,
body: Vec<RecoveredTx<TransactionSigned>>,
num_of_signer_txs: u64|
-> SealedBlockWithSenders {
let signed_body =
Expand Down
4 changes: 2 additions & 2 deletions crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
) -> SealedBlockWithSenders {
let mut rng = thread_rng();

let mock_tx = |nonce: u64| -> RecoveredTx {
let mock_tx = |nonce: u64| -> RecoveredTx<_> {
let tx = Transaction::Eip1559(TxEip1559 {
chain_id: self.chain_spec.chain.id(),
nonce,
Expand All @@ -112,7 +112,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {

let num_txs = rng.gen_range(0..5);
let signer_balance_decrease = Self::single_tx_cost() * U256::from(num_txs);
let transactions: Vec<RecoveredTx> = (0..num_txs)
let transactions: Vec<RecoveredTx<_>> = (0..num_txs)
.map(|_| {
let tx = mock_tx(self.signer_build_account_info.nonce);
self.signer_build_account_info.nonce += 1;
Expand Down
12 changes: 6 additions & 6 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,14 @@ impl TransactionSigned {

/// Returns the [`RecoveredTx`] transaction with the given sender.
#[inline]
pub const fn with_signer(self, signer: Address) -> RecoveredTx {
pub const fn with_signer(self, signer: Address) -> RecoveredTx<Self> {
RecoveredTx::from_signed_transaction(self, signer)
}

/// Consumes the type, recover signer and return [`RecoveredTx`]
///
/// Returns `None` if the transaction's signature is invalid, see also [`Self::recover_signer`].
pub fn into_ecrecovered(self) -> Option<RecoveredTx> {
pub fn into_ecrecovered(self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer()?;
Some(RecoveredTx { signed_transaction: self, signer })
}
Expand All @@ -928,7 +928,7 @@ impl TransactionSigned {
///
/// Returns `None` if the transaction's signature is invalid, see also
/// [`Self::recover_signer_unchecked`].
pub fn into_ecrecovered_unchecked(self) -> Option<RecoveredTx> {
pub fn into_ecrecovered_unchecked(self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer_unchecked()?;
Some(RecoveredTx { signed_transaction: self, signer })
}
Expand All @@ -938,7 +938,7 @@ impl TransactionSigned {
///
/// Returns `Err(Self)` if the transaction's signature is invalid, see also
/// [`Self::recover_signer_unchecked`].
pub fn try_into_ecrecovered_unchecked(self) -> Result<RecoveredTx, Self> {
pub fn try_into_ecrecovered_unchecked(self) -> Result<RecoveredTx<Self>, Self> {
match self.recover_signer_unchecked() {
None => Err(self),
Some(signer) => Ok(RecoveredTx { signed_transaction: self, signer }),
Expand Down Expand Up @@ -1182,8 +1182,8 @@ impl alloy_consensus::Transaction for TransactionSigned {
}
}

impl From<RecoveredTx> for TransactionSigned {
fn from(recovered: RecoveredTx) -> Self {
impl From<RecoveredTx<Self>> for TransactionSigned {
fn from(recovered: RecoveredTx<Self>) -> Self {
recovered.signed_transaction
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines the types for blob transactions, legacy, and other EIP-2718 transactions included in a
//! response to `GetPooledTransactions`.

use crate::RecoveredTx;
use crate::{RecoveredTx, TransactionSigned};
use alloy_consensus::transaction::PooledTransaction;
use alloy_eips::eip4844::BlobTransactionSidecar;
use reth_primitives_traits::transaction::error::TransactionConversionError;
Expand All @@ -11,7 +11,7 @@ pub type PooledTransactionsElementEcRecovered<T = PooledTransaction> = Recovered

impl PooledTransactionsElementEcRecovered {
/// Transform back to [`RecoveredTx`]
pub fn into_ecrecovered_transaction(self) -> RecoveredTx {
pub fn into_ecrecovered_transaction(self) -> RecoveredTx<TransactionSigned> {
let (tx, signer) = self.to_components();
RecoveredTx::from_signed_transaction(tx.into(), signer)
}
Expand All @@ -21,9 +21,9 @@ impl PooledTransactionsElementEcRecovered {
///
/// Returns the transaction is not an EIP-4844 transaction.
pub fn try_from_blob_transaction(
tx: RecoveredTx,
tx: RecoveredTx<TransactionSigned>,
sidecar: BlobTransactionSidecar,
) -> Result<Self, RecoveredTx> {
) -> Result<Self, RecoveredTx<TransactionSigned>> {
let RecoveredTx { signer, signed_transaction } = tx;
let transaction = signed_transaction
.try_into_pooled_eip4844(sidecar)
Expand All @@ -33,10 +33,10 @@ impl PooledTransactionsElementEcRecovered {
}

/// Converts a `Recovered` into a `PooledTransactionsElementEcRecovered`.
impl TryFrom<RecoveredTx> for PooledTransactionsElementEcRecovered {
impl TryFrom<RecoveredTx<TransactionSigned>> for PooledTransactionsElementEcRecovered {
type Error = TransactionConversionError;

fn try_from(tx: RecoveredTx) -> Result<Self, Self::Error> {
fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
match PooledTransaction::try_from(tx.signed_transaction) {
Ok(pooled_transaction) => {
Ok(Self::from_signed_transaction(pooled_transaction, tx.signer))
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/helpers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where

fn fill(
&self,
tx: RecoveredTx,
tx: RecoveredTx<TransactionSigned>,
tx_info: TransactionInfo,
) -> Result<Self::Transaction, Self::Error> {
let from = tx.signer();
Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,10 @@ impl EthPoolTransaction for MockTransaction {
}
}

impl TryFrom<RecoveredTx> for MockTransaction {
impl TryFrom<RecoveredTx<TransactionSigned>> for MockTransaction {
type Error = TryFromRecoveredTransactionError;

fn try_from(tx: RecoveredTx) -> Result<Self, Self::Error> {
fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
let sender = tx.signer();
let transaction = tx.into_signed();
let hash = transaction.hash();
Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl From<PooledTransactionsElementEcRecovered> for MockTransaction {
}
}

impl From<MockTransaction> for RecoveredTx {
impl From<MockTransaction> for RecoveredTx<TransactionSigned> {
fn from(tx: MockTransaction) -> Self {
let signed_tx =
TransactionSigned::new(tx.clone().into(), Signature::test_signature(), *tx.hash());
Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,10 @@ impl EthPoolTransaction for EthPooledTransaction {
}
}

impl TryFrom<RecoveredTx> for EthPooledTransaction {
impl TryFrom<RecoveredTx<TransactionSigned>> for EthPooledTransaction {
type Error = TryFromRecoveredTransactionError;

fn try_from(tx: RecoveredTx) -> Result<Self, Self::Error> {
fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
// ensure we can handle the transaction type and its format
match tx.ty() {
0..=EIP1559_TX_TYPE_ID | EIP7702_TX_TYPE_ID => {
Expand All @@ -1480,7 +1480,7 @@ impl TryFrom<RecoveredTx> for EthPooledTransaction {
}
}

impl From<EthPooledTransaction> for RecoveredTx {
impl From<EthPooledTransaction> for RecoveredTx<TransactionSigned> {
fn from(tx: EthPooledTransaction) -> Self {
tx.transaction
}
Expand Down
Loading