@@ -139,6 +139,43 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
139
139
}
140
140
141
141
/// Add [`Script`]s coupled with an associated label that will be synced against.
142
+ ///
143
+ /// # Example
144
+ ///
145
+ /// Sync revealed script pubkeys obtained from a
146
+ /// [`KeychainTxOutIndex`](crate::keychain_txout::KeychainTxOutIndex).
147
+ ///
148
+ /// ```rust
149
+ /// # use bdk_chain::spk_client::SyncRequest;
150
+ /// # use bdk_chain::indexer::keychain_txout::KeychainTxOutIndex;
151
+ /// # use bdk_chain::miniscript::{Descriptor, DescriptorPublicKey};
152
+ /// # let secp = bdk_chain::bitcoin::secp256k1::Secp256k1::signing_only();
153
+ /// # let (descriptor_a,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)").unwrap();
154
+ /// # let (descriptor_b,_) = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, "tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/*)").unwrap();
155
+ /// let mut indexer = KeychainTxOutIndex::<&'static str>::default();
156
+ /// indexer.insert_descriptor("descriptor_a", descriptor_a)?;
157
+ /// indexer.insert_descriptor("descriptor_b", descriptor_b)?;
158
+ ///
159
+ /// /* Assume that the caller does more mutations to the `indexer` here... */
160
+ ///
161
+ /// // Reveal spks for "descriptor_a", then build a sync request. Each spk will be labelled with
162
+ /// // `u32`, which represents the derivation index of the associated spk from "descriptor_a".
163
+ /// let (newly_revealed_spks, _changeset) = indexer
164
+ /// .reveal_to_target("descriptor_a", 21)
165
+ /// .expect("keychain must exist");
166
+ /// let _request = SyncRequest::builder()
167
+ /// .spks_with_labels(newly_revealed_spks)
168
+ /// .build();
169
+ ///
170
+ /// // Sync all revealed spks in the indexer. This time, spks may be derived from different
171
+ /// // keychains. Each spk will be labelled with `(&'static str, u32)` where `&'static str` is
172
+ /// // the keychain identifier and `u32` is the derivation index.
173
+ /// let all_revealed_spks = indexer.revealed_spks(..);
174
+ /// let _request = SyncRequest::builder()
175
+ /// .spks_with_labels(all_revealed_spks)
176
+ /// .build();
177
+ /// # Ok::<_, bdk_chain::keychain_txout::InsertDescriptorError<_>>(())
178
+ /// ```
142
179
pub fn spks_with_labels (
143
180
mut self ,
144
181
spks : impl IntoIterator < Item = ( SpkLabel , ScriptBuf ) > ,
0 commit comments