Skip to content

Commit b8447f1

Browse files
committed
Merge rust-bitcoin/rust-miniscript#670: Fix all lint errors and warnings
76346427f9f1ea8624ca6e1e1bb228a718c26e88 Use struct update syntax (Tobin C. Harding) 2bc083e607da8609d82123cd3505071898e4a14a Use iterator instead of manual loop (Tobin C. Harding) 6d663e15cee0586579fd5ef00812b3875b6ae382 Allow range loop in test code (Tobin C. Harding) a8c156e8787798f8d2b728d9adc54332a865c015 Use map instead of and_then (Tobin C. Harding) d5662dae0152f27bb81e464dbc9a91cd409e8109 Remove redundant closure (Tobin C. Harding) 90f1585a2f163f6328952fd56b272a6e05457e08 Remove redundant clone (Tobin C. Harding) 409d4b08af6213ab75fb78f78e68be2b024e5da3 Remove explicit reference (Tobin C. Harding) 9ec6b1767f2c182a40349b8d58e3c88252dafc61 Remove redundant field names in struct initialization (Tobin C. Harding) Pull request description: After doing #668 I wanted to be able to use the `just sane` command before pushing PRs, so fix the lint issues. ACKs for top commit: apoelstra: ACK 76346427f9f1ea8624ca6e1e1bb228a718c26e88 thanks! we should re-enabled Clippy in CI in this repo...I believe we disabled it due to a clippy bug in July Tree-SHA512: 1e953f2fc1a6e649324293a84abf1be54feca6095111653af046aacf17a83e6ae15452fe8825599ccbfae0ea84fe7d1988c8b72d5dd902c9d0fb1d34e660ef8b
2 parents afe1818 + 107113f commit b8447f1

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

examples/psbt_sign_finalize.rs

Lines changed: 7 additions & 6 deletions
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!("Bridge pubkey script: {}", bridge_descriptor.script_pubkey());
@@ -81,10 +81,11 @@ fn main() {
8181

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

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

9091
psbt.unsigned_tx.output.push(TxOut {
@@ -133,7 +134,7 @@ fn main() {
133134

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

138139
println!("{:#?}", psbt);
139140
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
}

src/policy/compiler.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ mod tests {
12731273
ret.push(pk);
12741274
}
12751275
let sig = secp.sign_ecdsa(
1276-
&secp256k1::Message::from_digest(sk.clone()), // Not a digest but 32 bytes nonetheless.
1276+
&secp256k1::Message::from_digest(sk), // Not a digest but 32 bytes nonetheless.
12771277
&secp256k1::SecretKey::from_slice(&sk[..]).expect("secret key"),
12781278
);
12791279
(ret, sig)
@@ -1351,11 +1351,12 @@ mod tests {
13511351
}
13521352

13531353
#[test]
1354+
#[allow(clippy::needless_range_loop)]
13541355
fn compile_misc() {
13551356
let (keys, sig) = pubkeys_and_a_sig(10);
13561357
let key_pol: Vec<BPolicy> = keys.iter().map(|k| Concrete::Key(*k)).collect();
13571358

1358-
let policy: BPolicy = Concrete::Key(keys[0].clone());
1359+
let policy: BPolicy = Concrete::Key(keys[0]);
13591360
let ms: SegwitMiniScript = policy.compile().unwrap();
13601361
assert_eq!(
13611362
ms.encode(),
@@ -1567,7 +1568,7 @@ mod tests {
15671568
(1, Arc::new(Concrete::Thresh(keys_b.len(), keys_b))),
15681569
])
15691570
.compile();
1570-
let script_size = thresh_res.clone().and_then(|m| Ok(m.script_size()));
1571+
let script_size = thresh_res.clone().map(|m| m.script_size());
15711572
assert_eq!(
15721573
thresh_res,
15731574
Err(CompilerError::LimitsExceeded),
@@ -1584,7 +1585,7 @@ mod tests {
15841585
let thresh_res: Result<SegwitMiniScript, _> = Concrete::Thresh(keys.len(), keys).compile();
15851586
let n_elements = thresh_res
15861587
.clone()
1587-
.and_then(|m| Ok(m.max_satisfaction_witness_elements()));
1588+
.map(|m| m.max_satisfaction_witness_elements());
15881589
assert_eq!(
15891590
thresh_res,
15901591
Err(CompilerError::LimitsExceeded),
@@ -1603,7 +1604,7 @@ mod tests {
16031604
.collect();
16041605
let thresh_res: Result<SegwitMiniScript, _> =
16051606
Concrete::Thresh(keys.len() - 1, keys).compile();
1606-
let ops_count = thresh_res.clone().and_then(|m| Ok(m.ext.ops.op_count()));
1607+
let ops_count = thresh_res.clone().map(|m| m.ext.ops.op_count());
16071608
assert_eq!(
16081609
thresh_res,
16091610
Err(CompilerError::LimitsExceeded),
@@ -1617,7 +1618,7 @@ mod tests {
16171618
.map(|pubkey| Arc::new(Concrete::Key(*pubkey)))
16181619
.collect();
16191620
let thresh_res = Concrete::Thresh(keys.len() - 1, keys).compile::<Legacy>();
1620-
let ops_count = thresh_res.clone().and_then(|m| Ok(m.ext.ops.op_count()));
1621+
let ops_count = thresh_res.clone().map(|m| m.ext.ops.op_count());
16211622
assert_eq!(
16221623
thresh_res,
16231624
Err(CompilerError::LimitsExceeded),

src/policy/concrete.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ mod compiler_tests {
11051105
let policies: Vec<Arc<Concrete<String>>> = vec!["pk(A)", "pk(B)", "pk(C)", "pk(D)"]
11061106
.into_iter()
11071107
.map(|st| policy_str!("{}", st))
1108-
.map(|p| Arc::new(p))
1108+
.map(Arc::new)
11091109
.collect();
11101110

11111111
let combinations = generate_combination(&policies, 1.0, 2);
@@ -1133,10 +1133,7 @@ mod compiler_tests {
11331133
let expected_comb = vec![comb_a, comb_b, comb_c, comb_d]
11341134
.into_iter()
11351135
.map(|sub_pol| {
1136-
(
1137-
0.25,
1138-
Arc::new(Policy::Thresh(2, sub_pol.into_iter().map(|p| Arc::new(p)).collect())),
1139-
)
1136+
(0.25, Arc::new(Policy::Thresh(2, sub_pol.into_iter().map(Arc::new).collect())))
11401137
})
11411138
.collect::<Vec<_>>();
11421139
assert_eq!(combinations, expected_comb);

src/policy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ mod tests {
453453
.iter()
454454
.zip(node_probabilities.iter())
455455
.collect::<Vec<_>>();
456-
sorted_policy_prob.sort_by(|a, b| (a.1).partial_cmp(&b.1).unwrap());
456+
sorted_policy_prob.sort_by(|a, b| (a.1).partial_cmp(b.1).unwrap());
457457
let sorted_policies = sorted_policy_prob
458458
.into_iter()
459459
.map(|(x, _prob)| x)

0 commit comments

Comments
 (0)