bitcoin_block_parser::blocks

Trait BlockParser

Source
pub trait BlockParser<B: Send + 'static>:
    Clone
    + Send
    + 'static {
    // Required method
    fn extract(&self, block: Block) -> Vec<B>;

    // Provided methods
    fn batch(&self, items: Vec<B>) -> Vec<B> { ... }
    fn options() -> Options { ... }
    fn parse(&self, headers: &[ParsedHeader]) -> Receiver<Result<B>> { ... }
    fn parse_dir(&self, blocks: &str) -> Result<Receiver<Result<B>>> { ... }
    fn parse_map<C: Send + 'static>(
        &self,
        headers: &[ParsedHeader],
        map: fn(_: B) -> C,
    ) -> Receiver<Result<C>> { ... }
    fn parse_with_opts(
        &self,
        headers: &[ParsedHeader],
        opts: Options,
    ) -> Receiver<Result<B>> { ... }
    fn parse_with_opts_map<C: Send + 'static>(
        &self,
        headers: &[ParsedHeader],
        opts: Options,
        map: fn(_: B) -> C,
    ) -> Receiver<Result<C>> { ... }
    fn send_batch<C>(
        &self,
        tx_c: &Sender<Result<C>>,
        batch: Result<Vec<B>>,
        map: fn(_: B) -> C,
    ) { ... }
}
Expand description

Implement this trait to create a custom Block parser.

Required Methods§

Source

fn extract(&self, block: Block) -> Vec<B>

Extracts the data you need from the block.

If you can keep Vec<B> small you will gain memory/speed performance. Always runs on blocks out-of-order using multiple threads so put compute-heavy code in here.

Provided Methods§

Source

fn batch(&self, items: Vec<B>) -> Vec<B>

Runs on batches of B to return the final results, blocks will be in-order if Options::order_output has been set.

Implement batch if your algorithm depends on the order of the blocks or if you need to reduce lock contention when accessing shared state in Arc<Mutex<_>>.

Use Options::batch_size if you need to tune the number of the items.

Source

fn options() -> Options

The default Options that this parser will use.

Implementing BlockParser::options allows for tuning of the parameters of the algorithm.

Source

fn parse(&self, headers: &[ParsedHeader]) -> Receiver<Result<B>>

Parse all the blocks represented by the headers.

Source

fn parse_dir(&self, blocks: &str) -> Result<Receiver<Result<B>>>

Parse all the blocks located in the blocks directory

Source

fn parse_map<C: Send + 'static>( &self, headers: &[ParsedHeader], map: fn(_: B) -> C, ) -> Receiver<Result<C>>

Parse the blocks and then perform the map function. Use when performing expensive post-processing for a large speed-up.

Source

fn parse_with_opts( &self, headers: &[ParsedHeader], opts: Options, ) -> Receiver<Result<B>>

Allows users to pass in custom Options in case they need to reduce memory usage or otherwise tune performance for their system. Users should call BlockParser::options to get the default options associated with the parser first.

Source

fn parse_with_opts_map<C: Send + 'static>( &self, headers: &[ParsedHeader], opts: Options, map: fn(_: B) -> C, ) -> Receiver<Result<C>>

Pass in custom Options and a map function.

Source

fn send_batch<C>( &self, tx_c: &Sender<Result<C>>, batch: Result<Vec<B>>, map: fn(_: B) -> C, )

Helper function for sending batch results in a channel

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§