bitcoins-provider

Crates.iobitcoins-provider
lib.rsbitcoins-provider
version0.7.0
sourcesrc
created_at2021-04-04 18:31:56.630423
updated_at2022-07-06 19:35:40.416253
descriptionStandardized Bitcoin RPC connection management
homepage
repositoryhttps://github.com/summa-tx/bitcoins-rs
max_upload_size
id378906
size84,324
James Prestwich (prestwich)

documentation

README

bitcoins-provider

This crate provides a generic chain-data API for Bitcoin apps. It aims to give a simple consistent interface to chain data, so that wallets can easily support a wide range of backends out of the box.

Apps that are generic over a BtcProvider can seamlessly accept different sources. We have implemented a BtcProvider calling the Blockstream Esplora API, and more options are coming.

The PollingBtcProvider trait can extend the BtcProvider with useful functionality like a polling chain-tip stream, a pending tx that streams confirmations, and a UTXO watcher that streams spend notifications.

Usage example

use futures_core::stream::StreamExt;
use tokio::runtime;

use bitcoins_provider::{
  BtcProvider,
  PollingBtcProvider,
  esplora::EsploraProvider
};

let fut = async move {
    // Defaults to blockstream.info/api/
    let provider = EsploraProvider::default();

    // Get a stream that emits the next 10 chain tips, polling every 10 seconds
    let mut tips = provider.tips(10).interval(Duration::from_secs(10));

    // Print each header as it comes in
    while let Some(next) = tips.next().await {
        dbg!(next.serialize_hex().unwrap());
    }
};

runtime::Runtime::new().unwrap().block_on(fut);
Commit count: 377

cargo fmt