Skip to content

Commit a0648b3

Browse files
committed
Merge #512: Use p2wpkh_script_code from rust-bitcoin
842ae93 Use p2wpkh_script_code from rust-bitcoin (Tobin C. Harding) Pull request description: Currently we have a function to construct the script code for a P2WPKH, this code is now upstream in `rust-bitcoin` so we can use it. Fix: #364 ACKs for top commit: sanket1729: ACK 842ae93 Tree-SHA512: 0510c7c12a8ad85947e7bb02d3cb1ca876af15d47b934688404562f49b9b2f195fb3ec2c4a0fff01b51bec1f0a4a2fa1eeccaf556c18b81570b2fbe69ef27806
2 parents c08f6dc + 842ae93 commit a0648b3

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/psbt/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -893,14 +893,17 @@ impl PsbtExt for Psbt {
893893
.unwrap_or(false);
894894
if inp_spk.is_v0_p2wpkh() || inp_spk.is_v0_p2wsh() || is_nested_wpkh || is_nested_wsh {
895895
let msg = if inp_spk.is_v0_p2wpkh() {
896-
let script_code = script_code_wpkh(inp_spk);
896+
let script_code = inp_spk
897+
.p2wpkh_script_code()
898+
.expect("checked is p2wpkh above");
897899
cache.segwit_signature_hash(idx, &script_code, amt, hash_ty)?
898900
} else if is_nested_wpkh {
899-
let script_code = script_code_wpkh(
900-
inp.redeem_script
901-
.as_ref()
902-
.expect("Redeem script non-empty checked earlier"),
903-
);
901+
let script_code = inp
902+
.redeem_script
903+
.as_ref()
904+
.expect("redeem script non-empty checked earlier")
905+
.p2wpkh_script_code()
906+
.expect("checked is p2wpkh above");
904907
cache.segwit_signature_hash(idx, &script_code, amt, hash_ty)?
905908
} else {
906909
// wsh and nested wsh, script code is witness script
@@ -1254,17 +1257,6 @@ fn update_item_with_descriptor_helper<F: PsbtFields>(
12541257
Ok((derived, true))
12551258
}
12561259

1257-
// Get a script from witness script pubkey hash
1258-
fn script_code_wpkh(script: &Script) -> Script {
1259-
assert!(script.is_v0_p2wpkh());
1260-
// ugly segwit stuff
1261-
let mut script_code = vec![0x76u8, 0xa9, 0x14];
1262-
script_code.extend(&script.as_bytes()[2..]);
1263-
script_code.push(0x88);
1264-
script_code.push(0xac);
1265-
Script::from(script_code)
1266-
}
1267-
12681260
/// Return error type for [`PsbtExt::update_input_with_descriptor`]
12691261
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
12701262
pub enum UtxoUpdateError {

0 commit comments

Comments
 (0)