Parsing scripts when they are marshalled from json

This commit is contained in:
Chris Stewart 2016-01-09 11:10:29 -06:00
parent a55b7b64ce
commit 3f48efd664
5 changed files with 17 additions and 16 deletions

View File

@ -1,6 +1,7 @@
package org.scalacoin.protocol.script
import org.scalacoin.protocol.BitcoinAddress
import org.scalacoin.script.ScriptToken
/**
* Created by chris on 12/26/15.
@ -13,5 +14,5 @@ trait ScriptPubKey extends ScriptSignature {
}
case class ScriptPubKeyImpl(asm : String, hex : String, reqSigs : Int,
case class ScriptPubKeyImpl(asm : List[ScriptToken], hex : String, reqSigs : Int,
addressType : String, addresses : Seq[BitcoinAddress]) extends ScriptPubKey

View File

@ -1,11 +1,13 @@
package org.scalacoin.protocol.script
import org.scalacoin.script.ScriptToken
/**
* Created by chris on 12/26/15.
*/
trait ScriptSignature {
def asm : String
def asm : Seq[ScriptToken]
def hex : String
}
case class ScriptSignatureImpl(asm : String, hex : String) extends ScriptSignature
case class ScriptSignatureImpl(asm : Seq[ScriptToken], hex : String) extends ScriptSignature

View File

@ -29,15 +29,13 @@ trait CryptoInterpreter extends ScalacoinUtil {
* @param script
* @return
*/
/*
def checkSig(inputScript : List[String], script : List[ScriptOperation]) : Boolean = {
def checkSig(inputScript : List[ScriptToken], script : List[ScriptToken], fullScript : List[ScriptToken]) : Boolean = {
require(inputScript.size > 1, "We must have at least 2 inputs for our OP_CHECKSIG operation")
require(script.headOption.isDefined && script.head == OP_CHECKSIG, "The top script stack element must be OP_CHECKSIG")
val pubKey = inputScript.head
val signature = inputScript(1)
???
}
*/
/*def codeSeparator()*/

View File

@ -25,7 +25,9 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
*/
def run(inputScript : List[ScriptToken], outputScript : List[ScriptToken]) : Boolean = {
val fullInputScript = inputScript
val fullOutputScript = outputScript
val fullScript = inputScript ++ fullOutputScript
@tailrec
def loop(scripts : (List[ScriptToken], List[ScriptToken])) : Boolean = {
val (inputScript,outputScript) = (scripts._1, scripts._2)
@ -40,7 +42,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
case ScriptConstantImpl(x) :: t => loop((ScriptConstantImpl(x) :: inputScript, t))
//these cases result in our boolean result
case OP_EQUALVERIFY :: t => equalVerify(inputScript,outputScript)
/*case OP_CHECKSIG :: t => checkSig(inputScript,outputScript)*/
case OP_CHECKSIG :: t => checkSig(inputScript,outputScript,fullScript)
}
}

View File

@ -1,9 +1,10 @@
package org.scalacoin.script.interpreter
import org.scalacoin.script.bitwise.OP_EQUALVERIFY
import org.scalacoin.script.{ ScriptOperation}
import org.scalacoin.script.{ScriptToken, ScriptOperation}
import org.scalacoin.script.crypto.{OP_CHECKSIG, OP_HASH160}
import org.scalacoin.script.stack.OP_DUP
import org.scalacoin.util.TestUtil
import org.scalatest.{MustMatchers, FlatSpec}
/**
@ -13,17 +14,14 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
/* "ScriptInterpreter" must "evaluate a valid script to true" in {
"ScriptInterpreter" must "evaluate a valid script to true" in {
//this is in asm format, not hex
val inputScript =
List("3044022016ffdbb7c57634903c5e018fcfc48d59f4e37dc4bc3bbc9ba4e6ee39150bca030220119c2241a931819bc1a75d3596e4029d803d1cd6de123bf8a1a1a2c3665e1fac01",
"02af7dad03e682fcd0427b5c24140c220ac9d8abe286c15f8cf5bf77eed19c3652")
val inputScript = TestUtil.p2pkhInputScriptAsm
//this is asm format, not hex
val outputScript : List[ScriptOperation] =
List(OP_DUP,OP_HASH160,ConstantImpl("e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b"),OP_EQUALVERIFY, OP_CHECKSIG)
val outputScript : List[ScriptToken] = TestUtil.p2pkhOutputScriptAsm
val result = run(inputScript, outputScript)
result must be (true)
}*/
}
}