pub struct BlockTxIter<'a> { /* private fields */ }Expand description
A streaming iterator over the transactions in a raw block.
No allocation is performed. Each call to BlockTxIter::next_tx advances
the cursor and calls a user-supplied closure.
Implementations§
Source§impl<'a> BlockTxIter<'a>
impl<'a> BlockTxIter<'a>
Sourcepub fn new(data: &'a [u8]) -> ParseResult<(BlockHeader<'a>, Self)>
pub fn new(data: &'a [u8]) -> ParseResult<(BlockHeader<'a>, Self)>
Position the iterator just after the block header.
Sourcepub fn bytes_remaining(&self) -> usize
pub fn bytes_remaining(&self) -> usize
Number of bytes remaining in the underlying cursor (unparsed portion of the block payload).
Sourcepub fn bytes_consumed(&self) -> usize
pub fn bytes_consumed(&self) -> usize
Number of bytes consumed so far from the underlying block payload.
This is useful for instrumentation / debugging: after parsing n transactions,
you can see how many bytes of the block were actually consumed.
Sourcepub fn next_tx<FI, FO>(
&mut self,
on_input: FI,
on_output: FO,
) -> ParseResult<bool>
pub fn next_tx<FI, FO>( &mut self, on_input: FI, on_output: FO, ) -> ParseResult<bool>
Parse the next transaction and pass it to f.
Returns Ok(true) if a transaction was parsed, Ok(false) at end of block.
Sourcepub fn skip_remaining(&mut self) -> ParseResult<()>
pub fn skip_remaining(&mut self) -> ParseResult<()>
Skip all remaining transactions (fast path — just advance the cursor).
Sourcepub fn finish_strict(&self) -> ParseResult<()>
pub fn finish_strict(&self) -> ParseResult<()>
In strict mode, ensure we’ve parsed exactly total transactions and consumed the buffer.
Call this after iterating all transactions. If there are unread bytes remaining, this returns an error to surface offset / format bugs early.
Sourcepub fn consume_all_strict<FI, FO>(
self,
on_input: FI,
on_output: FO,
) -> ParseResult<()>
pub fn consume_all_strict<FI, FO>( self, on_input: FI, on_output: FO, ) -> ParseResult<()>
Convenience helper: iterate all transactions and enforce strict completion.