diff --git a/src/main/scala/org/scalacoin/protocol/script/ScriptPubKey.scala b/src/main/scala/org/scalacoin/protocol/script/ScriptPubKey.scala index e88f922d34..7a41856462 100644 --- a/src/main/scala/org/scalacoin/protocol/script/ScriptPubKey.scala +++ b/src/main/scala/org/scalacoin/protocol/script/ScriptPubKey.scala @@ -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 diff --git a/src/main/scala/org/scalacoin/protocol/script/ScriptSignature.scala b/src/main/scala/org/scalacoin/protocol/script/ScriptSignature.scala index 8fe1e1c305..ff132b9650 100644 --- a/src/main/scala/org/scalacoin/protocol/script/ScriptSignature.scala +++ b/src/main/scala/org/scalacoin/protocol/script/ScriptSignature.scala @@ -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 \ No newline at end of file +case class ScriptSignatureImpl(asm : Seq[ScriptToken], hex : String) extends ScriptSignature \ No newline at end of file diff --git a/src/main/scala/org/scalacoin/script/crypto/CryptoInterpreter.scala b/src/main/scala/org/scalacoin/script/crypto/CryptoInterpreter.scala index dbe3940bbf..177d655725 100644 --- a/src/main/scala/org/scalacoin/script/crypto/CryptoInterpreter.scala +++ b/src/main/scala/org/scalacoin/script/crypto/CryptoInterpreter.scala @@ -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()*/ diff --git a/src/main/scala/org/scalacoin/script/interpreter/ScriptInterpreter.scala b/src/main/scala/org/scalacoin/script/interpreter/ScriptInterpreter.scala index c8729f59bb..8e46af01f0 100644 --- a/src/main/scala/org/scalacoin/script/interpreter/ScriptInterpreter.scala +++ b/src/main/scala/org/scalacoin/script/interpreter/ScriptInterpreter.scala @@ -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) } } diff --git a/src/test/scala/org/scalacoin/script/interpreter/ScriptInterpreterTest.scala b/src/test/scala/org/scalacoin/script/interpreter/ScriptInterpreterTest.scala index 1273556e13..4c0205a16f 100644 --- a/src/test/scala/org/scalacoin/script/interpreter/ScriptInterpreterTest.scala +++ b/src/test/scala/org/scalacoin/script/interpreter/ScriptInterpreterTest.scala @@ -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) - }*/ + } }