Skip to content

Commit 0379cdf

Browse files
committed
adapted to the updated version of the bitcoin crate
1 parent dc7079f commit 0379cdf

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ lazy_static = { version = "1.4", optional = true }
3333
tiny-bip39 = { version = "^0.8", optional = true }
3434
zeroize = { version = "<1.4.0", optional = true }
3535
bitcoinconsensus = { version = "0.19.0-3", optional = true }
36-
base64 = { version = "^0.11", optional = true }
36+
base64 = { version = "^0.13", optional = true }
3737

3838
# Needed by bdk_blockchain_tests macro
3939
bitcoincore-rpc = { version = "0.13", optional = true }
@@ -74,7 +74,7 @@ lazy_static = "1.4"
7474
env_logger = "0.7"
7575
clap = "2.33"
7676
electrsd = { version= "0.6", features = ["trigger", "bitcoind_0_21_1"] }
77-
rstest = "^0.7"
77+
rstest = "^0.10"
7878

7979
[[example]]
8080
name = "address_validator"

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)