Skip to content

Commit ea54520

Browse files
committed
clippy: non-reference stuff
As in other PRs, the meaningful changes here are: 'A'..'Z' becoming 'A'..='Z', and the partial_cmp replacements.
1 parent 594fda4 commit ea54520

24 files changed

+136
-217
lines changed

clippy.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
msrv = "1.41.1"
2+
# PSBT API returns Self as an error type for an large-ish enum
3+
large-error-threshold = 512
4+
# A couple tests have huge tuples instead of structs. This is fixed
5+
# in a later major rev. For now we just turn down the lint.
6+
type-complexity-threshold = 1000
7+
# Some internal compiler functions take a gazillion arguments. Again,
8+
# this is fixed in a later major rev so just turn down the lint here.
9+
too-many-arguments-threshold = 9

examples/psbt_sign_finalize.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::collections::BTreeMap;
22
use std::str::FromStr;
33

44
use bitcoin::consensus::serialize;
5+
use bitcoin::hashes::hex::ToHex as _;
56
use bitcoin::util::sighash::SighashCache;
67
use bitcoin::{PackedLockTime, PrivateKey};
7-
use bitcoin::hashes::hex::ToHex as _;
88
use miniscript::bitcoin::consensus::encode::deserialize;
99
use miniscript::bitcoin::hashes::hex::FromHex;
1010
use miniscript::bitcoin::util::psbt;
@@ -97,10 +97,12 @@ fn main() {
9797

9898
let (outpoint, witness_utxo) = get_vout(&depo_tx, bridge_descriptor.script_pubkey());
9999

100-
let mut txin = TxIn::default();
101-
txin.previous_output = outpoint;
100+
let txin = TxIn {
101+
previous_output: outpoint,
102102

103-
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
103+
sequence: Sequence::from_height(26),
104+
..TxIn::default()
105+
};
104106
psbt.unsigned_tx.input.push(txin);
105107

106108
psbt.unsigned_tx.output.push(TxOut {
@@ -147,13 +149,9 @@ fn main() {
147149
let pk2 = backup2_private.public_key(&secp256k1);
148150
assert!(secp256k1.verify_ecdsa(&msg, &sig2, &pk2.inner).is_ok());
149151

150-
psbt.inputs[0].partial_sigs.insert(
151-
pk1,
152-
bitcoin::EcdsaSig {
153-
sig: sig1,
154-
hash_ty: hash_ty,
155-
},
156-
);
152+
psbt.inputs[0]
153+
.partial_sigs
154+
.insert(pk1, bitcoin::EcdsaSig { sig: sig1, hash_ty });
157155

158156
println!("{:#?}", psbt);
159157

examples/taproot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ fn hardcoded_xonlypubkeys() -> Vec<bitcoin::XOnlyPublicKey> {
136136
],
137137
];
138138
let mut keys: Vec<bitcoin::XOnlyPublicKey> = vec![];
139-
for idx in 0..4 {
140-
keys.push(bitcoin::XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap());
139+
for key in &serialized_keys {
140+
keys.push(bitcoin::XOnlyPublicKey::from_slice(key).unwrap());
141141
}
142142
keys
143143
}

examples/verify_tx.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,12 @@ fn main() {
5959

6060
for elem in interpreter.iter_assume_sigs() {
6161
// Don't bother checking signatures.
62-
match elem.expect("no evaluation error") {
63-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
64-
let (key, sig) = key_sig
65-
.as_ecdsa()
66-
.expect("expected ecdsa sig, found schnorr sig");
67-
68-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
69-
}
70-
_ => {}
62+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
63+
let (key, sig) = key_sig
64+
.as_ecdsa()
65+
.expect("expected ecdsa sig, found schnorr sig");
66+
67+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
7168
}
7269
}
7370

@@ -84,12 +81,9 @@ fn main() {
8481
let prevouts = sighash::Prevouts::All::<bitcoin::TxOut>(&[]);
8582

8683
for elem in interpreter.iter(&secp, &tx, 0, &prevouts) {
87-
match elem.expect("no evaluation error") {
88-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
89-
let (key, sig) = key_sig.as_ecdsa().unwrap();
90-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
91-
}
92-
_ => {}
84+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
85+
let (key, sig) = key_sig.as_ecdsa().unwrap();
86+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
9387
}
9488
}
9589

src/descriptor/key.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
665665
let (compare_fingerprint, compare_path) = match self.origin {
666666
Some((fingerprint, ref path)) => (
667667
fingerprint,
668-
path.into_iter()
669-
.chain(self.derivation_path.into_iter())
670-
.collect(),
668+
path.into_iter().chain(&self.derivation_path).collect(),
671669
),
672670
None => (
673671
self.xkey.xkey_fingerprint(secp),
@@ -784,11 +782,9 @@ impl FromStr for DefiniteDescriptorKey {
784782

785783
fn from_str(s: &str) -> Result<Self, Self::Err> {
786784
let inner = DescriptorPublicKey::from_str(s)?;
787-
Ok(
788-
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
789-
"cannot parse key with a wilcard as a DerivedDescriptorKey",
790-
))?,
791-
)
785+
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
786+
"cannot parse key with a wilcard as a DerivedDescriptorKey",
787+
))
792788
}
793789
}
794790

@@ -948,17 +944,17 @@ mod test {
948944
let public_key = DescriptorPublicKey::from_str("[abcdef00/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2").unwrap();
949945
assert_eq!(public_key.master_fingerprint().to_string(), "abcdef00");
950946
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'/2");
951-
assert_eq!(public_key.has_wildcard(), false);
947+
assert!(!public_key.has_wildcard());
952948

953949
let public_key = DescriptorPublicKey::from_str("[abcdef00/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/*").unwrap();
954950
assert_eq!(public_key.master_fingerprint().to_string(), "abcdef00");
955951
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'");
956-
assert_eq!(public_key.has_wildcard(), true);
952+
assert!(public_key.has_wildcard());
957953

958954
let public_key = DescriptorPublicKey::from_str("[abcdef00/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/*h").unwrap();
959955
assert_eq!(public_key.master_fingerprint().to_string(), "abcdef00");
960956
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'");
961-
assert_eq!(public_key.has_wildcard(), true);
957+
assert!(public_key.has_wildcard());
962958
}
963959

964960
#[test]
@@ -970,7 +966,7 @@ mod test {
970966
assert_eq!(public_key.to_string(), "[2cbe2a6d/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2");
971967
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
972968
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'/2");
973-
assert_eq!(public_key.has_wildcard(), false);
969+
assert!(!public_key.has_wildcard());
974970

975971
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0'/1'/2'").unwrap();
976972
let public_key = secret_key.to_public(&secp).unwrap();

src/descriptor/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,7 @@ mod tests {
856856
use crate::{hex_script, Descriptor, DummyKey, Error, Miniscript, Satisfier};
857857

858858
type StdDescriptor = Descriptor<PublicKey>;
859-
const TEST_PK: &'static str =
860-
"pk(020000000000000000000000000000000000000000000000000000000000000002)";
859+
const TEST_PK: &str = "pk(020000000000000000000000000000000000000000000000000000000000000002)";
861860

862861
impl cmp::PartialEq for DescriptorSecretKey {
863862
fn eq(&self, other: &Self) -> bool {

src/descriptor/sortedmulti.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
112112
}
113113

114114
impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for SortedMultiVec<Pk, Ctx> {
115-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
115+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
116116
where
117117
Pk: 'a,
118118
{
119-
self.pks.iter().all(|key| pred(key))
119+
self.pks.iter().all(pred)
120120
}
121121
}
122122

@@ -258,11 +258,11 @@ mod tests {
258258

259259
let mut pks = Vec::new();
260260
for _ in 0..over {
261-
pks.push(pk.clone());
261+
pks.push(pk);
262262
}
263263

264264
let res: Result<SortedMultiVec<PublicKey, Legacy>, Error> = SortedMultiVec::new(0, pks);
265-
let error = res.err().expect("constructor should err");
265+
let error = res.expect_err("constructor should err");
266266

267267
match error {
268268
Error::BadDescriptor(_) => {} // ok

src/descriptor/tr.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ impl<Pk: MiniscriptKey> Eq for Tr<Pk> {}
8181

8282
impl<Pk: MiniscriptKey> PartialOrd for Tr<Pk> {
8383
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
84-
match self.internal_key.partial_cmp(&other.internal_key) {
85-
Some(cmp::Ordering::Equal) => {}
86-
ord => return ord,
87-
}
88-
self.tree.partial_cmp(&other.tree)
84+
Some(self.cmp(other))
8985
}
9086
}
9187

@@ -352,9 +348,8 @@ where
352348
type Item = (u8, &'a Miniscript<Pk, Tap>);
353349

354350
fn next(&mut self) -> Option<Self::Item> {
355-
while !self.stack.is_empty() {
356-
let (depth, last) = self.stack.pop().expect("Size checked above");
357-
match &*last {
351+
while let Some((depth, last)) = self.stack.pop() {
352+
match last {
358353
TapTree::Tree(l, r) => {
359354
self.stack.push((depth + 1, r));
360355
self.stack.push((depth + 1, l));

src/interpreter/inner.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,22 +344,20 @@ pub(super) fn from_txdata<'txin>(
344344
None => Err(Error::UnexpectedStackEnd),
345345
}
346346
// ** bare script **
347+
} else if wit_stack.is_empty() {
348+
// Bare script parsed in BareCtx
349+
let miniscript = Miniscript::<bitcoin::PublicKey, BareCtx>::parse_with_ext(
350+
spk,
351+
&ExtParams::allow_all(),
352+
)?;
353+
let miniscript = miniscript.to_no_checks_ms();
354+
Ok((
355+
Inner::Script(miniscript, ScriptType::Bare),
356+
ssig_stack,
357+
Some(spk.clone()),
358+
))
347359
} else {
348-
if wit_stack.is_empty() {
349-
// Bare script parsed in BareCtx
350-
let miniscript = Miniscript::<bitcoin::PublicKey, BareCtx>::parse_with_ext(
351-
spk,
352-
&ExtParams::allow_all(),
353-
)?;
354-
let miniscript = miniscript.to_no_checks_ms();
355-
Ok((
356-
Inner::Script(miniscript, ScriptType::Bare),
357-
ssig_stack,
358-
Some(spk.clone()),
359-
))
360-
} else {
361-
Err(Error::NonEmptyWitness)
362-
}
360+
Err(Error::NonEmptyWitness)
363361
}
364362
}
365363

0 commit comments

Comments
 (0)