[ci] Fix clippy warnings, enable clippy checks

This commit is contained in:
Steve Myers
2020-10-07 14:18:50 -07:00
parent 6402fd07c2
commit aea9abff8a
15 changed files with 69 additions and 68 deletions

View File

@@ -57,7 +57,7 @@ impl From<crate::keys::KeyError> for Error {
match key_error {
crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
crate::keys::KeyError::BIP32(inner) => Error::BIP32(inner),
e @ _ => Error::Key(e),
e => Error::Key(e),
}
}
}

View File

@@ -78,8 +78,8 @@ impl ToWalletDescriptor for &str {
self,
network: Network,
) -> Result<(ExtendedDescriptor, KeyMap), KeyError> {
let descriptor = if self.contains("#") {
let parts: Vec<&str> = self.splitn(2, "#").collect();
let descriptor = if self.contains('#') {
let parts: Vec<&str> = self.splitn(2, '#').collect();
if !get_checksum(parts[0])
.ok()
.map(|computed| computed == parts[1])
@@ -171,7 +171,7 @@ impl ToWalletDescriptor for (ExtendedDescriptor, KeyMap, ValidNetworks) {
DescriptorPublicKey::XPub(xpub)
}
other @ _ => other.clone(),
other => other.clone(),
};
Ok(pk)
@@ -201,19 +201,19 @@ pub(crate) trait XKeyUtils {
impl<K: InnerXKey> XKeyUtils for DescriptorXKey<K> {
fn full_path(&self, append: &[ChildNumber]) -> DerivationPath {
let full_path = match &self.source {
&Some((_, ref path)) => path
let full_path = match self.source {
Some((_, ref path)) => path
.into_iter()
.chain(self.derivation_path.into_iter())
.cloned()
.collect(),
&None => self.derivation_path.clone(),
None => self.derivation_path.clone(),
};
if self.is_wildcard {
full_path
.into_iter()
.chain(append.into_iter())
.chain(append.iter())
.cloned()
.collect()
} else {
@@ -222,9 +222,9 @@ impl<K: InnerXKey> XKeyUtils for DescriptorXKey<K> {
}
fn root_fingerprint(&self) -> Fingerprint {
match &self.source {
&Some((fingerprint, _)) => fingerprint.clone(),
&None => self.xkey.xkey_fingerprint(),
match self.source {
Some((fingerprint, _)) => fingerprint,
None => self.xkey.xkey_fingerprint(),
}
}
}

View File

@@ -43,7 +43,7 @@
//! # Ok::<(), bdk::Error>(())
//! ```
use std::cmp::max;
use std::cmp::{max, Ordering};
use std::collections::{BTreeMap, HashSet, VecDeque};
use std::fmt;
use std::sync::Arc;
@@ -155,7 +155,7 @@ impl SatisfiableItem {
}
}
fn combinations(vec: &Vec<usize>, size: usize) -> Vec<Vec<usize>> {
fn combinations(vec: &[usize], size: usize) -> Vec<Vec<usize>> {
assert!(vec.len() >= size);
let mut answer = Vec::new();
@@ -344,8 +344,8 @@ impl Satisfaction {
.map(|i| {
conditions
.get(i)
.and_then(|set| Some(set.clone().into_iter().collect()))
.unwrap_or(vec![])
.map(|set| set.clone().into_iter().collect())
.unwrap_or_default()
})
.collect())
.into_iter()
@@ -525,7 +525,7 @@ impl Policy {
}
fn make_multisig(
keys: &Vec<DescriptorPublicKey>,
keys: &[DescriptorPublicKey],
signers: Arc<SignersContainer<DescriptorPublicKey>>,
threshold: usize,
) -> Result<Option<Policy>, PolicyError> {
@@ -542,7 +542,7 @@ impl Policy {
conditions: Default::default(),
};
for (index, key) in keys.iter().enumerate() {
if let Some(_) = signers.find(signer_id(key)) {
if signers.find(signer_id(key)).is_some() {
contribution.add(
&Satisfaction::Complete {
condition: Default::default(),
@@ -582,7 +582,7 @@ impl Policy {
// if items.len() == threshold, selected can be omitted and we take all of them by default
let default = match &self.item {
SatisfiableItem::Thresh { items, threshold } if items.len() == *threshold => {
(0..*threshold).into_iter().collect()
(0..*threshold).collect()
}
_ => vec![],
};
@@ -608,10 +608,14 @@ impl Policy {
// if we have something, make sure we have enough items. note that the user can set
// an empty value for this step in case of n-of-n, because `selected` is set to all
// the elements above
if selected.len() < *threshold {
return Err(PolicyError::NotEnoughItemsSelected(self.id.clone()));
} else if selected.len() > *threshold {
return Err(PolicyError::TooManyItemsSelected(self.id.clone()));
match selected.len().cmp(threshold) {
Ordering::Less => {
return Err(PolicyError::NotEnoughItemsSelected(self.id.clone()))
}
Ordering::Greater => {
return Err(PolicyError::TooManyItemsSelected(self.id.clone()))
}
Ordering::Equal => (),
}
// check the selected items, see if there are conflicting requirements
@@ -676,7 +680,7 @@ fn signature_key(
) -> Policy {
let mut policy: Policy = SatisfiableItem::Signature(PKOrF::from_key_hash(*key_hash)).into();
if let Some(_) = signers.find(SignerId::PkHash(*key_hash)) {
if signers.find(SignerId::PkHash(*key_hash)).is_some() {
policy.contribution = Satisfaction::Complete {
condition: Default::default(),
}