chore: make clippy happy and bump clippy msrv

This commit is contained in:
志宇 2023-12-29 19:15:57 +08:00
parent c9467dcbb2
commit 1def76f1f1
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8
9 changed files with 16 additions and 35 deletions

View File

@ -118,7 +118,7 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: "stable" toolchain: stable
components: clippy components: clippy
override: true override: true
- name: Rust Cache - name: Rust Cache

View File

@ -1 +1 @@
msrv="1.57.0" msrv="1.63.0"

View File

@ -575,7 +575,7 @@ mod test {
if let ExtendedDescriptor::Pkh(pkh) = xdesc.0 { if let ExtendedDescriptor::Pkh(pkh) = xdesc.0 {
let path: Vec<ChildNumber> = pkh.into_inner().full_derivation_path().unwrap().into(); 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 }); assert_matches!(purpose, Hardened { index: 44 });
let coin_type = path.get(1).unwrap(); let coin_type = path.get(1).unwrap();
assert_matches!(coin_type, Hardened { index: 0 }); assert_matches!(coin_type, Hardened { index: 0 });
@ -589,7 +589,7 @@ mod test {
if let ExtendedDescriptor::Pkh(pkh) = tdesc.0 { if let ExtendedDescriptor::Pkh(pkh) = tdesc.0 {
let path: Vec<ChildNumber> = pkh.into_inner().full_derivation_path().unwrap().into(); 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 }); assert_matches!(purpose, Hardened { index: 44 });
let coin_type = path.get(1).unwrap(); let coin_type = path.get(1).unwrap();
assert_matches!(coin_type, Hardened { index: 1 }); assert_matches!(coin_type, Hardened { index: 1 });

View File

@ -812,9 +812,10 @@ pub struct SignOptions {
} }
/// Customize which taproot script-path leaves the signer should sign. /// Customize which taproot script-path leaves the signer should sign.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Default, Debug, Clone, PartialEq, Eq)]
pub enum TapLeavesOptions { pub enum TapLeavesOptions {
/// The signer will sign all the leaves it has a key for. /// The signer will sign all the leaves it has a key for.
#[default]
All, All,
/// The signer won't sign leaves other than the ones specified. Note that it could still ignore /// 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. /// some of the specified leaves, if it doesn't have the right key to sign them.
@ -825,12 +826,6 @@ pub enum TapLeavesOptions {
None, None,
} }
impl Default for TapLeavesOptions {
fn default() -> Self {
TapLeavesOptions::All
}
}
#[allow(clippy::derivable_impls)] #[allow(clippy::derivable_impls)]
impl Default for SignOptions { impl Default for SignOptions {
fn default() -> Self { fn default() -> Self {

View File

@ -811,9 +811,10 @@ impl<'a, D> TxBuilder<'a, D, DefaultCoinSelectionAlgorithm, BumpFee> {
} }
/// Ordering of the transaction's inputs and outputs /// 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 { pub enum TxOrdering {
/// Randomized (default) /// Randomized (default)
#[default]
Shuffle, Shuffle,
/// Unchanged /// Unchanged
Untouched, Untouched,
@ -821,12 +822,6 @@ pub enum TxOrdering {
Bip69Lexicographic, Bip69Lexicographic,
} }
impl Default for TxOrdering {
fn default() -> Self {
TxOrdering::Shuffle
}
}
impl TxOrdering { impl TxOrdering {
/// Sort transaction inputs and outputs by [`TxOrdering`] variant /// Sort transaction inputs and outputs by [`TxOrdering`] variant
pub fn sort_tx(&self, tx: &mut Transaction) { 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 /// 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 { pub enum ChangeSpendPolicy {
/// Use both change and non-change outputs (default) /// Use both change and non-change outputs (default)
#[default]
ChangeAllowed, ChangeAllowed,
/// Only use change outputs (see [`TxBuilder::only_spend_change`]) /// Only use change outputs (see [`TxBuilder::only_spend_change`])
OnlyChange, OnlyChange,
@ -890,12 +886,6 @@ pub enum ChangeSpendPolicy {
ChangeForbidden, ChangeForbidden,
} }
impl Default for ChangeSpendPolicy {
fn default() -> Self {
ChangeSpendPolicy::ChangeAllowed
}
}
impl ChangeSpendPolicy { impl ChangeSpendPolicy {
pub(crate) fn is_satisfied_by(&self, utxo: &LocalOutput) -> bool { pub(crate) fn is_satisfied_by(&self, utxo: &LocalOutput) -> bool {
match self { match self {

View 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. /// 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)> { pub fn txout(&self, outpoint: OutPoint) -> Option<(&I, &TxOut)> {
self.txouts self.txouts.get(&outpoint).map(|v| (&v.0, &v.1))
.get(&outpoint)
.map(|(spk_i, txout)| (spk_i, txout))
} }
/// Returns the script that has been inserted at the `index`. /// Returns the script that has been inserted at the `index`.

View File

@ -581,10 +581,7 @@ impl<A: Clone + Ord> TxGraph<A> {
} }
for (outpoint, txout) in changeset.txouts { for (outpoint, txout) in changeset.txouts {
let tx_entry = self let tx_entry = self.txs.entry(outpoint.txid).or_default();
.txs
.entry(outpoint.txid)
.or_insert_with(Default::default);
match tx_entry { match tx_entry {
(TxNodeInternal::Whole(_), _, _) => { /* do nothing since we already have full tx */ (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 { for (anchor, txid) in changeset.anchors {
if self.anchors.insert((anchor.clone(), txid)) { 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); anchors.insert(anchor);
} }
} }
for (txid, new_last_seen) in changeset.last_seen { 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 { if new_last_seen > *last_seen {
*last_seen = new_last_seen; *last_seen = new_last_seen;
} }

View File

@ -1,4 +1,5 @@
mod tx_template; mod tx_template;
#[allow(unused_imports)]
pub use tx_template::*; pub use tx_template::*;
#[allow(unused_macros)] #[allow(unused_macros)]

View File

@ -477,7 +477,7 @@ fn populate_with_txids(
let spk = tx let spk = tx
.output .output
.get(0) .first()
.map(|txo| &txo.script_pubkey) .map(|txo| &txo.script_pubkey)
.expect("tx must have an output"); .expect("tx must have an output");