-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathlib.rs
More file actions
83 lines (77 loc) · 2.69 KB
/
Copy pathlib.rs
File metadata and controls
83 lines (77 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![doc = include_str!("../README.md")]
//! # Stop Gap
//!
//! [`EsploraExt::full_scan`] takes in a `stop_gap` input which is defined as the maximum number of
//! consecutive unused script pubkeys to scan transactions for before stopping.
//!
//! For example, with a `stop_gap` of 3, `full_scan` will keep scanning until it encounters 3
//! consecutive script pubkeys with no associated transactions.
//!
//! This follows the same approach as other Bitcoin-related software,
//! such as [Electrum](https://electrum.readthedocs.io/en/latest/faq.html#what-is-the-gap-limit),
//! [BTCPay Server](https://docs.btcpayserver.org/FAQ/Wallet/#the-gap-limit-problem),
//! and [Sparrow](https://www.sparrowwallet.com/docs/faq.html#ive-restored-my-wallet-but-some-of-my-funds-are-missing).
//!
//! A `stop_gap` of 0 will be treated as a `stop_gap` of 1.
//!
//! # Async
//!
//! Just like how [`EsploraExt`] extends the functionality of an
//! [`esplora_client::BlockingClient`], [`EsploraAsyncExt`] is the async version which extends
//! [`esplora_client::AsyncClient`].
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
use bdk_core::bitcoin::{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));
}
}
/// Inserts floating txouts into `tx_graph` using [`Vin`](esplora_client::api::Vin)s returned by
/// Esplora.
#[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: prev_txout.value,
},
);
}
}