#zmq #bitcoin #bitcoin-core

bitcoincore-zmq

Bitcoin Core ZMQ subscriber with minimal dependencies

13 stable releases

1.4.0 Jan 23, 2024
1.3.1 Nov 5, 2023
1.3.0 Oct 22, 2023
1.2.0 Jul 28, 2023
1.0.3 Apr 19, 2023

#98 in Magic Beans

Download history 54/week @ 2023-12-27 28/week @ 2024-01-03 33/week @ 2024-01-10 25/week @ 2024-01-17 51/week @ 2024-01-24 50/week @ 2024-01-31 74/week @ 2024-02-07 46/week @ 2024-02-14 71/week @ 2024-02-21 106/week @ 2024-02-28 76/week @ 2024-03-06 58/week @ 2024-03-13 29/week @ 2024-03-20 15/week @ 2024-03-27 31/week @ 2024-04-03 14/week @ 2024-04-10

102 downloads per month

MIT license

58KB
1.5K SLoC

Build and test Integration tests crates.io docs.rs

Rust Bitcoin Core ZMQ Subscriber

Usage example

fn main() {
    for msg in bitcoincore_zmq::subscribe_receiver(&["tcp://127.0.0.1:28359"]).unwrap() {
        match msg {
            Ok(msg) => println!("Received message: {msg}"),
            Err(err) => println!("Error receiving message: {err}"),
        }
    }
}

For more examples, have a look in the examples directory.

Features

  • Minimal dependencies: the 2 crates bitcoin and zmq, optionally 2 additional crates are needed for the async subscriber, async_zmq and futures-util.
  • Handles all message types from Bitcoin Core: hashblock, hashtx, block, tx and sequence.
  • Flexible: choose between blocking functions with a callback, reading from a Receiver or reading from an asynchronous Stream without locking to a specific async runtime.

Testing

Tests run on every push and pull request. Integration tests use the latest version of the 3 most recent major Bitcoin Core versions, see integration_tests.yml.

Useful resources


TODO:

  • This README
  • SequenceMessage itest
  • Easy addEventListener like functionality with help of the getzmqnotifications rpc (bitcoincore-rpc PR: #295)
  • raw messages
  • zmq publisher
  • include source in message

Dependencies

~7–9.5MB
~116K SLoC