Skip to main content

BlockTxIter

Struct BlockTxIter 

Source
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>

Source

pub fn new(data: &'a [u8]) -> ParseResult<(BlockHeader<'a>, Self)>

Position the iterator just after the block header.

Source

pub fn total(&self) -> usize

Total number of transactions in this block.

Source

pub fn consumed(&self) -> usize

Number of transactions already consumed.

Source

pub fn bytes_remaining(&self) -> usize

Number of bytes remaining in the underlying cursor (unparsed portion of the block payload).

Source

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.

Source

pub fn next_tx<FI, FO>( &mut self, on_input: FI, on_output: FO, ) -> ParseResult<bool>
where FI: FnMut(TxInput<'a>) -> ParseResult<()>, FO: FnMut(TxOutput<'a>) -> ParseResult<()>,

Parse the next transaction and pass it to f.

Returns Ok(true) if a transaction was parsed, Ok(false) at end of block.

Source

pub fn skip_remaining(&mut self) -> ParseResult<()>

Skip all remaining transactions (fast path — just advance the cursor).

Source

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.

Source

pub fn consume_all_strict<FI, FO>( self, on_input: FI, on_output: FO, ) -> ParseResult<()>
where FI: FnMut(TxInput<'a>) -> ParseResult<()>, FO: FnMut(TxOutput<'a>) -> ParseResult<()>,

Convenience helper: iterate all transactions and enforce strict completion.

Auto Trait Implementations§

§

impl<'a> Freeze for BlockTxIter<'a>

§

impl<'a> RefUnwindSafe for BlockTxIter<'a>

§

impl<'a> Send for BlockTxIter<'a>

§

impl<'a> Sync for BlockTxIter<'a>

§

impl<'a> Unpin for BlockTxIter<'a>

§

impl<'a> UnsafeUnpin for BlockTxIter<'a>

§

impl<'a> UnwindSafe for BlockTxIter<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.