From 9c4a8ec711f74a018f68f7665272d83c0f5b8dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Fri, 29 Dec 2023 19:15:57 +0800 Subject: [PATCH] chore: make clippy happy --- .github/workflows/cont_integration.yml | 2 +- clippy.toml | 2 +- crates/bdk/src/wallet/signer.rs | 9 ++------- crates/bdk/src/wallet/tx_builder.rs | 18 ++++-------------- crates/chain/src/spk_txout_index.rs | 4 +--- crates/chain/src/tx_graph.rs | 9 +++------ crates/electrum/src/electrum_ext.rs | 2 +- 7 files changed, 13 insertions(+), 33 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 6281c465ca..3dfb9906c3 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -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 diff --git a/clippy.toml b/clippy.toml index 3f726dbda5..69478ceabd 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv="1.57.0" +msrv="1.63.0" diff --git a/crates/bdk/src/wallet/signer.rs b/crates/bdk/src/wallet/signer.rs index da4940bf93..18e2062fb4 100644 --- a/crates/bdk/src/wallet/signer.rs +++ b/crates/bdk/src/wallet/signer.rs @@ -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 { diff --git a/crates/bdk/src/wallet/tx_builder.rs b/crates/bdk/src/wallet/tx_builder.rs index 86decc8bb7..f914aaefa7 100644 --- a/crates/bdk/src/wallet/tx_builder.rs +++ b/crates/bdk/src/wallet/tx_builder.rs @@ -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 { diff --git a/crates/chain/src/spk_txout_index.rs b/crates/chain/src/spk_txout_index.rs index 4047f8fcb8..8df1b11975 100644 --- a/crates/chain/src/spk_txout_index.rs +++ b/crates/chain/src/spk_txout_index.rs @@ -168,9 +168,7 @@ impl SpkTxOutIndex { /// /// 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`. diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 10cf104466..ef15d7e7d8 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -581,10 +581,7 @@ impl TxGraph { } 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 TxGraph { 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; } diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index e54007cd93..216755a136 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -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");