chore: add typed2718 to txtype (#13076)

This commit is contained in:
Matthias Seitz
2024-12-05 16:58:19 +01:00
committed by GitHub
parent d71a4be982
commit 56624f820f
4 changed files with 20 additions and 70 deletions

View File

@ -1,4 +1,4 @@
use alloy_consensus::{Header, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy};
use alloy_consensus::{Header, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy, TxType};
use alloy_primitives::{PrimitiveSignature as Signature, TxHash};
/// Trait for calculating a heuristic for the in-memory size of a struct.
@ -28,7 +28,7 @@ macro_rules! impl_in_mem_size_size_of {
};
}
impl_in_mem_size_size_of!(Signature, TxHash);
impl_in_mem_size_size_of!(Signature, TxHash, TxType);
/// Implement `InMemorySize` for a type with a native `size` method.
macro_rules! impl_in_mem_size {
@ -47,11 +47,7 @@ macro_rules! impl_in_mem_size {
impl_in_mem_size!(Header, TxLegacy, TxEip2930, TxEip1559, TxEip7702, TxEip4844);
#[cfg(feature = "op")]
impl InMemorySize for op_alloy_consensus::OpTxType {
fn size(&self) -> usize {
1
}
}
impl_in_mem_size_size_of!(op_alloy_consensus::OpTxType);
#[cfg(test)]
mod tests {

View File

@ -1,6 +1,7 @@
//! Abstraction of transaction envelope type ID.
use crate::{InMemorySize, MaybeArbitrary, MaybeCompact};
use alloy_consensus::Typed2718;
use alloy_primitives::{U64, U8};
use core::fmt;
@ -30,24 +31,10 @@ pub trait TxType:
+ TryFrom<U64>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ Typed2718
+ InMemorySize
+ MaybeArbitrary
{
/// Returns `true` if this is a legacy transaction.
fn is_legacy(&self) -> bool;
/// Returns `true` if this is an eip-2930 transaction.
fn is_eip2930(&self) -> bool;
/// Returns `true` if this is an eip-1559 transaction.
fn is_eip1559(&self) -> bool;
/// Returns `true` if this is an eip-4844 transaction.
fn is_eip4844(&self) -> bool;
/// Returns `true` if this is an eip-7702 transaction.
fn is_eip7702(&self) -> bool;
/// Returns whether this transaction type can be __broadcasted__ as full transaction over the
/// network.
///
@ -60,24 +47,6 @@ pub trait TxType:
}
#[cfg(feature = "op")]
impl TxType for op_alloy_consensus::OpTxType {
fn is_legacy(&self) -> bool {
matches!(self, Self::Legacy)
}
impl TxType for op_alloy_consensus::OpTxType {}
fn is_eip2930(&self) -> bool {
matches!(self, Self::Eip2930)
}
fn is_eip1559(&self) -> bool {
matches!(self, Self::Eip1559)
}
fn is_eip4844(&self) -> bool {
false
}
fn is_eip7702(&self) -> bool {
matches!(self, Self::Eip7702)
}
}
impl TxType for alloy_consensus::TxType {}