Skip to content

Commit ea9746b

Browse files
committed
adapted to the updated version of the bitcoin crate
1 parent 6963661 commit ea9746b

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
@@ -32,7 +32,7 @@ socks = { version = "0.3", optional = true }
3232
lazy_static = { version = "1.4", optional = true }
3333
tiny-bip39 = { version = "^0.8", optional = true }
3434
bitcoinconsensus = { version = "0.19.0-3", optional = true }
35-
base64 = { version = "^0.11", optional = true }
35+
base64 = { version = "^0.13", optional = true }
3636

3737
# Needed by bdk_blockchain_tests macro
3838
bitcoincore-rpc = { version = "0.13", optional = true }
@@ -75,7 +75,7 @@ env_logger = "0.7"
7575
clap = "2.33"
7676
serial_test = "0.4"
7777
bitcoind = "0.10.0"
78-
rstest = "^0.7"
78+
rstest = "^0.10"
7979

8080
[[example]]
8181
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)