txscript: Remove CalcScriptInfo.

This removes the deprecated CalcScriptInfo function along with the
associated ScriptInfo struct and tests.
This commit is contained in:
Dave Collins 2019-06-18 23:50:44 -05:00
parent 41f1139e3b
commit b92aa63e07
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
2 changed files with 0 additions and 198 deletions

View File

@ -636,25 +636,6 @@ func expectedInputs(script []byte, class ScriptClass, subclass ScriptClass) int
}
}
// ScriptInfo houses information about a script pair that is determined by
// CalcScriptInfo.
type ScriptInfo struct {
// PkScriptClass is the class of the public key script and is equivalent
// to calling GetScriptClass on it.
PkScriptClass ScriptClass
// NumInputs is the number of inputs provided by the public key script.
NumInputs int
// ExpectedInputs is the number of outputs required by the signature
// script and any pay-to-script-hash scripts. The number will be -1 if
// unknown.
ExpectedInputs int
// SigOps is the number of signature operations in the script pair.
SigOps int
}
// isStakeOutput returns true is a script output is a stake type.
//
// NOTE: This function is only valid for version 0 scripts. Since the function
@ -721,77 +702,6 @@ func ContainsStakeOpCodes(pkScript []byte) (bool, error) {
return false, tokenizer.Err()
}
// CalcScriptInfo returns a structure providing data about the provided script
// pair. It will error if the pair is in someway invalid such that they can not
// be analysed, i.e. if they do not parse or the pkScript is not a push-only
// script
//
// 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.
//
// DEPRECATED. This will be removed in the next major version bump.
func CalcScriptInfo(sigScript, pkScript []byte, bip16 bool) (*ScriptInfo, error) {
// Count the number of opcodes in the signature script while also ensuring
// that successfully parses. Since there is a check below to ensure the
// script is push only, this equates to the number of inputs to the public
// key script.
const scriptVersion = 0
var numInputs int
tokenizer := MakeScriptTokenizer(scriptVersion, sigScript)
for tokenizer.Next() {
numInputs++
}
if err := tokenizer.Err(); err != nil {
return nil, err
}
if err := checkScriptParses(scriptVersion, pkScript); err != nil {
return nil, err
}
// Can't have a signature script that doesn't just push data.
if !IsPushOnlyScript(sigScript) {
return nil, scriptError(ErrNotPushOnly,
"signature script is not push only")
}
si := new(ScriptInfo)
si.PkScriptClass = typeOfScript(scriptVersion, pkScript)
subClass := ScriptClass(0)
if si.PkScriptClass == StakeSubmissionTy ||
si.PkScriptClass == StakeGenTy ||
si.PkScriptClass == StakeRevocationTy ||
si.PkScriptClass == StakeSubChangeTy {
subClass = typeOfScript(scriptVersion, getStakeOutSubscript(pkScript))
}
si.ExpectedInputs = expectedInputs(pkScript, si.PkScriptClass, subClass)
// All entries pushed to stack (or are OP_RESERVED and exec will fail).
si.NumInputs = numInputs
// Count sigops taking into account pay-to-script-hash.
if (si.PkScriptClass == ScriptHashTy || subClass == ScriptHashTy) && bip16 {
// The redeem script is the final data push of the signature script.
redeemScript := finalOpcodeData(scriptVersion, sigScript)
reedeemClass := typeOfScript(scriptVersion, redeemScript)
rsInputs := expectedInputs(redeemScript, reedeemClass, 0)
if rsInputs == -1 {
si.ExpectedInputs = -1
} else {
si.ExpectedInputs += rsInputs
}
si.SigOps = countSigOpsV0(redeemScript, true)
} else {
si.SigOps = countSigOpsV0(pkScript, true)
}
return si, nil
}
// CalcMultiSigStats returns the number of public keys and signatures from
// a multi-signature transaction script. The passed script MUST already be
// known to be a multi-signature script.

View File

@ -355,114 +355,6 @@ func TestExtractPkScriptAddrs(t *testing.T) {
}
}
// TestCalcScriptInfo ensures the CalcScriptInfo provides the expected results
// for various valid and invalid script pairs.
func TestCalcScriptInfo(t *testing.T) {
t.Parallel()
tests := []struct {
name string
sigScript string
pkScript string
bip16 bool
scriptInfo ScriptInfo
scriptInfoErr error
}{
{
// Invented scripts, the hashes do not match
// Truncated version of test below:
name: "pkscript doesn't parse",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c",
bip16: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
},
{
name: "sigScript doesn't parse",
// Truncated version of p2sh script below.
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
bip16: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
},
{
// Invented scripts, the hashes do not match
name: "p2sh standard script",
sigScript: "1 81 DATA_25 DUP HASH160 DATA_20 0x010203" +
"0405060708090a0b0c0d0e0f1011121314 EQUALVERIFY " +
"CHECKSIG",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
bip16: true,
scriptInfo: ScriptInfo{
PkScriptClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: 3, // nonstandard p2sh.
SigOps: 1,
},
},
{
// from 567a53d1ce19ce3d07711885168484439965501536d0d0294c5d46d46c10e53b
// from the blockchain.
name: "p2sh nonstandard script",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
bip16: true,
scriptInfo: ScriptInfo{
PkScriptClass: ScriptHashTy,
NumInputs: 3,
ExpectedInputs: -1, // nonstandard p2sh.
SigOps: 0,
},
},
{
// Script is invented, numbers all fake.
name: "multisig script",
sigScript: "1 1 1",
pkScript: "3 " +
"DATA_33 0x0202030405060708090a0b0c0d0e0f1011" +
"12131415161718191a1b1c1d1e1f2021 DATA_33 " +
"0x0302030405060708090a0b0c0d0e0f101112131415" +
"161718191a1b1c1d1e1f2021 DATA_33 0x020203040" +
"5060708090a0b0c0d0e0f101112131415161718191a1" +
"b1c1d1e1f2021 3 CHECKMULTISIG",
bip16: true,
scriptInfo: ScriptInfo{
PkScriptClass: MultiSigTy,
NumInputs: 3,
ExpectedInputs: 3,
SigOps: 3,
},
},
}
for _, test := range tests {
sigScript := mustParseShortForm(test.sigScript)
pkScript := mustParseShortForm(test.pkScript)
si, err := CalcScriptInfo(sigScript, pkScript, test.bip16)
if e := tstCheckScriptError(err, test.scriptInfoErr); e != nil {
t.Errorf("scriptinfo test %q: %v", test.name, e)
continue
}
if err != nil {
continue
}
if *si != test.scriptInfo {
t.Errorf("%s: scriptinfo doesn't match expected. "+
"got: %q expected %q", test.name, *si,
test.scriptInfo)
continue
}
}
}
// bogusAddress implements the dcrutil.Address interface so the tests can ensure
// unsupported address types are handled properly.
type bogusAddress struct{}