chore: add default for 2718 transactions (#13018)

This commit is contained in:
Matthias Seitz
2024-11-29 17:08:58 +01:00
committed by GitHub
parent b09c345257
commit 36eaf565d9
3 changed files with 36 additions and 15 deletions

View File

@ -1,13 +1,13 @@
//! Block body abstraction.
use alloc::{fmt, vec::Vec};
use alloy_consensus::Transaction;
use alloy_eips::{eip4844::DATA_GAS_PER_BLOB, eip4895::Withdrawals};
use crate::{
FullSignedTx, InMemorySize, MaybeArbitrary, MaybeSerde, MaybeSerdeBincodeCompat,
SignedTransaction,
};
use alloc::{fmt, vec::Vec};
use alloy_consensus::Transaction;
use alloy_eips::{eip2718::Encodable2718, eip4844::DATA_GAS_PER_BLOB, eip4895::Withdrawals};
use alloy_primitives::Bytes;
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> {}
@ -59,4 +59,24 @@ pub trait BlockBody:
.map(|hashes| hashes.len() as u64 * DATA_GAS_PER_BLOB)
.sum()
}
/// Returns an iterator over the encoded 2718 transactions.
///
/// This is also known as `raw transactions`.
///
/// See also [`Encodable2718`].
#[doc(alias = "raw_transactions_iter")]
fn encoded_2718_transactions_iter(&self) -> impl Iterator<Item = Vec<u8>> + '_ {
self.transactions().iter().map(|tx| tx.encoded_2718())
}
/// Returns a vector of encoded 2718 transactions.
///
/// This is also known as `raw transactions`.
///
/// See also [`Encodable2718`].
#[doc(alias = "raw_transactions")]
fn encoded_2718_transactions(&self) -> Vec<Bytes> {
self.encoded_2718_transactions_iter().map(Into::into).collect()
}
}