From: 志宇 Date: Tue, 13 Aug 2024 08:15:43 +0000 (+0000) Subject: refactor(chain)!: Rename `spks_with_labels` to `spks_with_indices` X-Git-Tag: v1.0.0-beta.2~10^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/struct.Witness.html?a=commitdiff_plain;h=6d77e2e2c3e7c8d49c50bd6b41e7dbc3ddd1d275;p=bdk refactor(chain)!: Rename `spks_with_labels` to `spks_with_indices` and use consistent generic parameter names across `SyncRequest` and `SyncRequestBuilder`. --- diff --git a/crates/chain/src/spk_client.rs b/crates/chain/src/spk_client.rs index 9a57a684..567a8f0a 100644 --- a/crates/chain/src/spk_client.rs +++ b/crates/chain/src/spk_client.rs @@ -89,11 +89,11 @@ impl SyncProgress { /// Builds a [`SyncRequest`]. #[must_use] -pub struct SyncRequestBuilder { - inner: SyncRequest, +pub struct SyncRequestBuilder { + inner: SyncRequest, } -impl Default for SyncRequestBuilder { +impl Default for SyncRequestBuilder { fn default() -> Self { Self { inner: Default::default(), @@ -110,7 +110,7 @@ impl SyncRequestBuilder<(K, u32 indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex, spk_range: impl core::ops::RangeBounds, ) -> 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 SyncRequestBuilder<(K, u32 self, indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex, ) -> 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) -> Self { - self.spks_with_labels(spks.into_iter().map(|spk| ((), spk))) + self.spks_with_indexes(spks.into_iter().map(|spk| ((), spk))) } } -impl SyncRequestBuilder { +impl SyncRequestBuilder { /// Set the initial chain tip for the sync request. /// /// This is used to update [`LocalChain`](crate::local_chain::LocalChain). @@ -138,7 +138,7 @@ impl SyncRequestBuilder { 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 SyncRequestBuilder { /// /// /* 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, - ) -> Self { + pub fn spks_with_indexes(mut self, spks: impl IntoIterator) -> Self { self.inner.spks.extend(spks); self } @@ -199,14 +196,14 @@ impl SyncRequestBuilder { /// Set the closure that will inspect every sync item visited. pub fn inspect(mut self, inspect: F) -> Self where - F: FnMut(SyncItem, SyncProgress) + Send + 'static, + F: FnMut(SyncItem, SyncProgress) + Send + 'static, { self.inner.inspect = Box::new(inspect); self } /// Build the [`SyncRequest`]. - pub fn build(self) -> SyncRequest { + pub fn build(self) -> SyncRequest { self.inner } } diff --git a/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index 7ef54f13..49608fbf 100644 --- a/example-crates/example_electrum/src/main.rs +++ b/example-crates/example_electrum/src/main.rs @@ -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(); diff --git a/example-crates/example_esplora/src/main.rs b/example-crates/example_esplora/src/main.rs index 7a28ee23..b07a6697 100644 --- a/example-crates/example_esplora/src/main.rs +++ b/example-crates/example_esplora/src/main.rs @@ -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