feat: add is_broadcastable_in_full to txtype (#12739)

This commit is contained in:
Matthias Seitz
2024-11-21 14:30:04 +01:00
committed by GitHub
parent 9fbe3468e8
commit 4f946733c3
2 changed files with 18 additions and 0 deletions

View File

@ -49,4 +49,14 @@ pub trait TxType:
/// 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.
///
/// Some transactions are not broadcastable as objects and only allowed to be broadcasted as
/// hashes, e.g. because they missing context (e.g. blob sidecar).
fn is_broadcastable_in_full(&self) -> bool {
// EIP-4844 transactions are not broadcastable in full, only hashes are allowed.
!self.is_eip4844()
}
}

View File

@ -257,8 +257,16 @@ mod tests {
use super::*;
use alloy_primitives::hex;
use reth_codecs::{txtype::*, Compact};
use reth_primitives_traits::TxType as _;
use rstest::rstest;
#[test]
fn is_broadcastable() {
assert!(TxType::Legacy.is_broadcastable_in_full());
assert!(TxType::Eip1559.is_broadcastable_in_full());
assert!(!TxType::Eip4844.is_broadcastable_in_full());
}
#[rstest]
#[case(U64::from(LEGACY_TX_TYPE_ID), Ok(TxType::Legacy))]
#[case(U64::from(EIP2930_TX_TYPE_ID), Ok(TxType::Eip2930))]