#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TransactionType {
Legacy = 0,
Eip2930 = 1,
Eip1559 = 2,
Eip4844 = 3,
Eip7702 = 4,
Custom = 0xFF,
}
impl TransactionType {
pub fn is_legacy(&self) -> bool {
matches!(self, Self::Legacy)
}
pub fn is_custom(&self) -> bool {
matches!(self, Self::Custom)
}
}
impl PartialEq<u8> for TransactionType {
fn eq(&self, other: &u8) -> bool {
(*self as u8) == *other
}
}
impl PartialEq<TransactionType> for u8 {
fn eq(&self, other: &TransactionType) -> bool {
*self == (*other as u8)
}
}
impl From<TransactionType> for u8 {
fn from(tx_type: TransactionType) -> u8 {
tx_type as u8
}
}
impl From<u8> for TransactionType {
fn from(value: u8) -> Self {
match value {
0 => Self::Legacy,
1 => Self::Eip2930,
2 => Self::Eip1559,
3 => Self::Eip4844,
4 => Self::Eip7702,
_ => Self::Custom,
}
}
}