feat: Introduce Block::into_ethereum_block to Block trait (#15940)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
This commit is contained in:
Ishika Choudhury
2025-04-26 11:52:02 +05:30
committed by GitHub
parent 1775cc4269
commit dd997e0705

View File

@@ -177,6 +177,27 @@ pub trait Block:
};
Ok(RecoveredBlock::new_unhashed(self, signers))
}
/// A Convenience function to convert this type into the regular ethereum block that
/// consists of:
///
/// - Header
///
/// And the ethereum block body [`alloy_consensus::BlockBody`], see also
/// [`BlockBody::into_ethereum_body`].
/// - Transactions
/// - Withdrawals
/// - Ommers
///
/// Note: This conversion can be incomplete. It is not expected that this `Block` is the same as
/// [`alloy_consensus::Block`] only that it can be converted into it which is useful for
/// the `eth_` RPC namespace (e.g. RPC block).
fn into_ethereum_block(
self,
) -> alloy_consensus::Block<<Self::Body as BlockBody>::Transaction, Self::Header> {
let (header, body) = self.split();
alloy_consensus::Block::new(header, body.into_ethereum_body())
}
}
impl<T, H> Block for alloy_consensus::Block<T, H>
@@ -206,6 +227,10 @@ where
fn rlp_length(header: &Self::Header, body: &Self::Body) -> usize {
Self::rlp_length_for(header, body)
}
fn into_ethereum_block(self) -> Self {
self
}
}
/// An extension trait for [`Block`]s that allows for mutable access to the block's internals.