#bitcoin #zmq #non-blocking #stream

bitcoin-zmq

A library providing a relatively thin wrapper around Bitcoin ZMQ, allowing the construction of asynchronous streams of transaction or block data

4 releases

✓ Uses Rust 2018 edition

0.1.3 Sep 11, 2019
0.1.2 Aug 17, 2019
0.1.1 Aug 11, 2019
0.1.0 Aug 7, 2019

#109 in Cryptocurrencies

32 downloads per month

MIT license

12KB
176 lines

Rust Bitcoin ZMQ

Build Status License Cargo Documentation

This crate provides a relatively thin wrapper around Bitcoin ZMQ, allowing for the construction of asynchronous streams of transaction or block data.

Requirements

sudo apt install pkg-config libzmq3-dev

Usage

use bitcoin_zmq::{Topic, ZMQSubscriber};
use futures::{lazy, Future, Stream};

fn main() {
    // Construct subscription factory and broker
    let (factory, broker) = ZMQSubscriber::new("tcp://127.0.0.1:28332", 1024);
    let broker = broker.map_err(|err| println!("err = {:?}", err));

    // Do something with stream of raw txs
    let print_txs = factory.subscribe(Topic::RawTx).for_each(|raw_tx| {
        println!("raw tx: {:?}", hex::encode(raw_tx));
        Ok(())
    });

    // Pass futures to Tokio's executor
    tokio::run(lazy(|| {
        tokio::spawn(broker);
        tokio::spawn(print_txs);
        Ok(())
    }))
}

Dependencies

~2.5MB
~54K SLoC