chore: make block field private (#13628)

This commit is contained in:
Matthias Seitz
2025-01-03 16:10:32 +01:00
committed by GitHub
parent 82013f46da
commit dbd4f0c4fe
67 changed files with 317 additions and 291 deletions

View File

@ -16,14 +16,14 @@ impl TryFrom<AnyRpcBlock> for SealedBlock {
let block_hash = block.header.hash;
let block = block.try_map_transactions(|tx| tx.try_into())?;
Ok(Self {
header: SealedHeader::new(block.header.inner.into_header_with_defaults(), block_hash),
body: BlockBody {
Ok(Self::new(
SealedHeader::new(block.header.inner.into_header_with_defaults(), block_hash),
BlockBody {
transactions: block.transactions.into_transactions().collect(),
ommers: Default::default(),
withdrawals: block.withdrawals.map(|w| w.into_inner().into()),
},
})
))
}
}

View File

@ -169,7 +169,7 @@ pub struct SealedBlock<H = Header, B = BlockBody> {
#[deref_mut]
pub header: SealedHeader<H>,
/// Block body.
pub body: B,
body: B,
}
impl<H, B> SealedBlock<H, B> {
@ -190,6 +190,16 @@ impl<H, B> SealedBlock<H, B> {
&self.body
}
/// Consumes the block and returns the header.
pub fn into_header(self) -> H {
self.header.unseal()
}
/// Consumes the block and returns the body.
pub fn into_body(self) -> B {
self.body
}
/// Splits the [`BlockBody`] and [`SealedHeader`] into separate components
#[inline]
pub fn split_header_body(self) -> (SealedHeader<H>, B) {

View File

@ -13,7 +13,7 @@ pub trait BlockExt: Block {
/// Calculate the header hash and seal the block so that it can't be changed.
fn seal_slow(self) -> SealedBlock<Self::Header, Self::Body> {
let (header, body) = self.split();
SealedBlock { header: SealedHeader::seal(header), body }
SealedBlock::new(SealedHeader::seal(header), body)
}
/// Seal the block with a known hash.
@ -21,7 +21,7 @@ pub trait BlockExt: Block {
/// WARNING: This method does not perform validation whether the hash is correct.
fn seal(self, hash: B256) -> SealedBlock<Self::Header, Self::Body> {
let (header, body) = self.split();
SealedBlock { header: SealedHeader::new(header, hash), body }
SealedBlock::new(SealedHeader::new(header, hash), body)
}
/// Expensive operation that recovers transaction signer.