2023-03-10 13:40:27 +13:00
|
|
|
#![doc = include_str!("../README.md")]
|
2023-12-06 21:21:02 -06:00
|
|
|
|
|
|
|
//! This crate is used for updating structures of [`bdk_chain`] with data from an Esplora server.
|
|
|
|
//!
|
|
|
|
//! The two primary methods are [`EsploraExt::sync`] and [`EsploraExt::full_scan`]. In most cases
|
|
|
|
//! [`EsploraExt::sync`] is used to sync the transaction histories of scripts that the application
|
|
|
|
//! cares about, for example the scripts for all the receive addresses of a Wallet's keychain that it
|
|
|
|
//! has shown a user. [`EsploraExt::full_scan`] is meant to be used when importing or restoring a
|
|
|
|
//! keychain where the range of possibly used scripts is not known. In this case it is necessary to
|
|
|
|
//! scan all keychain scripts until a number (the "stop gap") of unused scripts is discovered. For a
|
|
|
|
//! sync or full scan the user receives relevant blockchain data and output updates for [`bdk_chain`]
|
|
|
|
//! via a new [`TxGraph`] to be appended to any existing [`TxGraph`] data.
|
|
|
|
//!
|
|
|
|
//! Refer to [`example_esplora`] for a complete example.
|
|
|
|
//!
|
|
|
|
//! [`TxGraph`]: bdk_chain::tx_graph::TxGraph
|
|
|
|
//! [`example_esplora`]: https://github.com/bitcoindevkit/bdk/tree/master/example-crates/example_esplora
|
|
|
|
|
2023-11-12 21:31:44 +08:00
|
|
|
use bdk_chain::{BlockId, ConfirmationTimeHeightAnchor};
|
2023-03-09 10:59:18 +13:00
|
|
|
use esplora_client::TxStatus;
|
2023-03-02 16:23:06 +11:00
|
|
|
|
|
|
|
pub use esplora_client;
|
2023-03-07 17:04:06 +03:00
|
|
|
|
|
|
|
#[cfg(feature = "blocking")]
|
2023-03-09 10:59:18 +13:00
|
|
|
mod blocking_ext;
|
2023-03-03 12:07:04 +01:00
|
|
|
#[cfg(feature = "blocking")]
|
2023-03-09 10:59:18 +13:00
|
|
|
pub use blocking_ext::*;
|
2023-03-02 16:23:06 +11:00
|
|
|
|
2023-03-09 10:59:18 +13:00
|
|
|
#[cfg(feature = "async")]
|
|
|
|
mod async_ext;
|
|
|
|
#[cfg(feature = "async")]
|
|
|
|
pub use async_ext::*;
|
2023-03-02 16:23:06 +11:00
|
|
|
|
2023-11-12 21:31:44 +08:00
|
|
|
fn anchor_from_status(status: &TxStatus) -> Option<ConfirmationTimeHeightAnchor> {
|
2023-07-19 17:42:52 +08:00
|
|
|
if let TxStatus {
|
|
|
|
block_height: Some(height),
|
|
|
|
block_hash: Some(hash),
|
|
|
|
block_time: Some(time),
|
|
|
|
..
|
|
|
|
} = status.clone()
|
|
|
|
{
|
2023-11-12 21:31:44 +08:00
|
|
|
Some(ConfirmationTimeHeightAnchor {
|
2023-07-19 17:42:52 +08:00
|
|
|
anchor_block: BlockId { height, hash },
|
|
|
|
confirmation_height: height,
|
|
|
|
confirmation_time: time,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
2023-05-18 14:04:48 +08:00
|
|
|
}
|
|
|
|
}
|