txscript: Make alwaysIllegal accept raw opcode.

This converts the alwaysIllegal function defined on a parsed opcode to a
standalone function named isOpcodeAlwaysIllegal which accepts an opcode
as a byte instead in order to make it more flexible for raw script
analysis.

It also updates all callers accordingly.
This commit is contained in:
Dave Collins 2019-03-13 01:12:53 -05:00 committed by Roy Lee
parent e928eeb5ce
commit 804327d22c
2 changed files with 15 additions and 15 deletions

View file

@ -194,6 +194,20 @@ func isOpcodeDisabled(opcode byte) bool {
}
}
// isOpcodeAlwaysIllegal returns whether or not the opcode is always illegal
// when passed over by the program counter even if in a non-executed branch (it
// isn't a coincidence that they are conditionals).
func isOpcodeAlwaysIllegal(opcode byte) bool {
switch opcode {
case OP_VERIF:
return true
case OP_VERNOTIF:
return true
default:
return false
}
}
// executeOpcode peforms execution on the passed opcode. It takes into account
// whether or not it is hidden by conditionals, but some rules still must be
// tested in this case.
@ -206,7 +220,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {
}
// Always-illegal opcodes are fail on program counter.
if pop.alwaysIllegal() {
if isOpcodeAlwaysIllegal(pop.opcode.value) {
str := fmt.Sprintf("attempt to execute reserved opcode %s",
pop.opcode.name)
return scriptError(ErrReservedOpcode, str)

View file

@ -692,20 +692,6 @@ func (pop *parsedOpcode) checkParseableInScript(script []byte, scriptPos int) (i
return scriptPos, nil
}
// alwaysIllegal returns whether or not the opcode is always illegal when passed
// over by the program counter even if in a non-executed branch (it isn't a
// coincidence that they are conditionals).
func (pop *parsedOpcode) alwaysIllegal() bool {
switch pop.opcode.value {
case OP_VERIF:
return true
case OP_VERNOTIF:
return true
default:
return false
}
}
// isConditional returns whether or not the opcode is a conditional opcode which
// changes the conditional execution stack when executed.
func (pop *parsedOpcode) isConditional() bool {