1
- //! [`SpkTxOutIndex`] is an index storing [`TxOut`]s that have a script pubkey that matches those in a list.
1
+ //! [`SpkTxOutIndex`] is an index storing [`TxOut`]s that have a script pubkey that matches those in
2
+ //! a list.
2
3
3
4
use core:: ops:: RangeBounds ;
4
5
@@ -15,14 +16,14 @@ use bitcoin::{Amount, OutPoint, ScriptBuf, SignedAmount, Transaction, TxOut, Txi
15
16
/// index will look at any txouts you pass in and store and index any txouts matching one of its
16
17
/// script pubkeys.
17
18
///
18
- /// Each script pubkey is associated with an application-defined index script index `I`, which must be
19
- /// [`Ord`]. Usually, this is used to associate the derivation index of the script pubkey or even a
20
- /// combination of `(keychain, derivation_index)`.
19
+ /// Each script pubkey is associated with an application-defined index script index `I`, which must
20
+ /// be [`Ord`]. Usually, this is used to associate the derivation index of the script pubkey or even
21
+ /// a combination of `(keychain, derivation_index)`.
21
22
///
22
23
/// Note there is no harm in scanning transactions that disappear from the blockchain or were never
23
24
/// in there in the first place. `SpkTxOutIndex` is intentionally *monotone* -- you cannot delete or
24
- /// modify txouts that have been indexed. To find out which txouts from the index are actually in the
25
- /// chain or unspent, you must use other sources of information like a [`TxGraph`].
25
+ /// modify txouts that have been indexed. To find out which txouts from the index are actually in
26
+ /// the chain or unspent, you must use other sources of information like a [`TxGraph`].
26
27
///
27
28
/// [`TxOut`]: bitcoin::TxOut
28
29
/// [`insert_spk`]: Self::insert_spk
@@ -89,9 +90,10 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
89
90
///
90
91
/// Typically, this is used in two situations:
91
92
///
92
- /// 1. After loading transaction data from the disk, you may scan over all the txouts to restore all
93
- /// your txouts.
94
- /// 2. When getting new data from the chain, you usually scan it before incorporating it into your chain state.
93
+ /// 1. After loading transaction data from the disk, you may scan over all the txouts to restore
94
+ /// all your txouts.
95
+ /// 2. When getting new data from the chain, you usually scan it before incorporating it into
96
+ /// your chain state.
95
97
pub fn scan ( & mut self , tx : & Transaction ) -> BTreeSet < I > {
96
98
let mut scanned_indices = BTreeSet :: new ( ) ;
97
99
let txid = tx. compute_txid ( ) ;
@@ -191,7 +193,8 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
191
193
& self . spks
192
194
}
193
195
194
- /// Adds a script pubkey to scan for. Returns `false` and does nothing if spk already exists in the map
196
+ /// Adds a script pubkey to scan for. Returns `false` and does nothing if spk already exists in
197
+ /// the map
195
198
///
196
199
/// the index will look for outputs spending to this spk whenever it scans new data.
197
200
pub fn insert_spk ( & mut self , index : I , spk : ScriptBuf ) -> bool {
@@ -243,14 +246,14 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
243
246
!self . unused . contains ( index)
244
247
}
245
248
246
- /// Marks the script pubkey at `index` as used even though it hasn't seen an output spending to it.
247
- /// This only affects when the `index` had already been added to `self` and was unused.
249
+ /// Marks the script pubkey at `index` as used even though it hasn't seen an output spending to
250
+ /// it. This only affects when the `index` had already been added to `self` and was unused.
248
251
///
249
252
/// Returns whether the `index` was initially present as `unused`.
250
253
///
251
254
/// This is useful when you want to reserve a script pubkey for something but don't want to add
252
- /// the transaction output using it to the index yet. Other callers will consider the `index` used
253
- /// until you call [`unmark_used`].
255
+ /// the transaction output using it to the index yet. Other callers will consider the `index`
256
+ /// used until you call [`unmark_used`].
254
257
///
255
258
/// [`unmark_used`]: Self::unmark_used
256
259
pub fn mark_used ( & mut self , index : & I ) -> bool {
@@ -326,8 +329,8 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
326
329
/// matches one of our script pubkeys.
327
330
///
328
331
/// It is easily possible to misuse this method and get false negatives by calling it before you
329
- /// have scanned the `TxOut`s the transaction is spending. For example, if you want to filter out
330
- /// all the transactions in a block that are irrelevant, you **must first scan all the
332
+ /// have scanned the `TxOut`s the transaction is spending. For example, if you want to filter
333
+ /// out all the transactions in a block that are irrelevant, you **must first scan all the
331
334
/// transactions in the block** and only then use this method.
332
335
pub fn is_relevant ( & self , tx : & Transaction ) -> bool {
333
336
let input_matches = tx
0 commit comments