Skip to content

Commit 4974d61

Browse files
committed
refactor(chain,bdk): fix clippy warnings
fix "use of `or_insert_with` to construct default value" fix "this `impl` can be derived"
1 parent 2ba955f commit 4974d61

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv="1.57.0"
1+
msrv="1.63.0"

crates/bdk/src/wallet/signer.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,10 @@ pub struct SignOptions {
812812
}
813813

814814
/// Customize which taproot script-path leaves the signer should sign.
815-
#[derive(Debug, Clone, PartialEq, Eq)]
815+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
816816
pub enum TapLeavesOptions {
817817
/// The signer will sign all the leaves it has a key for.
818+
#[default]
818819
All,
819820
/// The signer won't sign leaves other than the ones specified. Note that it could still ignore
820821
/// some of the specified leaves, if it doesn't have the right key to sign them.
@@ -825,12 +826,6 @@ pub enum TapLeavesOptions {
825826
None,
826827
}
827828

828-
impl Default for TapLeavesOptions {
829-
fn default() -> Self {
830-
TapLeavesOptions::All
831-
}
832-
}
833-
834829
#[allow(clippy::derivable_impls)]
835830
impl Default for SignOptions {
836831
fn default() -> Self {

crates/bdk/src/wallet/tx_builder.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -811,22 +811,17 @@ impl<'a, D> TxBuilder<'a, D, DefaultCoinSelectionAlgorithm, BumpFee> {
811811
}
812812

813813
/// Ordering of the transaction's inputs and outputs
814-
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
814+
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy, Default)]
815815
pub enum TxOrdering {
816816
/// Randomized (default)
817+
#[default]
817818
Shuffle,
818819
/// Unchanged
819820
Untouched,
820821
/// BIP69 / Lexicographic
821822
Bip69Lexicographic,
822823
}
823824

824-
impl Default for TxOrdering {
825-
fn default() -> Self {
826-
TxOrdering::Shuffle
827-
}
828-
}
829-
830825
impl TxOrdering {
831826
/// Sort transaction inputs and outputs by [`TxOrdering`] variant
832827
pub fn sort_tx(&self, tx: &mut Transaction) {
@@ -880,22 +875,17 @@ impl RbfValue {
880875
}
881876

882877
/// Policy regarding the use of change outputs when creating a transaction
883-
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
878+
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy, Default)]
884879
pub enum ChangeSpendPolicy {
885880
/// Use both change and non-change outputs (default)
881+
#[default]
886882
ChangeAllowed,
887883
/// Only use change outputs (see [`TxBuilder::only_spend_change`])
888884
OnlyChange,
889885
/// Only use non-change outputs (see [`TxBuilder::do_not_spend_change`])
890886
ChangeForbidden,
891887
}
892888

893-
impl Default for ChangeSpendPolicy {
894-
fn default() -> Self {
895-
ChangeSpendPolicy::ChangeAllowed
896-
}
897-
}
898-
899889
impl ChangeSpendPolicy {
900890
pub(crate) fn is_satisfied_by(&self, utxo: &LocalOutput) -> bool {
901891
match self {

crates/chain/src/tx_graph.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,7 @@ impl<A: Clone + Ord> TxGraph<A> {
581581
}
582582

583583
for (outpoint, txout) in changeset.txouts {
584-
let tx_entry = self
585-
.txs
586-
.entry(outpoint.txid)
587-
.or_insert_with(Default::default);
584+
let tx_entry = self.txs.entry(outpoint.txid).or_default();
588585

589586
match tx_entry {
590587
(TxNodeInternal::Whole(_), _, _) => { /* do nothing since we already have full tx */
@@ -597,13 +594,13 @@ impl<A: Clone + Ord> TxGraph<A> {
597594

598595
for (anchor, txid) in changeset.anchors {
599596
if self.anchors.insert((anchor.clone(), txid)) {
600-
let (_, anchors, _) = self.txs.entry(txid).or_insert_with(Default::default);
597+
let (_, anchors, _) = self.txs.entry(txid).or_default();
601598
anchors.insert(anchor);
602599
}
603600
}
604601

605602
for (txid, new_last_seen) in changeset.last_seen {
606-
let (_, _, last_seen) = self.txs.entry(txid).or_insert_with(Default::default);
603+
let (_, _, last_seen) = self.txs.entry(txid).or_default();
607604
if new_last_seen > *last_seen {
608605
*last_seen = new_last_seen;
609606
}

0 commit comments

Comments
 (0)