Skip to content

Commit 57795f0

Browse files
committed
clippy: all the lifetime-related stuff
Split off because I imagine these ones will be easier to review.
1 parent 2ab85ed commit 57795f0

File tree

15 files changed

+106
-110
lines changed

15 files changed

+106
-110
lines changed

examples/psbt_sign_finalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
let secp256k1 = secp256k1::Secp256k1::new();
2020

2121
let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn";
22-
let bridge_descriptor = Descriptor::from_str(&s).unwrap();
22+
let bridge_descriptor = Descriptor::from_str(s).unwrap();
2323
//let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
2424
assert!(bridge_descriptor.sanity_check().is_ok());
2525
println!(

examples/xpub_descriptors.rs

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

4343
let address = Descriptor::<DefiniteDescriptorKey>::from_str(&s)
4444
.unwrap()
45-
.derived_descriptor(&secp)
45+
.derived_descriptor(secp)
4646
.unwrap()
4747
.address(Network::Bitcoin)
4848
.unwrap();
@@ -63,7 +63,7 @@ fn p2sh_p2wsh<C: Verification>(secp: &Secp256k1<C>) -> Address {
6363

6464
let address = Descriptor::<DescriptorPublicKey>::from_str(&s)
6565
.unwrap()
66-
.derived_descriptor(&secp, 5)
66+
.derived_descriptor(secp, 5)
6767
.unwrap()
6868
.address(Network::Bitcoin)
6969
.unwrap();

src/descriptor/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl Descriptor<DescriptorPublicKey> {
579579
secp: &secp256k1::Secp256k1<C>,
580580
index: u32,
581581
) -> Result<Descriptor<bitcoin::PublicKey>, ConversionError> {
582-
self.at_derivation_index(index).derived_descriptor(&secp)
582+
self.at_derivation_index(index).derived_descriptor(secp)
583583
}
584584

585585
/// Parse a descriptor that may contain secret keys
@@ -591,7 +591,7 @@ impl Descriptor<DescriptorPublicKey> {
591591
s: &str,
592592
) -> Result<(Descriptor<DescriptorPublicKey>, KeyMap), Error> {
593593
fn parse_key<C: secp256k1::Signing>(
594-
s: &String,
594+
s: &str,
595595
key_map: &mut KeyMap,
596596
secp: &secp256k1::Secp256k1<C>,
597597
) -> Result<DescriptorPublicKey, Error> {
@@ -762,7 +762,7 @@ impl Descriptor<DefiniteDescriptorKey> {
762762
&mut self,
763763
pk: &DefiniteDescriptorKey,
764764
) -> Result<bitcoin::PublicKey, ConversionError> {
765-
pk.derive_public_key(&self.0)
765+
pk.derive_public_key(self.0)
766766
}
767767

768768
translate_hash_clone!(DefiniteDescriptorKey, bitcoin::PublicKey, ConversionError);
@@ -861,10 +861,10 @@ mod tests {
861861
impl cmp::PartialEq for DescriptorSecretKey {
862862
fn eq(&self, other: &Self) -> bool {
863863
match (self, other) {
864-
(&DescriptorSecretKey::Single(ref a), &DescriptorSecretKey::Single(ref b)) => {
864+
(DescriptorSecretKey::Single(a), DescriptorSecretKey::Single(b)) => {
865865
a.origin == b.origin && a.key == b.key
866866
}
867-
(&DescriptorSecretKey::XPrv(ref a), &DescriptorSecretKey::XPrv(ref b)) => {
867+
(DescriptorSecretKey::XPrv(a), DescriptorSecretKey::XPrv(b)) => {
868868
a.origin == b.origin
869869
&& a.xkey == b.xkey
870870
&& a.derivation_path == b.derivation_path
@@ -876,7 +876,7 @@ mod tests {
876876
}
877877

878878
fn roundtrip_descriptor(s: &str) {
879-
let desc = Descriptor::<DummyKey>::from_str(&s).unwrap();
879+
let desc = Descriptor::<DummyKey>::from_str(s).unwrap();
880880
let output = desc.to_string();
881881
let normalize_aliases = s.replace("c:pk_k(", "pk(").replace("c:pk_h(", "pkh(");
882882
assert_eq!(
@@ -939,9 +939,9 @@ mod tests {
939939

940940
#[test]
941941
pub fn script_pubkey() {
942-
let bare = StdDescriptor::from_str(&format!(
943-
"multi(1,020000000000000000000000000000000000000000000000000000000000000002)"
944-
))
942+
let bare = StdDescriptor::from_str(
943+
"multi(1,020000000000000000000000000000000000000000000000000000000000000002)",
944+
)
945945
.unwrap();
946946
assert_eq!(
947947
bare.script_pubkey(),
@@ -1663,8 +1663,8 @@ mod tests {
16631663
"sh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))##tjq09x4t"
16641664
);
16651665

1666-
Descriptor::parse_descriptor(&secp, "sh(multi(2,[00000000/111'/222]xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L/0))#ggrsrxfy").expect("Valid descriptor with checksum");
1667-
Descriptor::parse_descriptor(&secp, "sh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))#tjg09x5t").expect("Valid descriptor with checksum");
1666+
Descriptor::parse_descriptor(secp, "sh(multi(2,[00000000/111'/222]xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L/0))#ggrsrxfy").expect("Valid descriptor with checksum");
1667+
Descriptor::parse_descriptor(secp, "sh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))#tjg09x5t").expect("Valid descriptor with checksum");
16681668
}
16691669

16701670
#[test]
@@ -1694,7 +1694,7 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
16941694
let secp = &secp256k1::Secp256k1::signing_only();
16951695
let descriptor_str = "wpkh(xprv9s21ZrQH143K4CTb63EaMxja1YiTnSEWKMbn23uoEnAzxjdUJRQkazCAtzxGm4LSoTSVTptoV9RbchnKPW9HxKtZumdyxyikZFDLhogJ5Uj/44'/0'/0'/0/*)#v20xlvm9";
16961696
let (descriptor, keymap) =
1697-
Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, descriptor_str).unwrap();
1697+
Descriptor::<DescriptorPublicKey>::parse_descriptor(secp, descriptor_str).unwrap();
16981698

16991699
let expected = "wpkh([a12b02f4/44'/0'/0']xpub6BzhLAQUDcBUfHRQHZxDF2AbcJqp4Kaeq6bzJpXrjrWuK26ymTFwkEFbxPra2bJ7yeZKbDjfDeFwxe93JMqpo5SsPJH6dZdvV9kMzJkAZ69/0/*)#u37l7u8u";
17001700
assert_eq!(expected, descriptor.to_string());

src/descriptor/tr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
116116
}
117117

118118
/// Iterate over all miniscripts
119-
pub fn iter(&self) -> TapTreeIter<Pk> {
119+
pub fn iter(&self) -> TapTreeIter<'_, Pk> {
120120
TapTreeIter {
121121
stack: vec![(0, self)],
122122
}
@@ -185,7 +185,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
185185

186186
/// Iterate over all scripts in merkle tree. If there is no script path, the iterator
187187
/// yields [`None`]
188-
pub fn iter_scripts(&self) -> TapTreeIter<Pk> {
188+
pub fn iter_scripts(&self) -> TapTreeIter<'_, Pk> {
189189
match self.tree {
190190
Some(ref t) => t.iter(),
191191
None => TapTreeIter { stack: vec![] },
@@ -462,7 +462,7 @@ impl<Pk: MiniscriptKey> fmt::Display for Tr<Pk> {
462462
}
463463

464464
// Helper function to parse string into miniscript tree form
465-
fn parse_tr_tree(s: &str) -> Result<expression::Tree, Error> {
465+
fn parse_tr_tree(s: &str) -> Result<expression::Tree<'_>, Error> {
466466
for ch in s.bytes() {
467467
if !ch.is_ascii() {
468468
return Err(Error::Unprintable(ch));

src/interpreter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ mod tests {
11421142
stack,
11431143
public_key: None,
11441144
state: vec![NodeEvaluationState {
1145-
node: &ms,
1145+
node: ms,
11461146
n_evaluated: 0,
11471147
n_satisfied: 0,
11481148
}],

src/miniscript/astelem.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
129129
Terminal::RawPkH(ref p) => Terminal::RawPkH(*p),
130130
Terminal::After(n) => Terminal::After(n),
131131
Terminal::Older(n) => Terminal::Older(n),
132-
Terminal::Sha256(ref x) => Terminal::Sha256(t.sha256(&x)?),
133-
Terminal::Hash256(ref x) => Terminal::Hash256(t.hash256(&x)?),
134-
Terminal::Ripemd160(ref x) => Terminal::Ripemd160(t.ripemd160(&x)?),
135-
Terminal::Hash160(ref x) => Terminal::Hash160(t.hash160(&x)?),
132+
Terminal::Sha256(ref x) => Terminal::Sha256(t.sha256(x)?),
133+
Terminal::Hash256(ref x) => Terminal::Hash256(t.hash256(x)?),
134+
Terminal::Ripemd160(ref x) => Terminal::Ripemd160(t.ripemd160(x)?),
135+
Terminal::Hash160(ref x) => Terminal::Hash160(t.hash160(x)?),
136136
Terminal::True => Terminal::True,
137137
Terminal::False => Terminal::False,
138138
Terminal::Alt(ref sub) => Terminal::Alt(Arc::new(sub.real_translate_pk(t)?)),
@@ -622,7 +622,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
622622
Terminal::RawPkH(ref hash) => builder
623623
.push_opcode(opcodes::all::OP_DUP)
624624
.push_opcode(opcodes::all::OP_HASH160)
625-
.push_slice(&hash)
625+
.push_slice(hash)
626626
.push_opcode(opcodes::all::OP_EQUALVERIFY),
627627
Terminal::After(t) => builder
628628
.push_int(t.to_u32().into())
@@ -635,28 +635,28 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
635635
.push_int(32)
636636
.push_opcode(opcodes::all::OP_EQUALVERIFY)
637637
.push_opcode(opcodes::all::OP_SHA256)
638-
.push_slice(&Pk::to_sha256(&h))
638+
.push_slice(&Pk::to_sha256(h))
639639
.push_opcode(opcodes::all::OP_EQUAL),
640640
Terminal::Hash256(ref h) => builder
641641
.push_opcode(opcodes::all::OP_SIZE)
642642
.push_int(32)
643643
.push_opcode(opcodes::all::OP_EQUALVERIFY)
644644
.push_opcode(opcodes::all::OP_HASH256)
645-
.push_slice(&Pk::to_hash256(&h))
645+
.push_slice(&Pk::to_hash256(h))
646646
.push_opcode(opcodes::all::OP_EQUAL),
647647
Terminal::Ripemd160(ref h) => builder
648648
.push_opcode(opcodes::all::OP_SIZE)
649649
.push_int(32)
650650
.push_opcode(opcodes::all::OP_EQUALVERIFY)
651651
.push_opcode(opcodes::all::OP_RIPEMD160)
652-
.push_slice(&Pk::to_ripemd160(&h))
652+
.push_slice(&Pk::to_ripemd160(h))
653653
.push_opcode(opcodes::all::OP_EQUAL),
654654
Terminal::Hash160(ref h) => builder
655655
.push_opcode(opcodes::all::OP_SIZE)
656656
.push_int(32)
657657
.push_opcode(opcodes::all::OP_EQUALVERIFY)
658658
.push_opcode(opcodes::all::OP_HASH160)
659-
.push_slice(&Pk::to_hash160(&h))
659+
.push_slice(&Pk::to_hash160(h))
660660
.push_opcode(opcodes::all::OP_EQUAL),
661661
Terminal::True => builder.push_opcode(opcodes::OP_TRUE),
662662
Terminal::False => builder.push_opcode(opcodes::OP_FALSE),

src/miniscript/iter.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
2929
/// Creates a new [Iter] iterator that will iterate over all [Miniscript] items within
3030
/// AST by traversing its branches. For the specific algorithm please see
3131
/// [Iter::next] function.
32-
pub fn iter(&self) -> Iter<Pk, Ctx> {
32+
pub fn iter(&self) -> Iter<'_, Pk, Ctx> {
3333
Iter::new(self)
3434
}
3535

3636
/// Creates a new [PkIter] iterator that will iterate over all plain public keys (and not
3737
/// key hash values) present in [Miniscript] items within AST by traversing all its branches.
3838
/// For the specific algorithm please see [PkIter::next] function.
39-
pub fn iter_pk(&self) -> PkIter<Pk, Ctx> {
39+
pub fn iter_pk(&self) -> PkIter<'_, Pk, Ctx> {
4040
PkIter::new(self)
4141
}
4242

@@ -74,30 +74,30 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
7474
/// Returns child node with given index, if any
7575
pub fn get_nth_child(&self, n: usize) -> Option<&Miniscript<Pk, Ctx>> {
7676
match (n, &self.node) {
77-
(0, &Terminal::Alt(ref node))
78-
| (0, &Terminal::Swap(ref node))
79-
| (0, &Terminal::Check(ref node))
80-
| (0, &Terminal::DupIf(ref node))
81-
| (0, &Terminal::Verify(ref node))
82-
| (0, &Terminal::NonZero(ref node))
83-
| (0, &Terminal::ZeroNotEqual(ref node))
84-
| (0, &Terminal::AndV(ref node, _))
85-
| (0, &Terminal::AndB(ref node, _))
86-
| (0, &Terminal::OrB(ref node, _))
87-
| (0, &Terminal::OrD(ref node, _))
88-
| (0, &Terminal::OrC(ref node, _))
89-
| (0, &Terminal::OrI(ref node, _))
90-
| (1, &Terminal::AndV(_, ref node))
91-
| (1, &Terminal::AndB(_, ref node))
92-
| (1, &Terminal::OrB(_, ref node))
93-
| (1, &Terminal::OrD(_, ref node))
94-
| (1, &Terminal::OrC(_, ref node))
95-
| (1, &Terminal::OrI(_, ref node))
96-
| (0, &Terminal::AndOr(ref node, _, _))
97-
| (1, &Terminal::AndOr(_, ref node, _))
98-
| (2, &Terminal::AndOr(_, _, ref node)) => Some(node),
99-
100-
(n, &Terminal::Thresh(_, ref node_vec)) => node_vec.get(n).map(|x| &**x),
77+
(0, Terminal::Alt(node))
78+
| (0, Terminal::Swap(node))
79+
| (0, Terminal::Check(node))
80+
| (0, Terminal::DupIf(node))
81+
| (0, Terminal::Verify(node))
82+
| (0, Terminal::NonZero(node))
83+
| (0, Terminal::ZeroNotEqual(node))
84+
| (0, Terminal::AndV(node, _))
85+
| (0, Terminal::AndB(node, _))
86+
| (0, Terminal::OrB(node, _))
87+
| (0, Terminal::OrD(node, _))
88+
| (0, Terminal::OrC(node, _))
89+
| (0, Terminal::OrI(node, _))
90+
| (1, Terminal::AndV(_, node))
91+
| (1, Terminal::AndB(_, node))
92+
| (1, Terminal::OrB(_, node))
93+
| (1, Terminal::OrD(_, node))
94+
| (1, Terminal::OrC(_, node))
95+
| (1, Terminal::OrI(_, node))
96+
| (0, Terminal::AndOr(node, _, _))
97+
| (1, Terminal::AndOr(_, node, _))
98+
| (2, Terminal::AndOr(_, _, node)) => Some(node),
99+
100+
(n, Terminal::Thresh(_, node_vec)) => node_vec.get(n).map(|x| &**x),
101101

102102
_ => None,
103103
}

src/miniscript/lex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'s> TokenIter<'s> {
8989
}
9090

9191
/// Look at the top at Iterator
92-
pub fn peek(&self) -> Option<&'s Token> {
92+
pub fn peek(&self) -> Option<&'s Token<'_>> {
9393
self.0.last()
9494
}
9595

src/miniscript/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -994,28 +994,28 @@ mod tests {
994994
#[test]
995995
fn test_tapscript_rtt() {
996996
// Test x-only invalid under segwitc0 context
997-
let ms = Segwitv0Script::from_str_insane(&format!(
998-
"pk(2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)"
999-
));
997+
let ms = Segwitv0Script::from_str_insane(
998+
"pk(2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)",
999+
);
10001000
assert_eq!(
10011001
&ms.unwrap_err().to_string()[..35],
10021002
"unexpected «key hex decoding error",
10031003
);
1004-
Tapscript::from_str_insane(&format!(
1005-
"pk(2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)"
1006-
))
1004+
Tapscript::from_str_insane(
1005+
"pk(2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)",
1006+
)
10071007
.unwrap();
10081008

10091009
// Now test that bitcoin::PublicKey works with Taproot context
1010-
Miniscript::<bitcoin::PublicKey, Tap>::from_str_insane(&format!(
1011-
"pk(022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)"
1012-
))
1010+
Miniscript::<bitcoin::PublicKey, Tap>::from_str_insane(
1011+
"pk(022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)",
1012+
)
10131013
.unwrap();
10141014

10151015
// uncompressed keys should not be allowed
1016-
Miniscript::<bitcoin::PublicKey, Tap>::from_str_insane(&format!(
1016+
Miniscript::<bitcoin::PublicKey, Tap>::from_str_insane(
10171017
"pk(04eed24a081bf1b1e49e3300df4bebe04208ac7e516b6f3ea8eb6e094584267c13483f89dcf194132e12238cc5a34b6b286fc7990d68ed1db86b69ebd826c63b29)"
1018-
))
1018+
)
10191019
.unwrap_err();
10201020

10211021
//---------------- test script <-> miniscript ---------------
@@ -1041,14 +1041,14 @@ mod tests {
10411041
.unwrap();
10421042

10431043
// multi not allowed in tapscript
1044-
Tapscript::from_str_insane(&format!(
1045-
"multi(1,2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)"
1046-
))
1044+
Tapscript::from_str_insane(
1045+
"multi(1,2788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)",
1046+
)
10471047
.unwrap_err();
10481048
// but allowed in segwit
1049-
Segwitv0Script::from_str_insane(&format!(
1050-
"multi(1,022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)"
1051-
))
1049+
Segwitv0Script::from_str_insane(
1050+
"multi(1,022788ee41e76f4f3af603da5bc8fa22997bc0344bb0f95666ba6aaff0242baa99)",
1051+
)
10521052
.unwrap();
10531053
}
10541054

0 commit comments

Comments
 (0)