feat: add clone into consensus (#12999)

This commit is contained in:
Matthias Seitz
2024-11-29 11:53:05 +01:00
committed by GitHub
parent b6ba822cc3
commit a01e0319e4
7 changed files with 25 additions and 7 deletions

View File

@ -602,7 +602,7 @@ where
.into_iter()
.map(|tx| {
let recovered: TransactionSignedEcRecovered =
tx.transaction.clone().into_consensus().into();
tx.transaction.clone_into_consensus().into();
recovered.into_signed()
})
.collect::<Vec<_>>();

View File

@ -979,6 +979,13 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone {
tx.try_into()
}
/// Clone the transaction into a consensus variant.
///
/// This method is preferred when the [`PoolTransaction`] already wraps the consensus variant.
fn clone_into_consensus(&self) -> Self::Consensus {
self.clone().into_consensus()
}
/// Define a method to convert from the `Self` type to `Consensus`
fn into_consensus(self) -> Self::Consensus {
self.into()
@ -1237,6 +1244,10 @@ impl PoolTransaction for EthPooledTransaction {
type Pooled = PooledTransactionsElementEcRecovered;
fn clone_into_consensus(&self) -> Self::Consensus {
self.transaction().clone()
}
fn try_consensus_into_pooled(
tx: Self::Consensus,
) -> Result<Self::Pooled, Self::TryFromConsensusError> {

View File

@ -375,6 +375,13 @@ impl<T: PoolTransaction> ValidPoolTransaction<T> {
self.is_eip4844() != other.is_eip4844()
}
/// Converts to this type into the consensus transaction of the pooled transaction.
///
/// Note: this takes `&self` since indented usage is via `Arc<Self>`.
pub fn to_consensus(&self) -> T::Consensus {
self.transaction.clone_into_consensus()
}
/// Determines whether a candidate transaction (`maybe_replacement`) is underpriced compared to
/// an existing transaction in the pool.
///
@ -433,7 +440,7 @@ impl<T: PoolTransaction<Consensus: Into<TransactionSignedEcRecovered>>> ValidPoo
///
/// Note: this takes `&self` since indented usage is via `Arc<Self>`.
pub fn to_recovered_transaction(&self) -> TransactionSignedEcRecovered {
self.transaction.clone().into_consensus().into()
self.to_consensus().into()
}
}