feat: EthApi traits abstraction (#13170)

This commit is contained in:
Arsenii Kulikov
2024-12-06 16:30:50 +04:00
committed by GitHub
parent ab87f22cab
commit cf2a6a1ee8
53 changed files with 851 additions and 511 deletions

View File

@ -447,31 +447,6 @@ where
}
}
impl<H, B> reth_primitives_traits::Block for SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
B: reth_primitives_traits::BlockBody<OmmerHeader = H>,
{
type Header = H;
type Body = B;
fn new(header: Self::Header, body: Self::Body) -> Self {
Self { header: SealedHeader::seal(header), body }
}
fn header(&self) -> &Self::Header {
self.header.header()
}
fn body(&self) -> &Self::Body {
&self.body
}
fn split(self) -> (Self::Header, Self::Body) {
(self.header.unseal(), self.body)
}
}
#[cfg(any(test, feature = "arbitrary"))]
impl<'a, H, B> arbitrary::Arbitrary<'a> for SealedBlock<H, B>
where
@ -1022,7 +997,6 @@ mod tests {
const fn _traits() {
const fn assert_block<T: reth_primitives_traits::Block>() {}
assert_block::<Block>();
assert_block::<SealedBlock>();
}
/// Check parsing according to EIP-1898.

View File

@ -1506,6 +1506,11 @@ impl<T> RecoveredTx<T> {
pub const fn from_signed_transaction(signed_transaction: T, signer: Address) -> Self {
Self { signed_transaction, signer }
}
/// Applies the given closure to the inner transactions.
pub fn map_transaction<Tx>(self, f: impl FnOnce(T) -> Tx) -> RecoveredTx<Tx> {
RecoveredTx::from_signed_transaction(f(self.signed_transaction), self.signer)
}
}
impl<T: Encodable> Encodable for RecoveredTx<T> {

View File

@ -654,6 +654,18 @@ impl TryFrom<TransactionSigned> for PooledTransactionsElement {
}
}
impl From<PooledTransactionsElement> for TransactionSigned {
fn from(element: PooledTransactionsElement) -> Self {
match element {
PooledTransactionsElement::Legacy(tx) => tx.into(),
PooledTransactionsElement::Eip2930(tx) => tx.into(),
PooledTransactionsElement::Eip1559(tx) => tx.into(),
PooledTransactionsElement::Eip7702(tx) => tx.into(),
PooledTransactionsElement::BlobTransaction(blob_tx) => blob_tx.into_parts().0,
}
}
}
#[cfg(any(test, feature = "arbitrary"))]
impl<'a> arbitrary::Arbitrary<'a> for PooledTransactionsElement {
/// Generates an arbitrary `PooledTransactionsElement`.