Merge pull request #141 from Christewart/interpreter_run_verify

Add runVerify, runAll, and runAllVerify helper methods in ScriptInter…
This commit is contained in:
Chris Stewart 2018-04-05 11:59:42 -04:00 committed by GitHub
commit 5ee167e60d

View file

@ -97,6 +97,27 @@ sealed abstract class ScriptInterpreter {
else ScriptErrorEvalFalse
}
/**
* Runs the given [[org.bitcoins.core.script.PreExecutionScriptProgram]] and
* return if that script was valid or not
*/
def runVerify(p: PreExecutionScriptProgram): Boolean = { ScriptInterpreter.run(p) == ScriptOk }
/**
* Every given [[org.bitcoins.core.script.PreExecutionScriptProgram]] and returns
* it's [[org.bitcoins.core.script.result.ScriptResult]]
*/
def runAll(programs: Seq[PreExecutionScriptProgram]): Seq[ScriptResult] = {
programs.map(p => ScriptInterpreter.run(p))
}
/**
* Runs all the given [[org.bitcoins.core.script.ScriptProgram]] and return
* if it is valid or not
*/
def runAllVerify(programs: Seq[PreExecutionScriptProgram]): Boolean = {
!programs.exists(p => ScriptInterpreter.run(p) != ScriptOk)
}
/**
* P2SH scripts are unique in their evaluation, first the scriptSignature must be added to the stack, next the
* p2sh scriptPubKey must be run to make sure the serialized redeem script hashes to the value found in the p2sh