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.
23
34use core:: ops:: RangeBounds ;
45
@@ -15,14 +16,14 @@ use bitcoin::{Amount, OutPoint, ScriptBuf, SignedAmount, Transaction, TxOut, Txi
1516/// index will look at any txouts you pass in and store and index any txouts matching one of its
1617/// script pubkeys.
1718///
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)`.
2122///
2223/// Note there is no harm in scanning transactions that disappear from the blockchain or were never
2324/// 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`].
2627///
2728/// [`TxOut`]: bitcoin::TxOut
2829/// [`insert_spk`]: Self::insert_spk
@@ -89,9 +90,10 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
8990 ///
9091 /// Typically, this is used in two situations:
9192 ///
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.
9597 pub fn scan ( & mut self , tx : & Transaction ) -> BTreeSet < I > {
9698 let mut scanned_indices = BTreeSet :: new ( ) ;
9799 let txid = tx. compute_txid ( ) ;
@@ -191,7 +193,8 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
191193 & self . spks
192194 }
193195
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
195198 ///
196199 /// the index will look for outputs spending to this spk whenever it scans new data.
197200 pub fn insert_spk ( & mut self , index : I , spk : ScriptBuf ) -> bool {
@@ -243,14 +246,14 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
243246 !self . unused . contains ( index)
244247 }
245248
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.
248251 ///
249252 /// Returns whether the `index` was initially present as `unused`.
250253 ///
251254 /// 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`].
254257 ///
255258 /// [`unmark_used`]: Self::unmark_used
256259 pub fn mark_used ( & mut self , index : & I ) -> bool {
@@ -326,8 +329,8 @@ impl<I: Clone + Ord + core::fmt::Debug> SpkTxOutIndex<I> {
326329 /// matches one of our script pubkeys.
327330 ///
328331 /// 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
331334 /// transactions in the block** and only then use this method.
332335 pub fn is_relevant ( & self , tx : & Transaction ) -> bool {
333336 let input_matches = tx
0 commit comments