From d882b68a2cbba8e643695552f38e4b36558f9617 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Thu, 7 Apr 2022 15:13:07 +1000 Subject: [PATCH] Add Script conversion method p2wpkh_script_code In order to sign a utxo that does a p2wpkh spend we need to create the script that can be used to create a sighash. In the libbitcoin docs this is referred to as the 'script code' [0]. The script is the same as a p2pkh script but the pubkey_hash is found in the scriptPubkey. Add a `Script` conversion method that checks if `self` is a v0 p2wpkh script and if so extracts the pubkey_hash and returns the required script. [0] https://github.com/libbitcoin/libbitcoin-system/wiki/P2WPKH-Transactions#spending-a-p2wpkh-output --- src/blockdata/script.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index dd448fd8..5f995a26 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -427,6 +427,25 @@ impl Script { Script::new_p2sh(&self.script_hash()) } + /// Returns the script code used for spending a P2WPKH output if this script is a script pubkey + /// for a P2WPKH output. The `scriptCode` is described in [BIP143]. + /// + /// [BIP143]: + pub fn p2wpkh_script_code(&self) -> Option