txscript: Make isConditional accept raw opcode.
This converts the isConditional function defined on a parsed opcode to a standalone function named isOpcodeConditional 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:
parent
c6410257eb
commit
62c608f265
2 changed files with 18 additions and 18 deletions
|
@ -208,6 +208,23 @@ func isOpcodeAlwaysIllegal(opcode byte) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isOpcodeConditional returns whether or not the opcode is a conditional opcode
|
||||||
|
// which changes the conditional execution stack when executed.
|
||||||
|
func isOpcodeConditional(opcode byte) bool {
|
||||||
|
switch opcode {
|
||||||
|
case OP_IF:
|
||||||
|
return true
|
||||||
|
case OP_NOTIF:
|
||||||
|
return true
|
||||||
|
case OP_ELSE:
|
||||||
|
return true
|
||||||
|
case OP_ENDIF:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// executeOpcode peforms execution on the passed opcode. It takes into account
|
// 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
|
// whether or not it is hidden by conditionals, but some rules still must be
|
||||||
// tested in this case.
|
// tested in this case.
|
||||||
|
@ -243,7 +260,7 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {
|
||||||
|
|
||||||
// Nothing left to do when this is not a conditional opcode and it is
|
// Nothing left to do when this is not a conditional opcode and it is
|
||||||
// not in an executing branch.
|
// not in an executing branch.
|
||||||
if !vm.isBranchExecuting() && !pop.isConditional() {
|
if !vm.isBranchExecuting() && !isOpcodeConditional(pop.opcode.value) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -692,23 +692,6 @@ func (pop *parsedOpcode) checkParseableInScript(script []byte, scriptPos int) (i
|
||||||
return scriptPos, nil
|
return scriptPos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// isConditional returns whether or not the opcode is a conditional opcode which
|
|
||||||
// changes the conditional execution stack when executed.
|
|
||||||
func (pop *parsedOpcode) isConditional() bool {
|
|
||||||
switch pop.opcode.value {
|
|
||||||
case OP_IF:
|
|
||||||
return true
|
|
||||||
case OP_NOTIF:
|
|
||||||
return true
|
|
||||||
case OP_ELSE:
|
|
||||||
return true
|
|
||||||
case OP_ENDIF:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkMinimalDataPush returns whether or not the current data push uses the
|
// checkMinimalDataPush returns whether or not the current data push uses the
|
||||||
// smallest possible opcode to represent it. For example, the value 15 could
|
// smallest possible opcode to represent it. For example, the value 15 could
|
||||||
// be pushed with OP_DATA_1 15 (among other variations); however, OP_15 is a
|
// be pushed with OP_DATA_1 15 (among other variations); however, OP_15 is a
|
||||||
|
|
Loading…
Reference in a new issue