5 releases (3 breaking)
0.7.0 | Jul 6, 2022 |
---|---|
0.6.0 | Dec 20, 2021 |
0.3.0 | Jul 6, 2021 |
0.2.2 | Apr 4, 2021 |
0.2.0 | Apr 4, 2021 |
#15 in #polling
200KB
4K
SLoC
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);
Dependencies
~7–12MB
~227K SLoC