From 706b3a1fcdb1b8e807eb0814aa0335f57dfd4d39 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 13 Mar 2019 01:12:48 -0500 Subject: [PATCH] txscript: Use raw scripts in RawTxInSignatureAlt. This converts RawTxInSignatureAlt to make use of the recently converted CalcSignatureHash function that works with raw scripts in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether and updates the comment to explicitly call out the script version semantics. It is worth noting that this has the side effect of optimizing the function as well, however, since this change is not focused on the optimization aspects, no benchmarks are provided. --- txscript/sign.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/txscript/sign.go b/txscript/sign.go index 4b602448..f9f53925 100644 --- a/txscript/sign.go +++ b/txscript/sign.go @@ -41,15 +41,15 @@ func RawTxInSignature(tx *wire.MsgTx, idx int, subScript []byte, // RawTxInSignatureAlt returns the serialized ECDSA signature for the input idx of // the given transaction, with hashType appended to it. +// +// NOTE: This function is only valid for version 0 scripts. Since the function +// does not accept a script version, the results are undefined for other script +// versions. func RawTxInSignatureAlt(tx *wire.MsgTx, idx int, subScript []byte, hashType SigHashType, key chainec.PrivateKey, sigType dcrec.SignatureType) ([]byte, error) { - parsedScript, err := parseScript(subScript) - if err != nil { - return nil, fmt.Errorf("cannot parse output script: %v", err) - } - hash, err := calcSignatureHash(parsedScript, hashType, tx, idx, nil) + hash, err := CalcSignatureHash(subScript, hashType, tx, idx, nil) if err != nil { return nil, err }