diff --git a/txscript/script.go b/txscript/script.go index 43048e9526..59dc2e272b 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -110,11 +110,7 @@ func IsPayToWitnessScriptHash(script []byte) bool { // IsPayToWitnessPubKeyHash returns true if the is in the standard // pay-to-witness-pubkey-hash (P2WKH) format, false otherwise. func IsPayToWitnessPubKeyHash(script []byte) bool { - pops, err := parseScript(script) - if err != nil { - return false - } - return isWitnessPubKeyHash(pops) + return isWitnessPubKeyHashScript(script) } // isWitnessPubKeyHash returns true if the passed script is a diff --git a/txscript/standard.go b/txscript/standard.go index 98f8f53a9f..b53c83c021 100644 --- a/txscript/standard.go +++ b/txscript/standard.go @@ -396,6 +396,25 @@ func IsMultisigSigScript(script []byte) bool { return isMultisigScript(scriptVersion, possibleRedeemScript) } +// extractWitnessPubKeyHash extracts the witness public key hash from the passed +// script if it is a standard witness-pay-to-pubkey-hash script. It will return +// nil otherwise. +func extractWitnessPubKeyHash(script []byte) []byte { + if len(script) == 22 && + script[0] == OP_0 && + script[1] == OP_DATA_20 { + + return script[2:22] + } + return nil +} + +// isWitnessPubKeyHashScript returns whether or not the passed script is a +// standard witness-pay-to-pubkey-hash script. +func isWitnessPubKeyHashScript(script []byte) bool { + return extractWitnessPubKeyHash(script) != nil +} + // isNullData returns true if the passed script is a null data transaction, // false otherwise. func isNullData(pops []parsedOpcode) bool {