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: add utility trait methods to Transaction #12704

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ftupas
Copy link
Contributor

@ftupas ftupas commented Nov 20, 2024

This pr does the following:

  • add methods as trait methods for reth_primitives_traits::Transaction
    /// Returns true if the transaction is a legacy transaction.
    #[inline]
    pub const fn is_legacy(&self) -> bool {
    matches!(self, Self::Legacy(_))
    }
    /// Returns true if the transaction is an EIP-2930 transaction.
    #[inline]
    pub const fn is_eip2930(&self) -> bool {
    matches!(self, Self::Eip2930(_))
    }
    /// Returns true if the transaction is an EIP-1559 transaction.
    #[inline]
    pub const fn is_eip1559(&self) -> bool {
    matches!(self, Self::Eip1559(_))
    }
    /// Returns true if the transaction is an EIP-4844 transaction.
    #[inline]
    pub const fn is_eip4844(&self) -> bool {
    matches!(self, Self::Eip4844(_))
    }
    /// Returns true if the transaction is an EIP-7702 transaction.
    #[inline]
    pub const fn is_eip7702(&self) -> bool {
    matches!(self, Self::Eip7702(_))
    }
    /// Returns the [`TxLegacy`] variant if the transaction is a legacy transaction.
    pub const fn as_legacy(&self) -> Option<&TxLegacy> {
    match self {
    Self::Legacy(tx) => Some(tx),
    _ => None,
    }
    }
    /// Returns the [`TxEip2930`] variant if the transaction is an EIP-2930 transaction.
    pub const fn as_eip2930(&self) -> Option<&TxEip2930> {
    match self {
    Self::Eip2930(tx) => Some(tx),
    _ => None,
    }
    }
    /// Returns the [`TxEip1559`] variant if the transaction is an EIP-1559 transaction.
    pub const fn as_eip1559(&self) -> Option<&TxEip1559> {
    match self {
    Self::Eip1559(tx) => Some(tx),
    _ => None,
    }
    }
    /// Returns the [`TxEip4844`] variant if the transaction is an EIP-4844 transaction.
    pub const fn as_eip4844(&self) -> Option<&TxEip4844> {
    match self {
    Self::Eip4844(tx) => Some(tx),
    _ => None,
    }
    }
    /// Returns the [`TxEip7702`] variant if the transaction is an EIP-7702 transaction.
    pub const fn as_eip7702(&self) -> Option<&TxEip7702> {
    match self {
    Self::Eip7702(tx) => Some(tx),
    _ => None,
    }
    }
  • add default implementations for is_* methods
  • resolved Add utility trait methods to Transaction #12571

Comment on lines 103 to 120
fn as_legacy(&self) -> Option<&TxLegacy> {
(self as &dyn any::Any).downcast_ref::<TxLegacy>().filter(|_| self.is_legacy())
}

fn as_eip2930(&self) -> Option<&TxEip2930> {
(self as &dyn any::Any).downcast_ref::<TxEip2930>().filter(|_| self.is_eip2930())
}

fn as_eip1559(&self) -> Option<&TxEip1559> {
(self as &dyn any::Any).downcast_ref::<TxEip1559>().filter(|_| self.is_eip1559())
}

fn as_eip4844(&self) -> Option<&TxEip4844> {
(self as &dyn any::Any).downcast_ref::<TxEip4844>().filter(|_| self.is_eip4844())
}

fn as_eip7702(&self) -> Option<&TxEip7702> {
(self as &dyn any::Any).downcast_ref::<TxEip7702>().filter(|_| self.is_eip7702())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not work.

please exclude these function for this pr

@ftupas ftupas requested a review from mattsse November 20, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add utility trait methods to Transaction
2 participants