From c6410257eb2894ee086fda5bb5ce88e33a44011a Mon Sep 17 00:00:00 2001
From: Dave Collins <davec@conformal.com>
Date: Wed, 13 Mar 2019 01:12:53 -0500
Subject: [PATCH] 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.
---
 txscript/engine.go | 16 +++++++++++++++-
 txscript/opcode.go | 14 --------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/txscript/engine.go b/txscript/engine.go
index 00973a03..1c6a124b 100644
--- a/txscript/engine.go
+++ b/txscript/engine.go
@@ -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)
diff --git a/txscript/opcode.go b/txscript/opcode.go
index 62c6649d..dc4ec50e 100644
--- a/txscript/opcode.go
+++ b/txscript/opcode.go
@@ -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 {