include:
- rust: stable
features: default
- clippy: false
+ clippy: true
test: true
- rust: 1.45.0
features: default
+ clippy: true
test: true
- rust: nightly
features: test-md-docs
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
+ components: clippy
- name: build
uses: actions-rs/cargo@v1
with:
impl Progress for LogProgress {
fn update(&self, progress: f32, message: Option<String>) -> Result<(), Error> {
- log::info!("Sync {:.3}%: `{}`", progress, message.unwrap_or("".into()));
+ log::info!(
+ "Sync {:.3}%: `{}`",
+ progress,
+ message.unwrap_or_else(|| "".into())
+ );
Ok(())
}
let is_internal = serde_json::from_value(val["i"].take())?;
Ok(UTXO {
- outpoint: outpoint.clone(),
+ outpoint: *outpoint,
txout,
is_internal,
})
fn serialize_content(&self) -> Vec<u8> {
match self {
- MapKey::Path((_, Some(child))) => u32::from(*child).to_be_bytes().to_vec(),
+ MapKey::Path((_, Some(child))) => child.to_be_bytes().to_vec(),
MapKey::Script(Some(s)) => serialize(*s),
MapKey::UTXO(Some(s)) => serialize(*s),
MapKey::RawTx(Some(s)) => serialize(*s),
}
}
-fn after(key: &Vec<u8>) -> Vec<u8> {
- let mut key = key.clone();
+fn after(key: &[u8]) -> Vec<u8> {
+ let mut key = key.to_owned();
let mut idx = key.len();
while idx > 0 {
if key[idx - 1] == 0xFF {
Some(b) => {
let (txout, is_internal) = b.downcast_ref().cloned().unwrap();
Ok(Some(UTXO {
- outpoint: outpoint.clone(),
+ outpoint: *outpoint,
txout,
is_internal,
}))
Ok(self.map.get(&key).map(|b| {
let (txout, is_internal) = b.downcast_ref().cloned().unwrap();
UTXO {
- outpoint: outpoint.clone(),
+ outpoint: *outpoint,
txout,
is_internal,
}
let key = MapKey::LastIndex(script_type).as_map_key();
let value = self
.map
- .entry(key.clone())
+ .entry(key)
.and_modify(|x| *x.downcast_mut::<u32>().unwrap() += 1)
- .or_insert(Box::<u32>::new(0))
+ .or_insert_with(|| Box::<u32>::new(0))
.downcast_mut()
.unwrap();
for key in batch.deleted_keys {
self.map.remove(&key);
}
-
- Ok(self.map.append(&mut batch.map))
+ self.map.append(&mut batch.map);
+ Ok(())
}
}
self.get_raw_tx(&outpoint.txid)?
.map(|previous_tx| {
if outpoint.vout as usize >= previous_tx.output.len() {
- Err(Error::InvalidOutpoint(outpoint.clone()))
+ Err(Error::InvalidOutpoint(*outpoint))
} else {
Ok(previous_tx.output[outpoint.vout as usize].clone())
}
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),
}
}
}
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])
DescriptorPublicKey::XPub(xpub)
}
- other @ _ => other.clone(),
+ other => other.clone(),
};
Ok(pk)
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 {
}
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(),
}
}
}
//! # 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;
}
}
-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();
.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()
}
fn make_multisig(
- keys: &Vec<DescriptorPublicKey>,
+ keys: &[DescriptorPublicKey],
signers: Arc<SignersContainer<DescriptorPublicKey>>,
threshold: usize,
) -> Result<Option<Policy>, PolicyError> {
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(),
// 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![],
};
// 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
) -> 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(),
}
crate::keys::KeyError::Miniscript(inner) => Error::Miniscript(inner),
crate::keys::KeyError::BIP32(inner) => Error::BIP32(inner),
crate::keys::KeyError::InvalidChecksum => Error::ChecksumMismatch,
- e @ _ => Error::Key(e),
+ e => Error::Key(e),
}
}
}
use super::*;
- const test_entropy: [u8; 32] = [0xAA; 32];
+ const TEST_ENTROPY: [u8; 32] = [0xAA; 32];
#[test]
fn test_keys_generate_xprv() {
let generated_xprv: GeneratedKey<_, miniscript::Segwitv0> =
- bip32::ExtendedPrivKey::generate_with_entropy((), test_entropy).unwrap();
+ bip32::ExtendedPrivKey::generate_with_entropy((), TEST_ENTROPY).unwrap();
assert_eq!(generated_xprv.valid_networks, any_network());
assert_eq!(generated_xprv.to_string(), "xprv9s21ZrQH143K4Xr1cJyqTvuL2FWR8eicgY9boWqMBv8MDVUZ65AXHnzBrK1nyomu6wdcabRgmGTaAKawvhAno1V5FowGpTLVx3jxzE5uk3Q");
#[macro_use]
extern crate bdk_macros;
-#[cfg(any(test, feature = "compact_filters"))]
+#[cfg(feature = "compact_filters")]
#[macro_use]
extern crate lazy_static;
impl ScriptType {
pub fn as_byte(&self) -> u8 {
match self {
- ScriptType::External => 'e' as u8,
- ScriptType::Internal => 'i' as u8,
+ ScriptType::External => b'e',
+ ScriptType::Internal => b'i',
}
}
available_utxos,
use_all_utxos,
new_feerate,
- fee_difference
- .checked_sub(removed_change_output.value)
- .unwrap_or(0),
+ fee_difference.saturating_sub(removed_change_output.value),
input_witness_weight,
0.0,
)?;
// copy the n_sequence from the inputs that were already in the transaction
txin.iter_mut()
.for_each(|i| i.sequence = tx.input[0].sequence);
- tx.input.extend_from_slice(&mut txin);
+ tx.input.extend_from_slice(&txin);
details.sent += selected_amount;
selected_amount
.iter()
.map(|txin| {
Ok((
- txin.previous_output.clone(),
+ txin.previous_output,
self.database
.borrow()
.get_previous_output(&txin.previous_output)?,
.database
.borrow()
.get_tx(&input.previous_output.txid, false)?
- .and_then(|tx| Some(tx.height.unwrap_or(std::u32::MAX)));
+ .map(|tx| tx.height.unwrap_or(std::u32::MAX));
let current_height = assume_height.or(self.current_height);
debug!(
&self,
script_type: ScriptType,
) -> (&ExtendedDescriptor, ScriptType) {
- let desc = match script_type {
+ match script_type {
ScriptType::Internal if self.change_descriptor.is_some() => (
self.change_descriptor.as_ref().unwrap(),
ScriptType::Internal,
),
_ => (&self.descriptor, ScriptType::External),
- };
-
- desc
+ }
}
fn get_descriptor_for_txout(&self, txout: &TxOut) -> Result<Option<ExtendedDescriptor>, Error> {
) -> Result<(Vec<UTXO>, bool), Error> {
let unspendable_set = match unspendable {
None => HashSet::new(),
- Some(vec) => vec.into_iter().collect(),
+ Some(vec) => vec.iter().collect(),
};
match utxo {
if self
.database
.borrow()
- .get_script_pubkey_from_path(
- ScriptType::Internal,
- max_address.checked_sub(1).unwrap_or(0),
- )?
+ .get_script_pubkey_from_path(ScriptType::Internal, max_address.saturating_sub(1))?
.is_none()
{
run_setup = true;
.hd_keypaths
.iter()
.filter_map(|(pk, &(fingerprint, ref path))| {
- if self.matches(fingerprint.clone(), &path).is_some() {
+ if self.matches(fingerprint, &path).is_some() {
Some((pk, path))
} else {
None
}
fn descriptor_secret_key(&self) -> Option<DescriptorSecretKey> {
- Some(DescriptorSecretKey::PrivKey(self.clone()))
+ Some(DescriptorSecretKey::PrivKey(*self))
}
}
Included(&(id, SignerOrdering(usize::MAX)).into()),
))
.map(|(_, v)| v)
- .nth(0)
+ .next()
}
}
let tx_input = &psbt.global.unsigned_tx.input[input_index];
let sighash = psbt_input.sighash_type.ok_or(SignerError::MissingSighash)?;
- let script = match &psbt_input.redeem_script {
- &Some(ref redeem_script) => redeem_script.clone(),
- &None => {
+ let script = match psbt_input.redeem_script {
+ Some(ref redeem_script) => redeem_script.clone(),
+ None => {
let non_witness_utxo = psbt_input
.non_witness_utxo
.as_ref()
.ok_or(SignerError::MissingNonWitnessUtxo)?;
let value = witness_utxo.value;
- let script = match &psbt_input.witness_script {
- &Some(ref witness_script) => witness_script.clone(),
- &None => {
+ let script = match psbt_input.witness_script {
+ Some(ref witness_script) => witness_script.clone(),
+ None => {
if witness_utxo.script_pubkey.is_v0_p2wpkh() {
p2wpkh_script_code(&witness_utxo.script_pubkey)
} else if psbt_input
#[macro_use]
extern crate serde_json;
-#[macro_use]
-extern crate serial_test;
pub use serial_test::serial;