Skip to content

Commit

Permalink
ref(tmp_plan): fix some clippy nits, but still allow all
Browse files Browse the repository at this point in the history
Common cases were redundant borrows of a reference, and redundant
`clone`s of types that impl Copy
  • Loading branch information
ValuedMammal committed Dec 29, 2023
1 parent d2a4129 commit 6107725
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
22 changes: 11 additions & 11 deletions nursery/tmp_plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! doing coin selection. Furthermore it provides which subset of those keys and hash pre-images you
//! will actually need as well as what locktime or sequence number you need to set.
//!
//! Once you've obstained signatures, hash pre-images etc required by the plan, it can create a
//! Once you've obtained signatures, hash pre-images etc required by the plan, it can create a
//! witness/script_sig for the input.
use bdk_chain::{bitcoin, collections::*, miniscript};
use bitcoin::{
Expand All @@ -32,7 +32,7 @@ use miniscript::{
};

pub(crate) fn varint_len(v: usize) -> usize {
bitcoin::VarInt(v as u64).len() as usize
bitcoin::VarInt(v as u64).len()
}

mod plan_impls;
Expand Down Expand Up @@ -191,7 +191,7 @@ where
let mut witness = self
.template
.iter()
.flat_map(|step| step.to_witness_stack(&auth_data))
.flat_map(|step| step.to_witness_stack(auth_data))
.collect::<Vec<_>>();
match &self.target {
Target::Segwitv0 { .. } => todo!(),
Expand Down Expand Up @@ -250,7 +250,7 @@ where
script,
leaf_version,
} => {
let leaf_hash = TapLeafHash::from_script(&script, *leaf_version);
let leaf_hash = TapLeafHash::from_script(script, *leaf_version);
requirements.signatures = RequiredSignatures::TapScript {
leaf_hash,
plan_keys: vec![],
Expand All @@ -276,16 +276,16 @@ where
required_signatures.push(plan_key.clone());
}
TemplateItem::Hash160(image) => {
requirements.hash160_images.insert(image.clone());
requirements.hash160_images.insert(*image);
}
TemplateItem::Hash256(image) => {
requirements.hash256_images.insert(image.clone());
requirements.hash256_images.insert(*image);
}
TemplateItem::Sha256(image) => {
requirements.sha256_images.insert(image.clone());
requirements.sha256_images.insert(*image);
}
TemplateItem::Ripemd160(image) => {
requirements.ripemd160_images.insert(image.clone());
requirements.ripemd160_images.insert(*image);
}
TemplateItem::Pk { .. } | TemplateItem::One | TemplateItem::Zero => { /* no requirements */
}
Expand All @@ -307,17 +307,17 @@ where

/// The minimum required locktime height or time on the transaction using the plan.
pub fn required_locktime(&self) -> Option<absolute::LockTime> {
self.set_locktime.clone()
self.set_locktime
}

/// The minimum required sequence (height or time) on the input to satisfy the plan
pub fn required_sequence(&self) -> Option<Sequence> {
self.set_sequence.clone()
self.set_sequence
}

/// The minimum required transaction version required on the transaction using the plan.
pub fn min_version(&self) -> Option<u32> {
if let Some(_) = self.set_sequence {
if self.set_sequence.is_some() {
Some(2)
} else {
Some(1)
Expand Down
20 changes: 10 additions & 10 deletions nursery/tmp_plan/src/plan_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ where
leaf_version: LeafVersion::TapScript,
},
},
set_locktime: best_plan.min_locktime.clone(),
set_sequence: best_plan.min_sequence.clone(),
set_locktime: best_plan.min_locktime,
set_sequence: best_plan.min_sequence,
template: best_plan.template,
})
}
Expand Down Expand Up @@ -184,7 +184,7 @@ fn plan_steps<Ak: Clone + CanDerive, Ctx: ScriptContext>(
) -> Option<TermPlan<Ak>> {
match term {
Terminal::True => Some(TermPlan::new(vec![])),
Terminal::False => return None,
Terminal::False => None,
Terminal::PkH(key) => {
let (asset_key, derivation_hint) = assets
.keys
Expand Down Expand Up @@ -251,29 +251,29 @@ fn plan_steps<Ak: Clone + CanDerive, Ctx: ScriptContext>(
}
}
Terminal::Sha256(image) => {
if assets.sha256.contains(&image) {
Some(TermPlan::new(vec![TemplateItem::Sha256(image.clone())]))
if assets.sha256.contains(image) {
Some(TermPlan::new(vec![TemplateItem::Sha256(*image)]))
} else {
None
}
}
Terminal::Hash256(image) => {
if assets.hash256.contains(image) {
Some(TermPlan::new(vec![TemplateItem::Hash256(image.clone())]))
Some(TermPlan::new(vec![TemplateItem::Hash256(*image)]))
} else {
None
}
}
Terminal::Ripemd160(image) => {
if assets.ripemd160.contains(&image) {
Some(TermPlan::new(vec![TemplateItem::Ripemd160(image.clone())]))
if assets.ripemd160.contains(image) {
Some(TermPlan::new(vec![TemplateItem::Ripemd160(*image)]))
} else {
None
}
}
Terminal::Hash160(image) => {
if assets.hash160.contains(&image) {
Some(TermPlan::new(vec![TemplateItem::Hash160(image.clone())]))
if assets.hash160.contains(image) {
Some(TermPlan::new(vec![TemplateItem::Hash160(*image)]))
} else {
None
}
Expand Down
15 changes: 7 additions & 8 deletions nursery/tmp_plan/src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
DescriptorSecretKey::Single(single) => single.key.inner,
DescriptorSecretKey::XPrv(xprv) => {
xprv.xkey
.derive_priv(&secp, &plan_key.derivation_hint)?
.derive_priv(secp, &plan_key.derivation_hint)?
.private_key
}
DescriptorSecretKey::MultiXPrv(_) => {
Expand All @@ -158,13 +158,12 @@ impl RequiredSignatures<DescriptorPublicKey> {
}
};

let pubkey = PublicKey::from_secret_key(&secp, &secret_key);
let pubkey = PublicKey::from_secret_key(secp, &secret_key);
let x_only_pubkey = XOnlyPublicKey::from(pubkey);

let tweak =
taproot::TapTweakHash::from_key_and_tweak(x_only_pubkey, merkle_root.clone());
let keypair = KeyPair::from_secret_key(&secp, &secret_key.clone())
.add_xonly_tweak(&secp, &tweak.to_scalar())
let tweak = taproot::TapTweakHash::from_key_and_tweak(x_only_pubkey, *merkle_root);
let keypair = KeyPair::from_secret_key(secp, &secret_key.clone())
.add_xonly_tweak(secp, &tweak.to_scalar())
.unwrap();

let msg = Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
Expand Down Expand Up @@ -200,7 +199,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
DescriptorSecretKey::Single(single) => single.key.inner,
DescriptorSecretKey::XPrv(xprv) => {
xprv.xkey
.derive_priv(&secp, &plan_key.derivation_hint)?
.derive_priv(secp, &plan_key.derivation_hint)?
.private_key
}
DescriptorSecretKey::MultiXPrv(_) => {
Expand All @@ -209,7 +208,7 @@ impl RequiredSignatures<DescriptorPublicKey> {
todo!();
}
};
let keypair = KeyPair::from_secret_key(&secp, &secret_key.clone());
let keypair = KeyPair::from_secret_key(secp, &secret_key.clone());
let msg =
Message::from_slice(sighash.as_ref()).expect("Sighashes are 32 bytes");
let sig = secp.sign_schnorr_no_aux_rand(&msg, &keypair);
Expand Down

0 comments on commit 6107725

Please sign in to comment.