Skip to content

Commit 6d77e2e

Browse files
committed
refactor(chain)!: Rename spks_with_labels to spks_with_indices
and use consistent generic parameter names across `SyncRequest` and `SyncRequestBuilder`.
1 parent 584b10a commit 6d77e2e

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

crates/chain/src/spk_client.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ impl SyncProgress {
8989

9090
/// Builds a [`SyncRequest`].
9191
#[must_use]
92-
pub struct SyncRequestBuilder<SpkLabel = ()> {
93-
inner: SyncRequest<SpkLabel>,
92+
pub struct SyncRequestBuilder<I = ()> {
93+
inner: SyncRequest<I>,
9494
}
9595

96-
impl<SpkLabel> Default for SyncRequestBuilder<SpkLabel> {
96+
impl<I> Default for SyncRequestBuilder<I> {
9797
fn default() -> Self {
9898
Self {
9999
inner: Default::default(),
@@ -110,26 +110,26 @@ impl<K: Clone + Ord + core::fmt::Debug + Send + Sync> SyncRequestBuilder<(K, u32
110110
indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
111111
spk_range: impl core::ops::RangeBounds<K>,
112112
) -> Self {
113-
self.spks_with_labels(indexer.revealed_spks(spk_range))
113+
self.spks_with_indexes(indexer.revealed_spks(spk_range))
114114
}
115115

116116
/// Add [`Script`]s that are revealed by the `indexer` but currently unused.
117117
pub fn unused_spks_from_indexer(
118118
self,
119119
indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
120120
) -> Self {
121-
self.spks_with_labels(indexer.unused_spks())
121+
self.spks_with_indexes(indexer.unused_spks())
122122
}
123123
}
124124

125125
impl SyncRequestBuilder<()> {
126126
/// Add [`Script`]s that will be synced against.
127127
pub fn spks(self, spks: impl IntoIterator<Item = ScriptBuf>) -> Self {
128-
self.spks_with_labels(spks.into_iter().map(|spk| ((), spk)))
128+
self.spks_with_indexes(spks.into_iter().map(|spk| ((), spk)))
129129
}
130130
}
131131

132-
impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
132+
impl<I> SyncRequestBuilder<I> {
133133
/// Set the initial chain tip for the sync request.
134134
///
135135
/// This is used to update [`LocalChain`](crate::local_chain::LocalChain).
@@ -138,7 +138,7 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
138138
self
139139
}
140140

141-
/// Add [`Script`]s coupled with an associated label that will be synced against.
141+
/// Add [`Script`]s coupled with associated indexes that will be synced against.
142142
///
143143
/// # Example
144144
///
@@ -158,28 +158,25 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
158158
///
159159
/// /* Assume that the caller does more mutations to the `indexer` here... */
160160
///
161-
/// // Reveal spks for "descriptor_a", then build a sync request. Each spk will be labelled with
161+
/// // Reveal spks for "descriptor_a", then build a sync request. Each spk will be indexed with
162162
/// // `u32`, which represents the derivation index of the associated spk from "descriptor_a".
163163
/// let (newly_revealed_spks, _changeset) = indexer
164164
/// .reveal_to_target("descriptor_a", 21)
165165
/// .expect("keychain must exist");
166166
/// let _request = SyncRequest::builder()
167-
/// .spks_with_labels(newly_revealed_spks)
167+
/// .spks_with_indexes(newly_revealed_spks)
168168
/// .build();
169169
///
170170
/// // 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
171+
/// // keychains. Each spk will be indexed with `(&'static str, u32)` where `&'static str` is
172172
/// // the keychain identifier and `u32` is the derivation index.
173173
/// let all_revealed_spks = indexer.revealed_spks(..);
174174
/// let _request = SyncRequest::builder()
175-
/// .spks_with_labels(all_revealed_spks)
175+
/// .spks_with_indexes(all_revealed_spks)
176176
/// .build();
177177
/// # Ok::<_, bdk_chain::keychain_txout::InsertDescriptorError<_>>(())
178178
/// ```
179-
pub fn spks_with_labels(
180-
mut self,
181-
spks: impl IntoIterator<Item = (SpkLabel, ScriptBuf)>,
182-
) -> Self {
179+
pub fn spks_with_indexes(mut self, spks: impl IntoIterator<Item = (I, ScriptBuf)>) -> Self {
183180
self.inner.spks.extend(spks);
184181
self
185182
}
@@ -199,14 +196,14 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
199196
/// Set the closure that will inspect every sync item visited.
200197
pub fn inspect<F>(mut self, inspect: F) -> Self
201198
where
202-
F: FnMut(SyncItem<SpkLabel>, SyncProgress) + Send + 'static,
199+
F: FnMut(SyncItem<I>, SyncProgress) + Send + 'static,
203200
{
204201
self.inner.inspect = Box::new(inspect);
205202
self
206203
}
207204

208205
/// Build the [`SyncRequest`].
209-
pub fn build(self) -> SyncRequest<SpkLabel> {
206+
pub fn build(self) -> SyncRequest<I> {
210207
self.inner
211208
}
212209
}

example-crates/example_electrum/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ fn main() -> anyhow::Result<()> {
209209
});
210210

211211
if all_spks {
212-
request = request.spks_with_labels(graph.index.revealed_spks(..));
212+
request = request.spks_with_indexes(graph.index.revealed_spks(..));
213213
}
214214
if unused_spks {
215-
request = request.spks_with_labels(graph.index.unused_spks());
215+
request = request.spks_with_indexes(graph.index.unused_spks());
216216
}
217217
if utxos {
218218
let init_outpoints = graph.index.outpoints();

example-crates/example_esplora/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ fn main() -> anyhow::Result<()> {
230230
let chain = chain.lock().unwrap();
231231

232232
if *all_spks {
233-
request = request.spks_with_labels(graph.index.revealed_spks(..));
233+
request = request.spks_with_indexes(graph.index.revealed_spks(..));
234234
}
235235
if unused_spks {
236-
request = request.spks_with_labels(graph.index.unused_spks());
236+
request = request.spks_with_indexes(graph.index.unused_spks());
237237
}
238238
if utxos {
239239
// We want to search for whether the UTXO is spent, and spent by which

0 commit comments

Comments
 (0)