]> Untitled Git - bdk/commitdiff
chore: make clippy happy and bump clippy msrv
author志宇 <hello@evanlinjin.me>
Fri, 29 Dec 2023 11:15:57 +0000 (19:15 +0800)
committer志宇 <hello@evanlinjin.me>
Fri, 29 Dec 2023 11:57:48 +0000 (19:57 +0800)
.github/workflows/cont_integration.yml
clippy.toml
crates/bdk/src/descriptor/template.rs
crates/bdk/src/wallet/signer.rs
crates/bdk/src/wallet/tx_builder.rs
crates/chain/src/spk_txout_index.rs
crates/chain/src/tx_graph.rs
crates/chain/tests/common/mod.rs
crates/electrum/src/electrum_ext.rs

index 6281c465ca7df6003c63efd800490cea29813224..3dfb9906c3e58d4c87c418f69dc154181ab0b9c5 100644 (file)
@@ -118,7 +118,7 @@ jobs:
       - uses: actions/checkout@v1
       - uses: actions-rs/toolchain@v1
         with:
-            toolchain: "stable"
+            toolchain: stable
             components: clippy
             override: true
       - name: Rust Cache
index 3f726dbda58b8454f7cd72cc054461b93c6d2a8a..69478ceabd3cd548b3838ee3a3cba3166f390f85 100644 (file)
@@ -1 +1 @@
-msrv="1.57.0"
+msrv="1.63.0"
index c5e8b31c507bb51057bee702d65f42eb089f8f26..2773795a83a5b2b2765b5da973984f9067e5d9ac 100644 (file)
@@ -575,7 +575,7 @@ mod test {
 
         if let ExtendedDescriptor::Pkh(pkh) = xdesc.0 {
             let path: Vec<ChildNumber> = pkh.into_inner().full_derivation_path().unwrap().into();
-            let purpose = path.get(0).unwrap();
+            let purpose = path.first().unwrap();
             assert_matches!(purpose, Hardened { index: 44 });
             let coin_type = path.get(1).unwrap();
             assert_matches!(coin_type, Hardened { index: 0 });
@@ -589,7 +589,7 @@ mod test {
 
         if let ExtendedDescriptor::Pkh(pkh) = tdesc.0 {
             let path: Vec<ChildNumber> = pkh.into_inner().full_derivation_path().unwrap().into();
-            let purpose = path.get(0).unwrap();
+            let purpose = path.first().unwrap();
             assert_matches!(purpose, Hardened { index: 44 });
             let coin_type = path.get(1).unwrap();
             assert_matches!(coin_type, Hardened { index: 1 });
index da4940bf93dce627f3734933921fdb46033e4967..18e2062fb426fd70c3caf2c28b996a8ecd02ec96 100644 (file)
@@ -812,9 +812,10 @@ pub struct SignOptions {
 }
 
 /// Customize which taproot script-path leaves the signer should sign.
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Default, Debug, Clone, PartialEq, Eq)]
 pub enum TapLeavesOptions {
     /// The signer will sign all the leaves it has a key for.
+    #[default]
     All,
     /// The signer won't sign leaves other than the ones specified. Note that it could still ignore
     /// some of the specified leaves, if it doesn't have the right key to sign them.
@@ -825,12 +826,6 @@ pub enum TapLeavesOptions {
     None,
 }
 
-impl Default for TapLeavesOptions {
-    fn default() -> Self {
-        TapLeavesOptions::All
-    }
-}
-
 #[allow(clippy::derivable_impls)]
 impl Default for SignOptions {
     fn default() -> Self {
index 86decc8bb7a8cfdf77899c504b18030049444f45..f914aaefa7959dc2aaba84ff7f956562dd8db8c3 100644 (file)
@@ -811,9 +811,10 @@ impl<'a, D> TxBuilder<'a, D, DefaultCoinSelectionAlgorithm, BumpFee> {
 }
 
 /// Ordering of the transaction's inputs and outputs
-#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
+#[derive(Default, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
 pub enum TxOrdering {
     /// Randomized (default)
+    #[default]
     Shuffle,
     /// Unchanged
     Untouched,
@@ -821,12 +822,6 @@ pub enum TxOrdering {
     Bip69Lexicographic,
 }
 
-impl Default for TxOrdering {
-    fn default() -> Self {
-        TxOrdering::Shuffle
-    }
-}
-
 impl TxOrdering {
     /// Sort transaction inputs and outputs by [`TxOrdering`] variant
     pub fn sort_tx(&self, tx: &mut Transaction) {
@@ -880,9 +875,10 @@ impl RbfValue {
 }
 
 /// Policy regarding the use of change outputs when creating a transaction
-#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
+#[derive(Default, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
 pub enum ChangeSpendPolicy {
     /// Use both change and non-change outputs (default)
+    #[default]
     ChangeAllowed,
     /// Only use change outputs (see [`TxBuilder::only_spend_change`])
     OnlyChange,
@@ -890,12 +886,6 @@ pub enum ChangeSpendPolicy {
     ChangeForbidden,
 }
 
-impl Default for ChangeSpendPolicy {
-    fn default() -> Self {
-        ChangeSpendPolicy::ChangeAllowed
-    }
-}
-
 impl ChangeSpendPolicy {
     pub(crate) fn is_satisfied_by(&self, utxo: &LocalOutput) -> bool {
         match self {
index 4047f8fcb82a53e323055299e3ba3241be154f0e..8df1b119756e7a46534f5991971902467efb292b 100644 (file)
@@ -168,9 +168,7 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
     ///
     /// Returns `None` if the `TxOut` hasn't been scanned or if nothing matching was found there.
     pub fn txout(&self, outpoint: OutPoint) -> Option<(&I, &TxOut)> {
-        self.txouts
-            .get(&outpoint)
-            .map(|(spk_i, txout)| (spk_i, txout))
+        self.txouts.get(&outpoint).map(|v| (&v.0, &v.1))
     }
 
     /// Returns the script that has been inserted at the `index`.
index 10cf104466a23128f6ad819d36044567d1eb8a7e..ef15d7e7d8a4fc2dd9d2d0b5f2afcd29adf3443e 100644 (file)
@@ -581,10 +581,7 @@ impl<A: Clone + Ord> TxGraph<A> {
         }
 
         for (outpoint, txout) in changeset.txouts {
-            let tx_entry = self
-                .txs
-                .entry(outpoint.txid)
-                .or_insert_with(Default::default);
+            let tx_entry = self.txs.entry(outpoint.txid).or_default();
 
             match tx_entry {
                 (TxNodeInternal::Whole(_), _, _) => { /* do nothing since we already have full tx */
@@ -597,13 +594,13 @@ impl<A: Clone + Ord> TxGraph<A> {
 
         for (anchor, txid) in changeset.anchors {
             if self.anchors.insert((anchor.clone(), txid)) {
-                let (_, anchors, _) = self.txs.entry(txid).or_insert_with(Default::default);
+                let (_, anchors, _) = self.txs.entry(txid).or_default();
                 anchors.insert(anchor);
             }
         }
 
         for (txid, new_last_seen) in changeset.last_seen {
-            let (_, _, last_seen) = self.txs.entry(txid).or_insert_with(Default::default);
+            let (_, _, last_seen) = self.txs.entry(txid).or_default();
             if new_last_seen > *last_seen {
                 *last_seen = new_last_seen;
             }
index cfb8b7c4496b7e62c4f6adfbabfd1c5a978b111b..7cc3f57a9bf446a1906b869e671ae6b8f0be3818 100644 (file)
@@ -1,4 +1,5 @@
 mod tx_template;
+#[allow(unused_imports)]
 pub use tx_template::*;
 
 #[allow(unused_macros)]
index e54007cd93b83f183a40ba58abb914835323007d..216755a1364b7cd656246c7fb17a016e2a45628a 100644 (file)
@@ -477,7 +477,7 @@ fn populate_with_txids(
 
         let spk = tx
             .output
-            .get(0)
+            .first()
             .map(|txo| &txo.script_pubkey)
             .expect("tx must have an output");