]> Untitled Git - bdk/commitdiff
chore(chain): add type IndexSpk, fix clippy type complexity warning
authorSteve Myers <steve@notmandatory.org>
Thu, 6 Jun 2024 19:10:20 +0000 (14:10 -0500)
committer志宇 <hello@evanlinjin.me>
Thu, 13 Jun 2024 14:52:44 +0000 (22:52 +0800)
clippy.toml
crates/chain/src/keychain/txout_index.rs
crates/chain/src/spk_client.rs
crates/chain/src/spk_iter.rs
crates/esplora/src/async_ext.rs
crates/esplora/src/blocking_ext.rs
crates/wallet/src/wallet/mod.rs

index fec36d9d91067bdb9d9dc6fecbcca94af6ad8e66..e3b99604d8114f26d1fe0490cfdbf65e17614c9d 100644 (file)
@@ -1,2 +1 @@
-msrv="1.63.0"
-type-complexity-threshold = 275
+msrv="1.63.0"
\ No newline at end of file
index 846b6c248e33916072f5f57db4d65efaa76a7574..6d0b7623ae1ef2487079ba359886812b1f026339 100644 (file)
@@ -3,10 +3,10 @@ use crate::{
     indexed_tx_graph::Indexer,
     miniscript::{Descriptor, DescriptorPublicKey},
     spk_iter::BIP32_MAX_INDEX,
-    DescriptorExt, DescriptorId, SpkIterator, SpkTxOutIndex,
+    DescriptorExt, DescriptorId, IndexSpk, SpkIterator, SpkTxOutIndex,
 };
 use alloc::{borrow::ToOwned, vec::Vec};
-use bitcoin::{Amount, OutPoint, Script, ScriptBuf, SignedAmount, Transaction, TxOut, Txid};
+use bitcoin::{Amount, OutPoint, Script, SignedAmount, Transaction, TxOut, Txid};
 use core::{
     fmt::Debug,
     ops::{Bound, RangeBounds},
@@ -739,9 +739,9 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
         &mut self,
         keychain: &K,
         target_index: u32,
-    ) -> Option<(Vec<(u32, ScriptBuf)>, ChangeSet<K>)> {
+    ) -> Option<(Vec<IndexSpk>, ChangeSet<K>)> {
         let mut changeset = ChangeSet::default();
-        let mut spks: Vec<(u32, ScriptBuf)> = vec![];
+        let mut spks: Vec<IndexSpk> = vec![];
         while let Some((i, new)) = self.next_index(keychain) {
             if !new || i > target_index {
                 break;
index d65ecdba15d315fc7aee042a9b67879223056378..cf78e7bdd58e493589eef50d0e6851c2f5163882 100644 (file)
@@ -1,7 +1,7 @@
 //! Helper types for spk-based blockchain clients.
 
 use crate::{
-    collections::BTreeMap, local_chain::CheckPoint, ConfirmationTimeHeightAnchor, TxGraph,
+    collections::BTreeMap, local_chain::CheckPoint, ConfirmationTimeHeightAnchor, IndexSpk, TxGraph,
 };
 use alloc::{boxed::Box, vec::Vec};
 use bitcoin::{OutPoint, Script, ScriptBuf, Txid};
@@ -195,7 +195,7 @@ pub struct FullScanRequest<K> {
     /// [`LocalChain::tip`]: crate::local_chain::LocalChain::tip
     pub chain_tip: CheckPoint,
     /// Iterators of script pubkeys indexed by the keychain index.
-    pub spks_by_keychain: BTreeMap<K, Box<dyn Iterator<Item = (u32, ScriptBuf)> + Send>>,
+    pub spks_by_keychain: BTreeMap<K, Box<dyn Iterator<Item = IndexSpk> + Send>>,
 }
 
 impl<K: Ord + Clone> FullScanRequest<K> {
@@ -238,7 +238,7 @@ impl<K: Ord + Clone> FullScanRequest<K> {
     pub fn set_spks_for_keychain(
         mut self,
         keychain: K,
-        spks: impl IntoIterator<IntoIter = impl Iterator<Item = (u32, ScriptBuf)> + Send + 'static>,
+        spks: impl IntoIterator<IntoIter = impl Iterator<Item = IndexSpk> + Send + 'static>,
     ) -> Self {
         self.spks_by_keychain
             .insert(keychain, Box::new(spks.into_iter()));
@@ -252,7 +252,7 @@ impl<K: Ord + Clone> FullScanRequest<K> {
     pub fn chain_spks_for_keychain(
         mut self,
         keychain: K,
-        spks: impl IntoIterator<IntoIter = impl Iterator<Item = (u32, ScriptBuf)> + Send + 'static>,
+        spks: impl IntoIterator<IntoIter = impl Iterator<Item = IndexSpk> + Send + 'static>,
     ) -> Self {
         match self.spks_by_keychain.remove(&keychain) {
             // clippy here suggests to remove `into_iter` from `spks.into_iter()`, but doing so
index 91c271c7a02cf6f689a8cb4391c745a4f41bbb53..8285036bf4a1f3b58d870799d6cc891d4c33a25b 100644 (file)
@@ -7,6 +7,9 @@ use core::{borrow::Borrow, ops::Bound, ops::RangeBounds};
 /// Maximum [BIP32](https://bips.xyz/32) derivation index.
 pub const BIP32_MAX_INDEX: u32 = (1 << 31) - 1;
 
+/// A tuple of keychain index and corresponding [`ScriptBuf`].
+pub type IndexSpk = (u32, ScriptBuf);
+
 /// An iterator for derived script pubkeys.
 ///
 /// [`SpkIterator`] is an implementation of the [`Iterator`] trait which possesses its own `next()`
@@ -97,7 +100,7 @@ impl<D> Iterator for SpkIterator<D>
 where
     D: Borrow<Descriptor<DescriptorPublicKey>>,
 {
-    type Item = (u32, ScriptBuf);
+    type Item = IndexSpk;
 
     fn next(&mut self) -> Option<Self::Item> {
         // For non-wildcard descriptors, we expect the first element to be Some((0, spk)), then None after.
index 304dedb3ee3c5dc3f63c2200f1e60bafc238da08..a7dbc24fcfb3f658757cb4e4d900bd776dda799b 100644 (file)
@@ -2,13 +2,13 @@ use std::collections::BTreeSet;
 
 use async_trait::async_trait;
 use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
-use bdk_chain::Anchor;
 use bdk_chain::{
     bitcoin::{BlockHash, OutPoint, ScriptBuf, TxOut, Txid},
     collections::BTreeMap,
     local_chain::CheckPoint,
     BlockId, ConfirmationTimeHeightAnchor, TxGraph,
 };
+use bdk_chain::{Anchor, IndexSpk};
 use esplora_client::{Amount, TxStatus};
 use futures::{stream::FuturesOrdered, TryStreamExt};
 
@@ -236,7 +236,7 @@ async fn full_scan_for_index_and_graph<K: Ord + Clone + Send>(
     client: &esplora_client::AsyncClient,
     keychain_spks: BTreeMap<
         K,
-        impl IntoIterator<IntoIter = impl Iterator<Item = (u32, ScriptBuf)> + Send> + Send,
+        impl IntoIterator<IntoIter = impl Iterator<Item = IndexSpk> + Send> + Send,
     >,
     stop_gap: usize,
     parallel_requests: usize,
index 09ad9c0aa96ae578f01ce2aa670b35b2fcc0a1f6..0b173c3af507f1f98ad29f5ae4c29d9cbdcfca8b 100644 (file)
@@ -4,12 +4,12 @@ use std::usize;
 
 use bdk_chain::collections::BTreeMap;
 use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
-use bdk_chain::Anchor;
 use bdk_chain::{
     bitcoin::{Amount, BlockHash, OutPoint, ScriptBuf, TxOut, Txid},
     local_chain::CheckPoint,
     BlockId, ConfirmationTimeHeightAnchor, TxGraph,
 };
+use bdk_chain::{Anchor, IndexSpk};
 use esplora_client::TxStatus;
 
 use crate::anchor_from_status;
@@ -217,7 +217,7 @@ fn chain_update<A: Anchor>(
 /// [`KeychainTxOutIndex`](bdk_chain::keychain::KeychainTxOutIndex).
 fn full_scan_for_index_and_graph_blocking<K: Ord + Clone>(
     client: &esplora_client::BlockingClient,
-    keychain_spks: BTreeMap<K, impl IntoIterator<Item = (u32, ScriptBuf)>>,
+    keychain_spks: BTreeMap<K, impl IntoIterator<Item = IndexSpk>>,
     stop_gap: usize,
     parallel_requests: usize,
 ) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error> {
index de7f19b0c47ad78ebea6a2a052982b2ef30dc6ff..184984122cb14c960963e222970dabb5b34a1e41 100644 (file)
@@ -29,7 +29,7 @@ use bdk_chain::{
     spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
     tx_graph::{CanonicalTx, TxGraph},
     Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeHeightAnchor, FullTxOut,
-    IndexedTxGraph,
+    IndexSpk, IndexedTxGraph,
 };
 use bdk_persist::{Persist, PersistBackend};
 use bitcoin::secp256k1::{All, Secp256k1};
@@ -910,7 +910,7 @@ impl Wallet {
     /// script pubkeys the wallet is storing internally).
     pub fn all_unbounded_spk_iters(
         &self,
-    ) -> BTreeMap<KeychainKind, impl Iterator<Item = (u32, ScriptBuf)> + Clone> {
+    ) -> BTreeMap<KeychainKind, impl Iterator<Item = IndexSpk> + Clone> {
         self.indexed_graph.index.all_unbounded_spk_iters()
     }
 
@@ -922,7 +922,7 @@ impl Wallet {
     pub fn unbounded_spk_iter(
         &self,
         keychain: KeychainKind,
-    ) -> impl Iterator<Item = (u32, ScriptBuf)> + Clone {
+    ) -> impl Iterator<Item = IndexSpk> + Clone {
         self.indexed_graph
             .index
             .unbounded_spk_iter(&keychain)