Skip to content

Commit

Permalink
replace BlockWithSenders with fn (#12695)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencartavia authored Nov 22, 2024
1 parent 3384c84 commit 87ecb43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl<N: NodePrimitives> BlockState<N> {
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.
Expand Down
11 changes: 8 additions & 3 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +82,7 @@ impl Block {
/// Returns `None` if a transaction is invalid.
pub fn with_recovered_senders(self) -> Option<BlockWithSenders> {
let senders = self.senders()?;
Some(BlockWithSenders { block: self, senders })
Some(BlockWithSenders::new_unchecked(self, senders))
}
}

Expand Down Expand Up @@ -214,6 +214,11 @@ pub struct BlockWithSenders {
}

impl BlockWithSenders {
/// New block with senders
pub const fn new_unchecked(block: Block, senders: Vec<Address>) -> 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<Address>) -> Option<Self> {
(block.body.transactions.len() == senders.len()).then_some(Self { block, senders })
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 87ecb43

Please sign in to comment.