From 87ecb434135294565b51a0ddc36d9aab146a9e23 Mon Sep 17 00:00:00 2001 From: Steven <112043913+stevencartavia@users.noreply.github.com> Date: Fri, 22 Nov 2024 07:52:08 -0600 Subject: [PATCH] replace BlockWithSenders with fn (#12695) --- crates/chain-state/src/in_memory.rs | 2 +- crates/primitives/src/block.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index e07eaeaa5d9e..24f394a761f5 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -619,7 +619,7 @@ impl BlockState { pub fn block_with_senders(&self) -> BlockWithSenders { let block = self.block.block().clone(); let senders = self.block.senders().clone(); - BlockWithSenders { block: block.unseal(), senders } + BlockWithSenders::new_unchecked(block.unseal(), senders) } /// Returns the sealed block with senders for the state. diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 57c63d53a43e..a93b1cf538a7 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -73,7 +73,7 @@ impl Block { senders }; - Ok(BlockWithSenders { block: self, senders }) + Ok(BlockWithSenders::new_unchecked(self, senders)) } /// **Expensive**. Transform into a [`BlockWithSenders`] by recovering senders in the contained @@ -82,7 +82,7 @@ impl Block { /// Returns `None` if a transaction is invalid. pub fn with_recovered_senders(self) -> Option { let senders = self.senders()?; - Some(BlockWithSenders { block: self, senders }) + Some(BlockWithSenders::new_unchecked(self, senders)) } } @@ -214,6 +214,11 @@ pub struct BlockWithSenders { } impl BlockWithSenders { + /// New block with senders + pub const fn new_unchecked(block: Block, senders: Vec
) -> Self { + Self { block, senders } + } + /// New block with senders. Return none if len of tx and senders does not match pub fn new(block: Block, senders: Vec
) -> Option { (block.body.transactions.len() == senders.len()).then_some(Self { block, senders }) @@ -527,7 +532,7 @@ impl SealedBlockWithSenders { #[inline] pub fn unseal(self) -> BlockWithSenders { let Self { block, senders } = self; - BlockWithSenders { block: block.unseal(), senders } + BlockWithSenders::new_unchecked(block.unseal(), senders) } /// Returns an iterator over all transactions in the block.