Skip to content

Commit 3942b07

Browse files
committed
clippy: fix most lints
This, and the next commit, are not organized in any way except that I did a new commit partway to try to make review a bit easier. There were too many lints for me to split them all up and do them in a nice PR. This changes `OrdF64::partial_cmp` to be consistent with `OrdF64::cmp` which is a bugfix and an observable behavior change (but not an easy one to observe). All other changes are just syntax stuff.
1 parent a602435 commit 3942b07

File tree

16 files changed

+71
-102
lines changed

16 files changed

+71
-102
lines changed

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
msrv = "1.48.0"
22
# plan API returns Self as an error type for an large-ish enum
3-
large-error-threshold = 256
3+
large-error-threshold = 512

examples/psbt_sign_finalize.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
let secp256k1 = secp256k1::Secp256k1::new();
1919

2020
let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn";
21-
let bridge_descriptor = Descriptor::from_str(&s).unwrap();
21+
let bridge_descriptor = Descriptor::from_str(s).unwrap();
2222
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
2323
assert!(bridge_descriptor.sanity_check().is_ok());
2424
println!("Bridge pubkey script: {}", bridge_descriptor.script_pubkey());
@@ -80,10 +80,11 @@ fn main() {
8080

8181
let (outpoint, witness_utxo) = get_vout(&depo_tx, &bridge_descriptor.script_pubkey());
8282

83-
let mut txin = TxIn::default();
84-
txin.previous_output = outpoint;
85-
86-
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
83+
let txin = TxIn {
84+
previous_output: outpoint,
85+
sequence: Sequence::from_height(26),
86+
..TxIn::default()
87+
};
8788
psbt.unsigned_tx.input.push(txin);
8889

8990
psbt.unsigned_tx.output.push(TxOut {
@@ -132,7 +133,7 @@ fn main() {
132133

133134
psbt.inputs[0]
134135
.partial_sigs
135-
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });
136+
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty });
136137

137138
println!("{:#?}", psbt);
138139
println!("{}", psbt);

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<XOnlyPublicKey> {
136136
],
137137
];
138138
let mut keys: Vec<XOnlyPublicKey> = vec![];
139-
for idx in 0..4 {
140-
keys.push(XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap());
139+
for key in &serialized_keys {
140+
keys.push(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
@@ -46,15 +46,12 @@ fn main() {
4646

4747
for elem in interpreter.iter_assume_sigs() {
4848
// Don't bother checking signatures.
49-
match elem.expect("no evaluation error") {
50-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
51-
let (key, sig) = key_sig
52-
.as_ecdsa()
53-
.expect("expected ecdsa sig, found schnorr sig");
54-
55-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
56-
}
57-
_ => {}
49+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
50+
let (key, sig) = key_sig
51+
.as_ecdsa()
52+
.expect("expected ecdsa sig, found schnorr sig");
53+
54+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
5855
}
5956
}
6057

@@ -71,12 +68,9 @@ fn main() {
7168
let prevouts = sighash::Prevouts::All::<bitcoin::TxOut>(&[]);
7269

7370
for elem in interpreter.iter(&secp, &tx, 0, &prevouts) {
74-
match elem.expect("no evaluation error") {
75-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
76-
let (key, sig) = key_sig.as_ecdsa().unwrap();
77-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
78-
}
79-
_ => {}
71+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
72+
let (key, sig) = key_sig.as_ecdsa().unwrap();
73+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
8074
}
8175
}
8276

examples/xpub_descriptors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
3030

3131
let address = Descriptor::<DefiniteDescriptorKey>::from_str(&s)
3232
.unwrap()
33-
.derived_descriptor(&secp)
33+
.derived_descriptor(secp)
3434
.unwrap()
3535
.address(Network::Bitcoin)
3636
.unwrap();
@@ -53,7 +53,7 @@ fn p2sh_p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
5353

5454
let address = Descriptor::<DescriptorPublicKey>::from_str(&s)
5555
.unwrap()
56-
.derived_descriptor(&secp, 5)
56+
.derived_descriptor(secp, 5)
5757
.unwrap()
5858
.address(Network::Bitcoin)
5959
.unwrap();

src/descriptor/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl Descriptor<DescriptorPublicKey> {
804804
///
805805
/// For multipath descriptors it will return as many descriptors as there is
806806
/// "parallel" paths. For regular descriptors it will just return itself.
807-
#[allow(clippy::blocks_in_if_conditions)]
807+
#[allow(clippy::blocks_in_conditions)]
808808
pub fn into_single_descriptors(self) -> Result<Vec<Descriptor<DescriptorPublicKey>>, Error> {
809809
// All single-path descriptors contained in this descriptor.
810810
let mut descriptors = Vec::new();
@@ -1323,7 +1323,7 @@ mod tests {
13231323
previous_output: bitcoin::OutPoint::default(),
13241324
script_sig: bitcoin::ScriptBuf::new(),
13251325
sequence: Sequence::from_height(100),
1326-
witness: Witness::from_slice(&vec![sigser.clone(), pk.to_bytes(),]),
1326+
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes(),]),
13271327
}
13281328
);
13291329
assert_eq!(wpkh.unsigned_script_sig(), bitcoin::ScriptBuf::new());
@@ -1346,7 +1346,7 @@ mod tests {
13461346
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
13471347
.into_script(),
13481348
sequence: Sequence::from_height(100),
1349-
witness: Witness::from_slice(&vec![sigser.clone(), pk.to_bytes(),]),
1349+
witness: Witness::from_slice(&[sigser.clone(), pk.to_bytes(),]),
13501350
}
13511351
);
13521352
assert_eq!(
@@ -1383,7 +1383,7 @@ mod tests {
13831383
previous_output: bitcoin::OutPoint::default(),
13841384
script_sig: bitcoin::ScriptBuf::new(),
13851385
sequence: Sequence::from_height(100),
1386-
witness: Witness::from_slice(&vec![sigser.clone(), ms.encode().into_bytes(),]),
1386+
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes(),]),
13871387
}
13881388
);
13891389
assert_eq!(wsh.unsigned_script_sig(), bitcoin::ScriptBuf::new());
@@ -1398,7 +1398,7 @@ mod tests {
13981398
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
13991399
.into_script(),
14001400
sequence: Sequence::from_height(100),
1401-
witness: Witness::from_slice(&vec![sigser.clone(), ms.encode().into_bytes(),]),
1401+
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes(),]),
14021402
}
14031403
);
14041404
assert_eq!(

src/interpreter/inner.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,21 +441,21 @@ mod tests {
441441
KeyTestData {
442442
pk_spk: bitcoin::ScriptBuf::new_p2pk(&key),
443443
pkh_spk: bitcoin::ScriptBuf::new_p2pkh(&pkhash),
444-
pk_sig: script::Builder::new().push_slice(&dummy_sig).into_script(),
444+
pk_sig: script::Builder::new().push_slice(dummy_sig).into_script(),
445445
pkh_sig: script::Builder::new()
446-
.push_slice(&dummy_sig)
446+
.push_slice(dummy_sig)
447447
.push_key(&key)
448448
.into_script(),
449449
pkh_sig_justkey: script::Builder::new().push_key(&key).into_script(),
450450
wpkh_spk: wpkh_spk.clone(),
451-
wpkh_stack: Witness::from_slice(&vec![dummy_sig_vec.clone(), key.to_bytes()]),
452-
wpkh_stack_justkey: Witness::from_slice(&vec![key.to_bytes()]),
451+
wpkh_stack: Witness::from_slice(&[dummy_sig_vec.clone(), key.to_bytes()]),
452+
wpkh_stack_justkey: Witness::from_slice(&[key.to_bytes()]),
453453
sh_wpkh_spk: bitcoin::ScriptBuf::new_p2sh(&wpkh_scripthash),
454454
sh_wpkh_sig: script::Builder::new()
455455
.push_slice(<&PushBytes>::try_from(wpkh_spk[..].as_bytes()).unwrap())
456456
.into_script(),
457-
sh_wpkh_stack: Witness::from_slice(&vec![dummy_sig_vec, key.to_bytes()]),
458-
sh_wpkh_stack_justkey: Witness::from_slice(&vec![key.to_bytes()]),
457+
sh_wpkh_stack: Witness::from_slice(&[dummy_sig_vec, key.to_bytes()]),
458+
sh_wpkh_stack_justkey: Witness::from_slice(&[key.to_bytes()]),
459459
}
460460
}
461461
}
@@ -534,7 +534,7 @@ mod tests {
534534
assert_eq!(&err.to_string()[0..12], "parse error:");
535535

536536
// Witness is nonempty
537-
let wit = Witness::from_slice(&vec![vec![]]);
537+
let wit = Witness::from_slice(&[vec![]]);
538538
let err = from_txdata(&comp.pk_spk, &comp.pk_sig, &wit).unwrap_err();
539539
assert_eq!(err.to_string(), "legacy spend had nonempty witness");
540540
}
@@ -583,7 +583,7 @@ mod tests {
583583
assert_eq!(script_code, Some(uncomp.pkh_spk.clone()));
584584

585585
// Witness is nonempty
586-
let wit = Witness::from_slice(&vec![vec![]]);
586+
let wit = Witness::from_slice(&[vec![]]);
587587
let err = from_txdata(&comp.pkh_spk, &comp.pkh_sig, &wit).unwrap_err();
588588
assert_eq!(err.to_string(), "legacy spend had nonempty witness");
589589
}
@@ -706,7 +706,7 @@ mod tests {
706706
assert_eq!(&err.to_string()[0..12], "parse error:");
707707

708708
// nonempty witness
709-
let wit = Witness::from_slice(&vec![vec![]]);
709+
let wit = Witness::from_slice(&[vec![]]);
710710
let err = from_txdata(&spk, &blank_script, &wit).unwrap_err();
711711
assert_eq!(&err.to_string(), "legacy spend had nonempty witness");
712712
}
@@ -742,7 +742,7 @@ mod tests {
742742
assert_eq!(script_code, Some(redeem_script));
743743

744744
// nonempty witness
745-
let wit = Witness::from_slice(&vec![vec![]]);
745+
let wit = Witness::from_slice(&[vec![]]);
746746
let err = from_txdata(&spk, &script_sig, &wit).unwrap_err();
747747
assert_eq!(&err.to_string(), "legacy spend had nonempty witness");
748748
}
@@ -753,7 +753,7 @@ mod tests {
753753
let hash = hash160::Hash::hash(&preimage[..]);
754754
let (miniscript, witness_script) = ms_inner_script(&format!("hash160({})", hash));
755755
let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
756-
let wit_stack = Witness::from_slice(&vec![witness_script.to_bytes()]);
756+
let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);
757757

758758
let spk = ScriptBuf::new_p2wsh(&wit_hash);
759759
let blank_script = bitcoin::ScriptBuf::new();
@@ -763,7 +763,7 @@ mod tests {
763763
assert_eq!(&err.to_string(), "unexpected end of stack");
764764

765765
// with incorrect witness
766-
let wit = Witness::from_slice(&vec![spk.to_bytes()]);
766+
let wit = Witness::from_slice(&[spk.to_bytes()]);
767767
let err = from_txdata(&spk, &blank_script, &wit).unwrap_err();
768768
assert_eq!(&err.to_string()[0..12], "parse error:");
769769

@@ -788,7 +788,7 @@ mod tests {
788788
let hash = hash160::Hash::hash(&preimage[..]);
789789
let (miniscript, witness_script) = ms_inner_script(&format!("hash160({})", hash));
790790
let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
791-
let wit_stack = Witness::from_slice(&vec![witness_script.to_bytes()]);
791+
let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);
792792

793793
let redeem_script = ScriptBuf::new_p2wsh(&wit_hash);
794794
let script_sig = script::Builder::new()
@@ -808,7 +808,7 @@ mod tests {
808808
assert_eq!(&err.to_string(), "unexpected end of stack");
809809

810810
// with incorrect witness
811-
let wit = Witness::from_slice(&vec![spk.to_bytes()]);
811+
let wit = Witness::from_slice(&[spk.to_bytes()]);
812812
let err = from_txdata(&spk, &script_sig, &wit).unwrap_err();
813813
assert_eq!(&err.to_string()[0..12], "parse error:");
814814

src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ impl<E> TranslateErr<E> {
333333
/// - Legacy/Bare does not allow x_only keys
334334
/// - SegwitV0 does not allow uncompressed keys and x_only keys
335335
/// - Tapscript does not allow uncompressed keys
336-
/// - Translating into multi-path descriptors should have same number of path
337-
/// for all the keys in the descriptor
336+
/// - Translating into multi-path descriptors should have same number of paths
337+
/// for all the keys in the descriptor
338338
///
339339
/// # Panics
340340
///
@@ -391,16 +391,6 @@ where
391391
T: Translator<P, Q, E>;
392392
}
393393

394-
/// Either a key or keyhash, but both contain Pk
395-
// pub struct ForEach<'a, Pk: MiniscriptKey>(&'a Pk);
396-
397-
// impl<'a, Pk: MiniscriptKey<Hash = Pk>> ForEach<'a, Pk> {
398-
// /// Convenience method to avoid distinguishing between keys and hashes when these are the same type
399-
// pub fn as_key(&self) -> &'a Pk {
400-
// self.0
401-
// }
402-
// }
403-
404394
/// Trait describing the ability to iterate over every key
405395
pub trait ForEachKey<Pk: MiniscriptKey> {
406396
/// Run a predicate on every key in the descriptor, returning whether

src/miniscript/analyzable.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};
1717
///
1818
/// This allows parsing miniscripts if
1919
/// 1. It is unsafe(does not require a digital signature to spend it)
20-
/// 2. It contains a unspendable path because of either
21-
/// a. Resource limitations
22-
/// b. Timelock Mixing
20+
/// 2. It contains a unspendable path because of either resource limitation or timelock mixing.
2321
/// 3. The script is malleable and thereby some of satisfaction weight
2422
/// guarantees are not satisfied.
2523
/// 4. It has repeated public keys
@@ -123,9 +121,7 @@ impl ExtParams {
123121
/// Possible reasons Miniscript guarantees can fail
124122
/// We currently mark Miniscript as Non-Analyzable if
125123
/// 1. It is unsafe(does not require a digital signature to spend it)
126-
/// 2. It contains a unspendable path because of either
127-
/// a. Resource limitations
128-
/// b. Timelock Mixing
124+
/// 2. It contains a unspendable path because of either resource limitations or timelock mixing.
129125
/// 3. The script is malleable and thereby some of satisfaction weight
130126
/// guarantees are not satisfied.
131127
/// 4. It has repeated publickeys

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<Ctx: ScriptContext> Miniscript<Ctx::Key, Ctx> {
363363
/// The type information and extra properties are implied by the AST.
364364
impl<Pk: MiniscriptKey, Ctx: ScriptContext> PartialOrd for Miniscript<Pk, Ctx> {
365365
fn partial_cmp(&self, other: &Miniscript<Pk, Ctx>) -> Option<cmp::Ordering> {
366-
Some(self.node.cmp(&other.node))
366+
Some(self.cmp(other))
367367
}
368368
}
369369

0 commit comments

Comments
 (0)