Skip to content

Commit

Permalink
Merge rust-bitcoin#670: Fix all lint errors and warnings
Browse files Browse the repository at this point in the history
7634642 Use struct update syntax (Tobin C. Harding)
2bc083e Use iterator instead of manual loop (Tobin C. Harding)
6d663e1 Allow range loop in test code (Tobin C. Harding)
a8c156e Use map instead of and_then (Tobin C. Harding)
d5662da Remove redundant closure (Tobin C. Harding)
90f1585 Remove redundant clone (Tobin C. Harding)
409d4b0 Remove explicit reference (Tobin C. Harding)
9ec6b17 Remove redundant field names in struct initialization (Tobin C. Harding)

Pull request description:

  After doing rust-bitcoin#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 7634642 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
  • Loading branch information
apoelstra committed Mar 29, 2024
2 parents cbfe991 + 7634642 commit f44943d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
13 changes: 7 additions & 6 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
let secp256k1 = secp256k1::Secp256k1::new();

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

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

let mut txin = TxIn::default();
txin.previous_output = outpoint;

txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
let txin = TxIn {
previous_output: outpoint,
sequence: Sequence::from_height(26),
..Default::default()
};
psbt.unsigned_tx.input.push(txin);

psbt.unsigned_tx.output.push(TxOut {
Expand Down Expand Up @@ -133,7 +134,7 @@ fn main() {

psbt.inputs[0]
.partial_sigs
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty });

println!("{:#?}", psbt);
println!("{}", psbt);
Expand Down
4 changes: 2 additions & 2 deletions examples/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ fn hardcoded_xonlypubkeys() -> Vec<XOnlyPublicKey> {
],
];
let mut keys: Vec<XOnlyPublicKey> = vec![];
for idx in 0..4 {
keys.push(XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap());
for key in serialized_keys {
keys.push(XOnlyPublicKey::from_slice(&key).unwrap());
}
keys
}
13 changes: 7 additions & 6 deletions src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ mod tests {
ret.push(pk);
}
let sig = secp.sign_ecdsa(
&secp256k1::Message::from_digest(sk.clone()), // Not a digest but 32 bytes nonetheless.
&secp256k1::Message::from_digest(sk), // Not a digest but 32 bytes nonetheless.
&secp256k1::SecretKey::from_slice(&sk[..]).expect("secret key"),
);
(ret, sig)
Expand Down Expand Up @@ -1351,11 +1351,12 @@ mod tests {
}

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

let policy: BPolicy = Concrete::Key(keys[0].clone());
let policy: BPolicy = Concrete::Key(keys[0]);
let ms: SegwitMiniScript = policy.compile().unwrap();
assert_eq!(
ms.encode(),
Expand Down Expand Up @@ -1567,7 +1568,7 @@ mod tests {
(1, Arc::new(Concrete::Thresh(keys_b.len(), keys_b))),
])
.compile();
let script_size = thresh_res.clone().and_then(|m| Ok(m.script_size()));
let script_size = thresh_res.clone().map(|m| m.script_size());
assert_eq!(
thresh_res,
Err(CompilerError::LimitsExceeded),
Expand All @@ -1584,7 +1585,7 @@ mod tests {
let thresh_res: Result<SegwitMiniScript, _> = Concrete::Thresh(keys.len(), keys).compile();
let n_elements = thresh_res
.clone()
.and_then(|m| Ok(m.max_satisfaction_witness_elements()));
.map(|m| m.max_satisfaction_witness_elements());
assert_eq!(
thresh_res,
Err(CompilerError::LimitsExceeded),
Expand All @@ -1603,7 +1604,7 @@ mod tests {
.collect();
let thresh_res: Result<SegwitMiniScript, _> =
Concrete::Thresh(keys.len() - 1, keys).compile();
let ops_count = thresh_res.clone().and_then(|m| Ok(m.ext.ops.op_count()));
let ops_count = thresh_res.clone().map(|m| m.ext.ops.op_count());
assert_eq!(
thresh_res,
Err(CompilerError::LimitsExceeded),
Expand All @@ -1617,7 +1618,7 @@ mod tests {
.map(|pubkey| Arc::new(Concrete::Key(*pubkey)))
.collect();
let thresh_res = Concrete::Thresh(keys.len() - 1, keys).compile::<Legacy>();
let ops_count = thresh_res.clone().and_then(|m| Ok(m.ext.ops.op_count()));
let ops_count = thresh_res.clone().map(|m| m.ext.ops.op_count());
assert_eq!(
thresh_res,
Err(CompilerError::LimitsExceeded),
Expand Down
7 changes: 2 additions & 5 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ mod compiler_tests {
let policies: Vec<Arc<Concrete<String>>> = vec!["pk(A)", "pk(B)", "pk(C)", "pk(D)"]
.into_iter()
.map(|st| policy_str!("{}", st))
.map(|p| Arc::new(p))
.map(Arc::new)
.collect();

let combinations = generate_combination(&policies, 1.0, 2);
Expand Down Expand Up @@ -1133,10 +1133,7 @@ mod compiler_tests {
let expected_comb = vec![comb_a, comb_b, comb_c, comb_d]
.into_iter()
.map(|sub_pol| {
(
0.25,
Arc::new(Policy::Thresh(2, sub_pol.into_iter().map(|p| Arc::new(p)).collect())),
)
(0.25, Arc::new(Policy::Thresh(2, sub_pol.into_iter().map(Arc::new).collect())))
})
.collect::<Vec<_>>();
assert_eq!(combinations, expected_comb);
Expand Down
2 changes: 1 addition & 1 deletion src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mod tests {
.iter()
.zip(node_probabilities.iter())
.collect::<Vec<_>>();
sorted_policy_prob.sort_by(|a, b| (a.1).partial_cmp(&b.1).unwrap());
sorted_policy_prob.sort_by(|a, b| (a.1).partial_cmp(b.1).unwrap());
let sorted_policies = sorted_policy_prob
.into_iter()
.map(|(x, _prob)| x)
Expand Down

0 comments on commit f44943d

Please sign in to comment.