]> Untitled Git - bdk/commitdiff
refactor(chain)!: Rename `spks_with_labels` to `spks_with_indices`
author志宇 <hello@evanlinjin.me>
Tue, 13 Aug 2024 08:15:43 +0000 (08:15 +0000)
committer志宇 <hello@evanlinjin.me>
Wed, 14 Aug 2024 08:30:03 +0000 (08:30 +0000)
and use consistent generic parameter names across `SyncRequest` and
`SyncRequestBuilder`.

crates/chain/src/spk_client.rs
example-crates/example_electrum/src/main.rs
example-crates/example_esplora/src/main.rs

index 9a57a684457c8cc03acd731ba0a2d4a72cbb9baf..567a8f0a956ed4ed72ad5c337092aaeb548c66d7 100644 (file)
@@ -89,11 +89,11 @@ impl SyncProgress {
 
 /// Builds a [`SyncRequest`].
 #[must_use]
-pub struct SyncRequestBuilder<SpkLabel = ()> {
-    inner: SyncRequest<SpkLabel>,
+pub struct SyncRequestBuilder<I = ()> {
+    inner: SyncRequest<I>,
 }
 
-impl<SpkLabel> Default for SyncRequestBuilder<SpkLabel> {
+impl<I> Default for SyncRequestBuilder<I> {
     fn default() -> Self {
         Self {
             inner: Default::default(),
@@ -110,7 +110,7 @@ impl<K: Clone + Ord + core::fmt::Debug + Send + Sync> SyncRequestBuilder<(K, u32
         indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
         spk_range: impl core::ops::RangeBounds<K>,
     ) -> Self {
-        self.spks_with_labels(indexer.revealed_spks(spk_range))
+        self.spks_with_indexes(indexer.revealed_spks(spk_range))
     }
 
     /// Add [`Script`]s that are revealed by the `indexer` but currently unused.
@@ -118,18 +118,18 @@ impl<K: Clone + Ord + core::fmt::Debug + Send + Sync> SyncRequestBuilder<(K, u32
         self,
         indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
     ) -> Self {
-        self.spks_with_labels(indexer.unused_spks())
+        self.spks_with_indexes(indexer.unused_spks())
     }
 }
 
 impl SyncRequestBuilder<()> {
     /// Add [`Script`]s that will be synced against.
     pub fn spks(self, spks: impl IntoIterator<Item = ScriptBuf>) -> Self {
-        self.spks_with_labels(spks.into_iter().map(|spk| ((), spk)))
+        self.spks_with_indexes(spks.into_iter().map(|spk| ((), spk)))
     }
 }
 
-impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
+impl<I> SyncRequestBuilder<I> {
     /// Set the initial chain tip for the sync request.
     ///
     /// This is used to update [`LocalChain`](crate::local_chain::LocalChain).
@@ -138,7 +138,7 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
         self
     }
 
-    /// Add [`Script`]s coupled with an associated label that will be synced against.
+    /// Add [`Script`]s coupled with associated indexes that will be synced against.
     ///
     /// # Example
     ///
@@ -158,28 +158,25 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
     ///
     /// /* Assume that the caller does more mutations to the `indexer` here... */
     ///
-    /// // Reveal spks for "descriptor_a", then build a sync request. Each spk will be labelled with
+    /// // Reveal spks for "descriptor_a", then build a sync request. Each spk will be indexed with
     /// // `u32`, which represents the derivation index of the associated spk from "descriptor_a".
     /// let (newly_revealed_spks, _changeset) = indexer
     ///     .reveal_to_target("descriptor_a", 21)
     ///     .expect("keychain must exist");
     /// let _request = SyncRequest::builder()
-    ///     .spks_with_labels(newly_revealed_spks)
+    ///     .spks_with_indexes(newly_revealed_spks)
     ///     .build();
     ///
     /// // Sync all revealed spks in the indexer. This time, spks may be derived from different
-    /// // keychains. Each spk will be labelled with `(&'static str, u32)` where `&'static str` is
+    /// // keychains. Each spk will be indexed with `(&'static str, u32)` where `&'static str` is
     /// // the keychain identifier and `u32` is the derivation index.
     /// let all_revealed_spks = indexer.revealed_spks(..);
     /// let _request = SyncRequest::builder()
-    ///     .spks_with_labels(all_revealed_spks)
+    ///     .spks_with_indexes(all_revealed_spks)
     ///     .build();
     /// # Ok::<_, bdk_chain::keychain_txout::InsertDescriptorError<_>>(())
     /// ```
-    pub fn spks_with_labels(
-        mut self,
-        spks: impl IntoIterator<Item = (SpkLabel, ScriptBuf)>,
-    ) -> Self {
+    pub fn spks_with_indexes(mut self, spks: impl IntoIterator<Item = (I, ScriptBuf)>) -> Self {
         self.inner.spks.extend(spks);
         self
     }
@@ -199,14 +196,14 @@ impl<SpkLabel> SyncRequestBuilder<SpkLabel> {
     /// Set the closure that will inspect every sync item visited.
     pub fn inspect<F>(mut self, inspect: F) -> Self
     where
-        F: FnMut(SyncItem<SpkLabel>, SyncProgress) + Send + 'static,
+        F: FnMut(SyncItem<I>, SyncProgress) + Send + 'static,
     {
         self.inner.inspect = Box::new(inspect);
         self
     }
 
     /// Build the [`SyncRequest`].
-    pub fn build(self) -> SyncRequest<SpkLabel> {
+    pub fn build(self) -> SyncRequest<I> {
         self.inner
     }
 }
index 7ef54f13b6ae40b1043577c7eee2902406ee3625..49608fbf152c01178a8c60422f308bf2db60e3d4 100644 (file)
@@ -209,10 +209,10 @@ fn main() -> anyhow::Result<()> {
                     });
 
             if all_spks {
-                request = request.spks_with_labels(graph.index.revealed_spks(..));
+                request = request.spks_with_indexes(graph.index.revealed_spks(..));
             }
             if unused_spks {
-                request = request.spks_with_labels(graph.index.unused_spks());
+                request = request.spks_with_indexes(graph.index.unused_spks());
             }
             if utxos {
                 let init_outpoints = graph.index.outpoints();
index 7a28ee2372726bc17281bd64f572849240701198..b07a6697d9d5a98c8fe6487b33adb4ff74d3e2e2 100644 (file)
@@ -230,10 +230,10 @@ fn main() -> anyhow::Result<()> {
                 let chain = chain.lock().unwrap();
 
                 if *all_spks {
-                    request = request.spks_with_labels(graph.index.revealed_spks(..));
+                    request = request.spks_with_indexes(graph.index.revealed_spks(..));
                 }
                 if unused_spks {
-                    request = request.spks_with_labels(graph.index.unused_spks());
+                    request = request.spks_with_indexes(graph.index.unused_spks());
                 }
                 if utxos {
                     // We want to search for whether the UTXO is spent, and spent by which