]> Untitled Git - bdk/commitdiff
Remove redundant borrows
authorTobin Harding <me@tobin.cc>
Tue, 8 Jun 2021 03:57:55 +0000 (13:57 +1000)
committerTobin Harding <me@tobin.cc>
Thu, 10 Jun 2021 03:16:07 +0000 (13:16 +1000)
Clippy emits:

  warning: this expression borrows a reference

As suggested remove the borrows from the front of vars that are already references.

src/blockchain/utils.rs
src/database/keyvalue.rs
src/database/memory.rs
src/descriptor/mod.rs
src/descriptor/policy.rs
src/types.rs
src/wallet/mod.rs
src/wallet/signer.rs

index 4d3a97a1ce9199d5861bcd21a3589a25abda7b61..ac86520ca844ac564864c14032a4bc4e12c697f2 100644 (file)
@@ -158,7 +158,7 @@ pub trait ElectrumLikeSync {
                 }
             } else {
                 save_transaction_details_and_utxos(
-                    &txid,
+                    txid,
                     db,
                     timestamp,
                     height,
@@ -171,7 +171,7 @@ pub trait ElectrumLikeSync {
         // remove any tx details in db but not in history_txs_id
         for txid in txs_details_in_db.keys() {
             if !history_txs_id.contains(txid) {
-                batch.del_tx(&txid, false)?;
+                batch.del_tx(txid, false)?;
             }
         }
 
@@ -329,7 +329,7 @@ fn save_transaction_details_and_utxos<D: BatchDatabase>(
 
         // removes conflicting UTXO if any (generated from same inputs, like for example RBF)
         if let Some(outpoint) = utxo_deps.get(&input.previous_output) {
-            updates.del_utxo(&outpoint)?;
+            updates.del_utxo(outpoint)?;
         }
     }
 
index 20662a140f7ab9d56c09496837862bc5270e9281..201fc2561c642792cd6506c91443f6ecb8d48f03 100644 (file)
@@ -320,7 +320,7 @@ impl Database for Tree {
             .map(|b| -> Result<_, Error> {
                 let mut txdetails: TransactionDetails = serde_json::from_slice(&b)?;
                 if include_raw {
-                    txdetails.transaction = self.get_raw_tx(&txid)?;
+                    txdetails.transaction = self.get_raw_tx(txid)?;
                 }
 
                 Ok(txdetails)
index adf4e20f34a905d3eacc94e54ce018480c81b9c6..964348afe6bdb12a8e9110d8369e07ccc6c32194 100644 (file)
@@ -394,7 +394,7 @@ impl Database for MemoryDatabase {
         Ok(self.map.get(&key).map(|b| {
             let mut txdetails: TransactionDetails = b.downcast_ref().cloned().unwrap();
             if include_raw {
-                txdetails.transaction = self.get_raw_tx(&txid).unwrap();
+                txdetails.transaction = self.get_raw_tx(txid).unwrap();
             }
 
             txdetails
index 92c149a594dfca0bbc48157d1b2de38baa82b045..69247905c8f86ce0761c3e8bb9676cec08a364c3 100644 (file)
@@ -128,11 +128,11 @@ impl IntoWalletDescriptor for (ExtendedDescriptor, KeyMap) {
             let (pk, _, networks) = if self.0.is_witness() {
                 let desciptor_key: DescriptorKey<miniscript::Segwitv0> =
                     pk.clone().into_descriptor_key()?;
-                desciptor_key.extract(&secp)?
+                desciptor_key.extract(secp)?
             } else {
                 let desciptor_key: DescriptorKey<miniscript::Legacy> =
                     pk.clone().into_descriptor_key()?;
-                desciptor_key.extract(&secp)?
+                desciptor_key.extract(secp)?
             };
 
             if networks.contains(&network) {
index ba28bf4a389fc44cf4ecbd5acd6a31a7610b78c8..3aebcfad3eb69ee4034e3b8337c8d2d069181229 100644 (file)
@@ -336,7 +336,7 @@ impl Satisfaction {
                         items.push(inner_index);
                         let conditions_set = other_conditions
                             .values()
-                            .fold(HashSet::new(), |set, i| set.union(&i).cloned().collect());
+                            .fold(HashSet::new(), |set, i| set.union(i).cloned().collect());
                         conditions.insert(inner_index, conditions_set);
                     }
                 }
@@ -1031,8 +1031,8 @@ mod test {
     ) -> (DescriptorKey<Ctx>, DescriptorKey<Ctx>, Fingerprint) {
         let path = bip32::DerivationPath::from_str(path).unwrap();
         let tprv = bip32::ExtendedPrivKey::from_str(tprv).unwrap();
-        let tpub = bip32::ExtendedPubKey::from_private(&secp, &tprv);
-        let fingerprint = tprv.fingerprint(&secp);
+        let tpub = bip32::ExtendedPubKey::from_private(secp, &tprv);
+        let fingerprint = tprv.fingerprint(secp);
         let prvkey = (tprv, path.clone()).into_descriptor_key().unwrap();
         let pubkey = (tpub, path).into_descriptor_key().unwrap();
 
index 780a6521ee24ad8d16a57ab2cb1da73013371763..b0d43db07200abf6c7de14f5ddb99e8f3a78b45e 100644 (file)
@@ -139,7 +139,7 @@ impl Utxo {
                 }
 
                 if let Some(txout) = &psbt_input.witness_utxo {
-                    return &txout;
+                    return txout;
                 }
 
                 unreachable!("Foreign UTXOs will always have one of these set")
index 0ec2a95ebcf1bea4b0926d00660e05ae31c3a40b..054aad1513ffa799d9149046473ddd30cbc78c89 100644 (file)
@@ -398,7 +398,7 @@ where
     /// [`TxBuilder`]: crate::TxBuilder
     pub fn build_tx(&self) -> TxBuilder<'_, B, D, DefaultCoinSelectionAlgorithm, CreateTx> {
         TxBuilder {
-            wallet: &self,
+            wallet: self,
             params: TxParams::default(),
             coin_selection: DefaultCoinSelectionAlgorithm::default(),
             phantom: core::marker::PhantomData,
@@ -861,7 +861,7 @@ where
         };
 
         Ok(TxBuilder {
-            wallet: &self,
+            wallet: self,
             params,
             coin_selection: DefaultCoinSelectionAlgorithm::default(),
             phantom: core::marker::PhantomData,
@@ -1031,7 +1031,7 @@ where
                     match desc.satisfy(
                         &mut tmp_input,
                         (
-                            PsbtInputSatisfier::new(&psbt, n),
+                            PsbtInputSatisfier::new(psbt, n),
                             After::new(current_height, false),
                             Older::new(current_height, create_height, false),
                         ),
index cf901c6a042caee01f1d0e72a16ee08475708039..bd25b74d949c6aa9ed0b68eb34a3cde777186e9f 100644 (file)
@@ -222,7 +222,7 @@ impl Signer for DescriptorXKey<ExtendedPrivKey> {
             .bip32_derivation
             .iter()
             .filter_map(|(pk, &(fingerprint, ref path))| {
-                if self.matches(&(fingerprint, path.clone()), &secp).is_some() {
+                if self.matches(&(fingerprint, path.clone()), secp).is_some() {
                     Some((pk, path))
                 } else {
                     None
@@ -240,12 +240,12 @@ impl Signer for DescriptorXKey<ExtendedPrivKey> {
                     &full_path.into_iter().cloned().collect::<Vec<ChildNumber>>()
                         [origin_path.len()..],
                 );
-                self.xkey.derive_priv(&secp, &deriv_path).unwrap()
+                self.xkey.derive_priv(secp, &deriv_path).unwrap()
             }
-            None => self.xkey.derive_priv(&secp, &full_path).unwrap(),
+            None => self.xkey.derive_priv(secp, &full_path).unwrap(),
         };
 
-        if &derived_key.private_key.public_key(&secp) != public_key {
+        if &derived_key.private_key.public_key(secp) != public_key {
             Err(SignerError::InvalidKey)
         } else {
             derived_key.private_key.sign(psbt, Some(input_index), secp)
@@ -257,7 +257,7 @@ impl Signer for DescriptorXKey<ExtendedPrivKey> {
     }
 
     fn id(&self, secp: &SecpCtx) -> SignerId {
-        SignerId::from(self.root_fingerprint(&secp))
+        SignerId::from(self.root_fingerprint(secp))
     }
 
     fn descriptor_secret_key(&self) -> Option<DescriptorSecretKey> {
@@ -283,7 +283,7 @@ impl Signer for PrivateKey {
             return Ok(());
         }
 
-        let pubkey = self.public_key(&secp);
+        let pubkey = self.public_key(secp);
         if psbt.inputs[input_index].partial_sigs.contains_key(&pubkey) {
             return Ok(());
         }
@@ -591,7 +591,7 @@ impl ComputeSighash for Segwitv0 {
                     .map(Script::is_v0_p2wpkh)
                     .unwrap_or(false)
                 {
-                    p2wpkh_script_code(&psbt_input.redeem_script.as_ref().unwrap())
+                    p2wpkh_script_code(psbt_input.redeem_script.as_ref().unwrap())
                 } else {
                     return Err(SignerError::MissingWitnessScript);
                 }