Skip to content

Commit

Permalink
feat: implement transaction_count method for SealedBlock and add unit…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
frankudoags committed Jan 5, 2025
1 parent 1304988 commit 83dafa2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ where
}
}

impl<H, B> SealedBlock<H, B>
where
B: reth_primitives_traits::BlockBody,
{
/// Returns the number of transactions in the block.
#[inline]
pub fn transaction_count(&self) -> usize {
self.body.transaction_count()
}
}

impl<H, B> SealedBlock<H, B>
where
H: alloy_consensus::BlockHeader,
Expand Down Expand Up @@ -918,4 +929,14 @@ mod tests {
let decoded = BlockBody::decode(&mut buf.as_slice()).unwrap();
assert_eq!(body, decoded);
}

#[test]
fn test_transaction_count() {
let mut block = Block::default();
assert_eq!(block.body.transaction_count(), 0);
block.body.transactions.push(TransactionSigned::default());
assert_eq!(block.body.transaction_count(), 1);
block.body.transactions.push(TransactionSigned::default());
assert_eq!(block.body.transaction_count(), 2);
}
}

0 comments on commit 83dafa2

Please sign in to comment.