Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
Disabled warnings for nursery/tmp_plan as it's going to be replaced
anyways
  • Loading branch information
danielabrozzoni committed Mar 3, 2023
1 parent 1805bd3 commit c61b360
Show file tree
Hide file tree
Showing 26 changed files with 140 additions and 154 deletions.
32 changes: 16 additions & 16 deletions crates/bdk/src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,26 @@ pub(crate) trait DescriptorMeta {
fn is_witness(&self) -> bool;
fn is_taproot(&self) -> bool;
fn get_extended_keys(&self) -> Vec<DescriptorXKey<ExtendedPubKey>>;
fn derive_from_hd_keypaths<'s>(
fn derive_from_hd_keypaths(
&self,
hd_keypaths: &HdKeyPaths,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor>;
fn derive_from_tap_key_origins<'s>(
fn derive_from_tap_key_origins(
&self,
tap_key_origins: &TapKeyOrigins,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor>;
fn derive_from_psbt_key_origins<'s>(
fn derive_from_psbt_key_origins(
&self,
key_origins: BTreeMap<Fingerprint, (&DerivationPath, SinglePubKey)>,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor>;
fn derive_from_psbt_input<'s>(
fn derive_from_psbt_input(
&self,
psbt_input: &psbt::Input,
utxo: Option<TxOut>,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor>;
}

Expand Down Expand Up @@ -410,10 +410,10 @@ impl DescriptorMeta for ExtendedDescriptor {
answer
}

fn derive_from_psbt_key_origins<'s>(
fn derive_from_psbt_key_origins(
&self,
key_origins: BTreeMap<Fingerprint, (&DerivationPath, SinglePubKey)>,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor> {
// Ensure that deriving `xpub` with `path` yields `expected`
let verify_key = |xpub: &DescriptorXKey<ExtendedPubKey>,
Expand Down Expand Up @@ -497,10 +497,10 @@ impl DescriptorMeta for ExtendedDescriptor {
path_found.map(|path| self.at_derivation_index(path))
}

fn derive_from_hd_keypaths<'s>(
fn derive_from_hd_keypaths(
&self,
hd_keypaths: &HdKeyPaths,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor> {
// "Convert" an hd_keypaths map to the format required by `derive_from_psbt_key_origins`
let key_origins = hd_keypaths
Expand All @@ -515,10 +515,10 @@ impl DescriptorMeta for ExtendedDescriptor {
self.derive_from_psbt_key_origins(key_origins, secp)
}

fn derive_from_tap_key_origins<'s>(
fn derive_from_tap_key_origins(
&self,
tap_key_origins: &TapKeyOrigins,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor> {
// "Convert" a tap_key_origins map to the format required by `derive_from_psbt_key_origins`
let key_origins = tap_key_origins
Expand All @@ -528,11 +528,11 @@ impl DescriptorMeta for ExtendedDescriptor {
self.derive_from_psbt_key_origins(key_origins, secp)
}

fn derive_from_psbt_input<'s>(
fn derive_from_psbt_input(
&self,
psbt_input: &psbt::Input,
utxo: Option<TxOut>,
secp: &'s SecpCtx,
secp: &SecpCtx,
) -> Option<DerivedDescriptor> {
if let Some(derived) = self.derive_from_hd_keypaths(&psbt_input.bip32_derivation, secp) {
return Some(derived);
Expand Down
2 changes: 1 addition & 1 deletion crates/bdk/src/wallet/coin_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ mod test {
fn get_test_utxos() -> Vec<WeightedUtxo> {
vec![
utxo(100_000, 0, ConfirmationTime::Unconfirmed),
utxo(FEE_AMOUNT as u64 - 40, 1, ConfirmationTime::Unconfirmed),
utxo(FEE_AMOUNT - 40, 1, ConfirmationTime::Unconfirmed),
utxo(200_000, 2, ConfirmationTime::Unconfirmed),
]
}
Expand Down
10 changes: 4 additions & 6 deletions crates/bdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,12 @@ impl<D> Wallet<D> {
.last()
.unwrap(),
};
let info = AddressInfo {
AddressInfo {
index,
address: Address::from_script(&spk, self.network)
.expect("descriptor must have address form"),
keychain,
};
info
}
}

/// Return whether or not a `script` is part of this wallet (either internal or external)
Expand All @@ -342,7 +341,7 @@ impl<D> Wallet<D> {
.map(|(&(keychain, derivation_index), utxo)| LocalUtxo {
outpoint: utxo.outpoint,
txout: utxo.txout,
keychain: keychain.clone(),
keychain,
is_spent: false,
derivation_index,
confirmation_time: utxo.chain_position,
Expand Down Expand Up @@ -1288,8 +1287,7 @@ impl<D> Wallet<D> {
// - If that also fails, it will try it on the internal descriptor, if present
let desc = psbt
.get_utxo_for(n)
.map(|txout| self.get_descriptor_for_txout(&txout))
.flatten()
.and_then(|txout| self.get_descriptor_for_txout(&txout))
.or_else(|| {
self.keychain_tracker
.txout_index
Expand Down
2 changes: 1 addition & 1 deletion crates/bdk/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ fn test_bump_fee_add_input() {
}],
};
wallet
.insert_tx(init_tx.clone(), wallet.transactions().last().unwrap().0)
.insert_tx(init_tx, wallet.transactions().last().unwrap().0)
.unwrap();

let addr = Address::from_str("2N1Ffz3WaNzbeLFBb51xyFMHYSEUXcbiSoX").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/chain/src/chain_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ where
}

/// Calculates the difference between self and `update` in the form of a [`ChangeSet`].
pub fn determine_changeset<'a, T2>(
pub fn determine_changeset<T2>(
&self,
update: &ChainGraph<P, T2>,
) -> Result<ChangeSet<P, T>, UpdateError<P>>
Expand Down Expand Up @@ -366,7 +366,7 @@ where
// evicted, return error
return Err(UnresolvableConflict {
already_confirmed_tx: (conflicting_pos.clone(), conflicting_txid),
update_tx: (update_pos.clone(), update_txid),
update_tx: (update_pos, update_txid),
});
}
TxHeight::Unconfirmed => {
Expand Down Expand Up @@ -516,7 +516,7 @@ impl<P: core::fmt::Debug> core::fmt::Display for NewError<P> {
f,
"missing full transactions for {}",
missing
.into_iter()
.iter()
.map(|txid| txid.to_string())
.collect::<Vec<_>>()
.join(", ")
Expand Down
8 changes: 4 additions & 4 deletions crates/chain/src/example_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use bitcoin::{

use crate::BlockId;

pub const RAW_TX_1: &'static str = "0200000000010116d6174da7183d70d0a7d4dc314d517a7d135db79ad63515028b293a76f4f9d10000000000feffffff023a21fc8350060000160014531c405e1881ef192294b8813631e258bf98ea7a1027000000000000225120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c024730440220591b1a172a122da49ba79a3e79f98aaa03fd7a372f9760da18890b6a327e6010022013e82319231da6c99abf8123d7c07e13cf9bd8d76e113e18dc452e5024db156d012102318a2d558b2936c52e320decd6d92a88d7f530be91b6fe0af5caf41661e77da3ef2e0100";
pub const RAW_TX_2: &'static str = "02000000000101a688607020cfae91a61e7c516b5ef1264d5d77f17200c3866826c6c808ebf1620000000000feffffff021027000000000000225120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c20fd48ff530600001600146886c525e41d4522042bd0b159dfbade2504a6bb024730440220740ff7e665cd20565d4296b549df8d26b941be3f1e3af89a0b60e50c0dbeb69a02206213ab7030cf6edc6c90d4ccf33010644261e029950a688dc0b1a9ebe6ddcc5a012102f2ac6b396a97853cb6cd62242c8ae4842024742074475023532a51e9c53194253e760100";
pub const RAW_TX_3: &'static str = "0200000000010135d67ee47b557e68b8c6223958f597381965ed719f1207ee2b9e20432a24a5dc0100000000feffffff021027000000000000225120a82f29944d65b86ae6b5e5cc75e294ead6c59391a1edc5e016e3498c67fc7bbb62215a5055060000160014070df7671dea67a50c4799a744b5c9be8f4bac690247304402207ebf8d29f71fd03e7e6977b3ea78ca5fcc5c49a42ae822348fc401862fdd766c02201d7e4ff0684ecb008b6142f36ead1b0b4d615524c4f58c261113d361f4427e25012103e6a75e2fab85e5ecad641afc4ffba7222f998649d9f18cac92f0fcc8618883b3ee760100";
pub const RAW_TX_4: &'static str = "02000000000101d00e8f76ed313e19b339ee293c0f52b0325c95e24c8f3966fa353fb2bedbcf580100000000feffffff021027000000000000225120882d74e5d0572d5a816cef0041a96b6c1de832f6f9676d9605c44d5e9a97d3dc9cda55fe53060000160014852b5864b8edd42fab4060c87f818e50780865ff0247304402201dccbb9bed7fba924b6d249c5837cc9b37470c0e3d8fbea77cb59baba3efe6fa0220700cc170916913b9bfc2bc0fefb6af776e8b542c561702f136cddc1c7aa43141012103acec3fc79dbbca745815c2a807dc4e81010c80e308e84913f59cb42a275dad97f3760100";
pub const RAW_TX_1: &str = "0200000000010116d6174da7183d70d0a7d4dc314d517a7d135db79ad63515028b293a76f4f9d10000000000feffffff023a21fc8350060000160014531c405e1881ef192294b8813631e258bf98ea7a1027000000000000225120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c024730440220591b1a172a122da49ba79a3e79f98aaa03fd7a372f9760da18890b6a327e6010022013e82319231da6c99abf8123d7c07e13cf9bd8d76e113e18dc452e5024db156d012102318a2d558b2936c52e320decd6d92a88d7f530be91b6fe0af5caf41661e77da3ef2e0100";
pub const RAW_TX_2: &str = "02000000000101a688607020cfae91a61e7c516b5ef1264d5d77f17200c3866826c6c808ebf1620000000000feffffff021027000000000000225120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c20fd48ff530600001600146886c525e41d4522042bd0b159dfbade2504a6bb024730440220740ff7e665cd20565d4296b549df8d26b941be3f1e3af89a0b60e50c0dbeb69a02206213ab7030cf6edc6c90d4ccf33010644261e029950a688dc0b1a9ebe6ddcc5a012102f2ac6b396a97853cb6cd62242c8ae4842024742074475023532a51e9c53194253e760100";
pub const RAW_TX_3: &str = "0200000000010135d67ee47b557e68b8c6223958f597381965ed719f1207ee2b9e20432a24a5dc0100000000feffffff021027000000000000225120a82f29944d65b86ae6b5e5cc75e294ead6c59391a1edc5e016e3498c67fc7bbb62215a5055060000160014070df7671dea67a50c4799a744b5c9be8f4bac690247304402207ebf8d29f71fd03e7e6977b3ea78ca5fcc5c49a42ae822348fc401862fdd766c02201d7e4ff0684ecb008b6142f36ead1b0b4d615524c4f58c261113d361f4427e25012103e6a75e2fab85e5ecad641afc4ffba7222f998649d9f18cac92f0fcc8618883b3ee760100";
pub const RAW_TX_4: &str = "02000000000101d00e8f76ed313e19b339ee293c0f52b0325c95e24c8f3966fa353fb2bedbcf580100000000feffffff021027000000000000225120882d74e5d0572d5a816cef0041a96b6c1de832f6f9676d9605c44d5e9a97d3dc9cda55fe53060000160014852b5864b8edd42fab4060c87f818e50780865ff0247304402201dccbb9bed7fba924b6d249c5837cc9b37470c0e3d8fbea77cb59baba3efe6fa0220700cc170916913b9bfc2bc0fefb6af776e8b542c561702f136cddc1c7aa43141012103acec3fc79dbbca745815c2a807dc4e81010c80e308e84913f59cb42a275dad97f3760100";

pub fn tx_from_hex(s: &str) -> Transaction {
let raw = Vec::from_hex(s).expect("data must be in hex");
Expand Down
4 changes: 2 additions & 2 deletions crates/chain/src/keychain/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ where

/// Returns a reference to the internal [`TxGraph`] (which is part of the [`ChainGraph`]).
pub fn graph(&self) -> &TxGraph<T> {
&self.chain_graph().graph()
self.chain_graph().graph()
}

/// Returns a reference to the internal [`SparseChain`] (which is part of the [`ChainGraph`]).
pub fn chain(&self) -> &SparseChain<P> {
&self.chain_graph().chain()
self.chain_graph().chain()
}

/// Determines the changes as result of inserting `block_id` (a height and block hash) into the
Expand Down
6 changes: 3 additions & 3 deletions crates/chain/src/keychain/txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::{fmt::Debug, ops::Deref};
use super::DerivationAdditions;

/// Maximum [BIP32](https://bips.xyz/32) derivation index.
pub const BIP32_MAX_INDEX: u32 = 1 << 31 - 1;
pub const BIP32_MAX_INDEX: u32 = (1 << 31) - 1;

/// A convenient wrapper around [`SpkTxOutIndex`] that relates script pubkeys to miniscript public
/// [`Descriptor`]s.
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
pub fn set_lookahead_for_all(&mut self, lookahead: u32) {
for keychain in &self.keychains.keys().cloned().collect::<Vec<_>>() {
self.lookahead.insert(keychain.clone(), lookahead);
self.replenish_lookahead(&keychain);
self.replenish_lookahead(keychain);
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
let mut spks = BTreeMap::new();

for (keychain, &index) in keychains {
let (new_spks, new_additions) = self.reveal_to_target(&keychain, index);
let (new_spks, new_additions) = self.reveal_to_target(keychain, index);
if !new_additions.is_empty() {
spks.insert(keychain.clone(), new_spks);
additions.append(new_additions);
Expand Down
13 changes: 7 additions & 6 deletions crates/chain/src/sparse_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,13 @@ impl<P: ChainPosition> SparseChain<P> {
where
C: IntoIterator<Item = BlockId>,
{
let mut chain = Self::default();
chain.checkpoints = checkpoints
.into_iter()
.map(|block_id| block_id.into())
.collect();
chain
Self {
checkpoints: checkpoints
.into_iter()
.map(|block_id| block_id.into())
.collect(),
..Default::default()
}
}

/// Get the checkpoint for the last known tip.
Expand Down
8 changes: 3 additions & 5 deletions crates/chain/src/spk_txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
if self.outputs_in_range(index..=index).next().is_some() {
return false;
}
return self.unused.insert(index.clone());
self.unused.insert(index.clone())
}

/// Returns the index associated with the script pubkey.
Expand Down Expand Up @@ -300,13 +300,11 @@ impl<I: Clone + Ord> SpkTxOutIndex<I> {
let input_matches = tx
.input
.iter()
.find(|input| self.txouts.contains_key(&input.previous_output))
.is_some();
.any(|input| self.txouts.contains_key(&input.previous_output));
let output_matches = tx
.output
.iter()
.find(|output| self.spk_indices.contains_key(&output.script_pubkey))
.is_some();
.any(|output| self.spk_indices.contains_key(&output.script_pubkey));
input_matches || output_matches
}
}
6 changes: 3 additions & 3 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<T: AsTransaction + Ord + Clone> TxGraph<T> {
///
/// The [`Additions`] would be the set difference of `update` and `self` (transactions that
/// exist in `update` but not in `self`).
pub fn determine_additions<'a, T2>(&self, update: &'a TxGraph<T2>) -> Additions<T>
pub fn determine_additions<T2>(&self, update: &TxGraph<T2>) -> Additions<T>
where
T2: IntoOwned<T> + Clone,
{
Expand All @@ -299,7 +299,7 @@ impl<T: AsTransaction + Ord + Clone> TxGraph<T> {
for (&vout, update_txout) in partial {
let outpoint = OutPoint::new(txid, vout);

if self.get_txout(outpoint) != Some(&update_txout) {
if self.get_txout(outpoint) != Some(update_txout) {
additions.txout.insert(outpoint, update_txout.clone());
}
}
Expand Down Expand Up @@ -627,7 +627,7 @@ where
};

self.populate_stack(op_spends + 1, txid);
return Some(item);
Some(item)
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/chain/tests/test_chain_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn update_evicts_conflicting_tx() {
let _ = cg.insert_checkpoint(cp_a).expect("should insert cp");
let _ = cg.insert_checkpoint(cp_b).expect("should insert cp");
let _ = cg
.insert_tx(tx_a.clone(), TxHeight::Confirmed(0))
.insert_tx(tx_a, TxHeight::Confirmed(0))
.expect("should insert tx");
let _ = cg
.insert_tx(tx_b.clone(), TxHeight::Confirmed(1))
Expand All @@ -213,7 +213,7 @@ fn update_evicts_conflicting_tx() {
.into(),
},
graph: tx_graph::Additions {
tx: [tx_b2.clone()].into(),
tx: [tx_b2].into(),
txout: [].into(),
},
};
Expand Down Expand Up @@ -460,7 +460,7 @@ fn test_apply_changes_reintroduce_tx() {
let mut cg = ChainGraph::default();
let _ = cg.insert_checkpoint(block1).unwrap();
let _ = cg.insert_checkpoint(block2a).unwrap();
let _ = cg.insert_tx(tx1.clone(), TxHeight::Confirmed(1)).unwrap();
let _ = cg.insert_tx(tx1, TxHeight::Confirmed(1)).unwrap();
let _ = cg.insert_tx(tx2a.clone(), TxHeight::Confirmed(2)).unwrap();
cg
};
Expand Down Expand Up @@ -647,7 +647,7 @@ fn test_evict_descendants() {
);

let err = cg
.insert_tx_preview(tx_conflict.clone(), TxHeight::Unconfirmed)
.insert_tx_preview(tx_conflict, TxHeight::Unconfirmed)
.expect_err("must fail due to conflicts");
assert!(matches!(err, InsertTxError::UnresolvableConflict(_)));
}
18 changes: 7 additions & 11 deletions crates/chain/tests/test_keychain_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ fn test_balance() {
let mut tracker = KeychainTracker::<Keychain, TxHeight>::default();
let one = Descriptor::from_str("tr([73c5da0a/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/*)#rg247h69").unwrap();
let two = Descriptor::from_str("tr([73c5da0a/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1/*)#ju05rz2a").unwrap();
tracker.add_keychain(Keychain::One, one.clone());
tracker.add_keychain(Keychain::Two, two.clone());
tracker.add_keychain(Keychain::One, one);
tracker.add_keychain(Keychain::Two, two);

let tx1 = Transaction {
version: 0x01,
Expand Down Expand Up @@ -126,9 +126,9 @@ fn test_balance() {
})
.unwrap();

let should_trust = |keychain: &Keychain| match keychain {
&Keychain::One => false,
&Keychain::Two => true,
let should_trust = |keychain: &Keychain| match *keychain {
Keychain::One => false,
Keychain::Two => true,
};

assert_eq!(tracker.balance(should_trust), Balance::default());
Expand Down Expand Up @@ -172,9 +172,7 @@ fn test_balance() {
}
);

let _ = tracker
.insert_tx(tx1.clone(), TxHeight::Confirmed(1))
.unwrap();
let _ = tracker.insert_tx(tx1, TxHeight::Confirmed(1)).unwrap();

assert_eq!(
tracker.balance(should_trust),
Expand All @@ -186,9 +184,7 @@ fn test_balance() {
}
);

let _ = tracker
.insert_tx(tx2.clone(), TxHeight::Confirmed(2))
.unwrap();
let _ = tracker.insert_tx(tx2, TxHeight::Confirmed(2)).unwrap();

assert_eq!(
tracker.balance(should_trust),
Expand Down
4 changes: 2 additions & 2 deletions crates/chain/tests/test_sparse_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ fn invalidate_a_checkpoint_and_try_and_move_tx_when_it_wasnt_within_invalidation
chain1.determine_changeset(&chain2),
Err(UpdateError::TxInconsistent {
txid: h!("tx0"),
original_pos: TxHeight::Confirmed(0).into(),
update_pos: TxHeight::Confirmed(1).into(),
original_pos: TxHeight::Confirmed(0),
update_pos: TxHeight::Confirmed(1),
})
);
}
Expand Down
Loading

0 comments on commit c61b360

Please sign in to comment.