Skip to content

Commit def6089

Browse files
committed
adapted to the updated version of the bitcoin crate
1 parent 2cfdf92 commit def6089

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/wallet/reserves.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,18 @@ fn challenge_txin(message: &str) -> TxIn {
283283
/// Verify the SIGHASH type for a TxIn
284284
fn verify_sighash_type_all(inp: &TxIn) -> bool {
285285
if inp.witness.is_empty() {
286-
if let Some(sht) = inp.script_sig.as_bytes().last() {
286+
if let Some(sht_int) = inp.script_sig.as_bytes().last() {
287287
#[allow(clippy::if_same_then_else)]
288288
#[allow(clippy::needless_bool)]
289-
if SigHashType::from_u32(*sht as u32) == SigHashType::All {
290-
true
291-
} else if *sht == 174 {
289+
if *sht_int == 174 {
292290
// ToDo: What is the meaning of this?
293291
true
292+
} else if let Ok(sht) = SigHashType::from_u32_standard(*sht_int as u32) {
293+
if sht == SigHashType::All {
294+
true
295+
} else {
296+
false
297+
}
294298
} else {
295299
false
296300
}
@@ -304,8 +308,11 @@ fn verify_sighash_type_all(inp: &TxIn) -> bool {
304308
// ToDo: Why are there empty elements?
305309
continue;
306310
}
307-
let sht = SigHashType::from_u32(*wit.last().unwrap() as u32);
308-
if SigHashType::All != sht {
311+
if let Ok(sht) = SigHashType::from_u32_standard(*wit.last().unwrap() as u32) {
312+
if SigHashType::All != sht {
313+
return false;
314+
}
315+
} else {
309316
return false;
310317
}
311318
}
@@ -358,7 +365,7 @@ mod test {
358365
.iter()
359366
.fold(0, |acc, i| acc + i.partial_sigs.len());
360367
assert_eq!(num_sigs, num_inp - 1);
361-
assert_eq!(finalized, true);
368+
assert!(finalized);
362369

363370
let spendable = wallet.verify_proof(&psbt, &message)?;
364371
assert_eq!(spendable, balance);
@@ -604,29 +611,29 @@ mod test {
604611
};
605612
let finalized = wallet1.sign(&mut psbt, signopts.clone())?;
606613
assert_eq!(count_signatures(&psbt), (num_inp - 1, 1, 0));
607-
assert_eq!(finalized, false);
614+
assert!(!finalized);
608615

609616
let finalized = wallet2.sign(&mut psbt, signopts.clone())?;
610617
assert_eq!(
611618
count_signatures(&psbt),
612619
((num_inp - 1) * 2, num_inp, num_inp - 1)
613620
);
614-
assert_eq!(finalized, true);
621+
assert!(finalized);
615622

616623
// 2 signatures are enough. Just checking what happens...
617624
let finalized = wallet3.sign(&mut psbt, signopts.clone())?;
618625
assert_eq!(
619626
count_signatures(&psbt),
620627
((num_inp - 1) * 2, num_inp, num_inp - 1)
621628
);
622-
assert_eq!(finalized, true);
629+
assert!(finalized);
623630

624631
let finalized = wallet1.finalize_psbt(&mut psbt, signopts)?;
625632
assert_eq!(
626633
count_signatures(&psbt),
627634
((num_inp - 1) * 2, num_inp, num_inp - 1)
628635
);
629-
assert_eq!(finalized, true);
636+
assert!(finalized);
630637

631638
// additional temporary checks
632639
match script_type {

0 commit comments

Comments
 (0)