#![doc = include_str!("../README.md")]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
use bdk_core::bitcoin::{Amount, OutPoint, TxOut, Txid};
use bdk_core::{BlockId, ConfirmationBlockTime, TxUpdate};
use esplora_client::TxStatus;
pub use esplora_client;
#[cfg(feature = "blocking")]
mod blocking_ext;
#[cfg(feature = "blocking")]
pub use blocking_ext::*;
#[cfg(feature = "async")]
mod async_ext;
#[cfg(feature = "async")]
pub use async_ext::*;
#[allow(dead_code)]
fn insert_anchor_or_seen_at_from_status(
update: &mut TxUpdate<ConfirmationBlockTime>,
start_time: u64,
txid: Txid,
status: TxStatus,
) {
if let TxStatus {
block_height: Some(height),
block_hash: Some(hash),
block_time: Some(time),
..
} = status
{
let anchor = ConfirmationBlockTime {
block_id: BlockId { height, hash },
confirmation_time: time,
};
update.anchors.insert((anchor, txid));
} else {
update.seen_ats.insert((txid, start_time));
}
}
#[allow(dead_code)]
fn insert_prevouts(
update: &mut TxUpdate<ConfirmationBlockTime>,
esplora_inputs: impl IntoIterator<Item = esplora_client::api::Vin>,
) {
let prevouts = esplora_inputs
.into_iter()
.filter_map(|vin| Some((vin.txid, vin.vout, vin.prevout?)));
for (prev_txid, prev_vout, prev_txout) in prevouts {
update.txouts.insert(
OutPoint::new(prev_txid, prev_vout),
TxOut {
script_pubkey: prev_txout.scriptpubkey,
value: Amount::from_sat(prev_txout.value),
},
);
}
}