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.
This commit is contained in:
Dave Collins 2019-03-13 01:12:48 -05:00
parent 7cf42b0a70
commit 706b3a1fcd
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -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
}