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

feat: make PooledTransactionsElementEcRecovered generic over transaction #12869

Merged
merged 2 commits into from
Nov 26, 2024
Merged
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
37 changes: 16 additions & 21 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,48 +667,43 @@ impl<'a> arbitrary::Arbitrary<'a> for PooledTransactionsElement {

/// A signed pooled transaction with recovered signer.
#[derive(Debug, Clone, PartialEq, Eq, AsRef, Deref)]
pub struct PooledTransactionsElementEcRecovered {
pub struct PooledTransactionsElementEcRecovered<T = PooledTransactionsElement> {
/// Signer of the transaction
signer: Address,
/// Signed transaction
#[deref]
#[as_ref]
transaction: PooledTransactionsElement,
transaction: T,
}

// === impl PooledTransactionsElementEcRecovered ===
impl<T> PooledTransactionsElementEcRecovered<T> {
/// Create an instance from the given transaction and the [`Address`] of the signer.
pub const fn from_signed_transaction(transaction: T, signer: Address) -> Self {
Self { transaction, signer }
}

impl PooledTransactionsElementEcRecovered {
/// Signer of transaction recovered from signature
pub const fn signer(&self) -> Address {
self.signer
}

/// Transform back to [`PooledTransactionsElement`]
pub fn into_transaction(self) -> PooledTransactionsElement {
/// Consume the type and return the transaction
pub fn into_transaction(self) -> T {
self.transaction
}

/// Dissolve Self to its component
pub fn into_components(self) -> (T, Address) {
(self.transaction, self.signer)
}
}
impl PooledTransactionsElementEcRecovered {
/// Transform back to [`TransactionSignedEcRecovered`]
pub fn into_ecrecovered_transaction(self) -> TransactionSignedEcRecovered {
let (tx, signer) = self.into_components();
tx.into_ecrecovered_transaction(signer)
}

/// Dissolve Self to its component
pub fn into_components(self) -> (PooledTransactionsElement, Address) {
(self.transaction, self.signer)
}

/// Create [`TransactionSignedEcRecovered`] from [`PooledTransactionsElement`] and [`Address`]
/// of the signer.
pub const fn from_signed_transaction(
transaction: PooledTransactionsElement,
signer: Address,
) -> Self {
Self { transaction, signer }
}

/// Converts from an EIP-4844 [`TransactionSignedEcRecovered`] to a
/// [`PooledTransactionsElementEcRecovered`] with the given sidecar.
///
Expand Down Expand Up @@ -739,7 +734,7 @@ impl TryFrom<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecove
}
}

impl Encodable2718 for PooledTransactionsElementEcRecovered {
impl<T: Encodable2718> Encodable2718 for PooledTransactionsElementEcRecovered<T> {
fn type_flag(&self) -> Option<u8> {
self.transaction.type_flag()
}
Expand Down
Loading