mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 02:11:40 +01:00
Adding comments as to why TransactionInput's parsed from JSON cannot be reserialized into bitcoin hex format as of now
This commit is contained in:
parent
06e7decf56
commit
4e93ff3e37
@ -28,23 +28,15 @@ trait RawTransactionInputParser extends RawBitcoinSerializer[Seq[TransactionInpu
|
||||
val outPointBytesSize = 36
|
||||
val outPointBytes = bytes.take(outPointBytesSize)
|
||||
val outPoint : TransactionOutPoint = RawTransactionOutPointParser.read(outPointBytes)
|
||||
//require(outPoint.txId == "e99eb3e6551844d0db252ef242c043796b3b0ccfb126c0ae09f9dd0230e2f10d")
|
||||
|
||||
val scriptVarIntSize : Int = ScalacoinUtil.parseVarIntSize(bytes(outPointBytesSize)).toInt
|
||||
//require(scriptVarIntSize == 3, scriptVarIntSize +" was not equal to 2")
|
||||
logger.debug("VarInt hex: " + ScalacoinUtil.encodeHex(bytes.slice(outPointBytesSize,outPointBytesSize + scriptVarIntSize)))
|
||||
val scriptSigVarInt : VarInt = ScalacoinUtil.parseVarInt(bytes.slice(outPointBytesSize,outPointBytesSize + scriptVarIntSize))
|
||||
//require(scriptSigVarInt == VarIntImpl(253,3), scriptSigVarInt + " was not what we expected")
|
||||
logger.debug("Outpoint hex: " + outPoint.hex)
|
||||
|
||||
logger.debug("Script VarInt bytes: " + bytes(outPointBytesSize))
|
||||
logger.debug("Script VarInt Size: " + scriptSigVarInt)
|
||||
val scriptSigBytes = bytes.slice(outPointBytesSize+ scriptVarIntSize,
|
||||
outPointBytesSize + scriptVarIntSize + scriptSigVarInt.num.toInt)
|
||||
|
||||
val scriptSig : ScriptSignature = RawScriptSignatureParser.read(scriptSigBytes)
|
||||
//require(scriptSig.hex == "004730440220028c02f14654a0cc12c7e3229adb09d5d35bebb6ba1057e39adb1b2706607b0d0220564fab12c6da3d5acef332406027a7ff1cbba980175ffd880e1ba1bf40598f6b014830450221009362f8d67b60773745e983d07ba10efbe566127e244b724385b2ca2e47292dda022033def393954c320653843555ddbe7679b35cc1cacfe1dad923977de8cd6cc6d7014c695221025e9adcc3d65c11346c8a6069d6ebf5b51b348d1d6dc4b95e67480c34dc0bc75c21030585b3c80f4964bf0820086feda57c8e49fa1eab925db7c04c985467973df96521037753a5e3e9c4717d3f81706b38a6fb82b5fb89d29e580d7b98a37fea8cdefcad53ae",
|
||||
//scriptSig.hex + " was not the expected hex value")
|
||||
logger.debug("Script sig hex: " + scriptSig.hex)
|
||||
|
||||
val sequenceBytesSize = 4
|
||||
val endOfScriptSigBytes = outPointBytesSize + scriptSigVarInt.num.toInt + scriptVarIntSize
|
||||
@ -58,8 +50,7 @@ trait RawTransactionInputParser extends RawBitcoinSerializer[Seq[TransactionInpu
|
||||
val newAccum = txInput :: accum
|
||||
val bytesToBeParsed = bytes.slice(lastInputByte, bytes.size)
|
||||
val inputsLeft = inputsLeftToParse - 1
|
||||
logger.debug("Parsed tx input: " + txInput)
|
||||
logger.debug("Inputs to be parsed " + inputsLeft)
|
||||
|
||||
loop(bytesToBeParsed, newAccum,inputsLeft)
|
||||
} else accum
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ trait CryptoInterpreter extends ControlOperationsInterpreter with ScalacoinUtil
|
||||
require(program.stack.size > 1, "Stack must have at least 2 items on it for OP_CHECKSIG")
|
||||
val pubKey = program.stack.head
|
||||
val signature = program.stack.tail.head
|
||||
val hashType = HashTypeFactory.fromByte(ScalacoinUtil.decodeHex(signature.hex.last))
|
||||
|
||||
val restOfStack = program.stack.tail.tail
|
||||
val hashType = HashTypeFactory.fromByte(ScalacoinUtil.decodeHex(signature.hex).last)
|
||||
???
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,10 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
|
||||
//crypto operations
|
||||
case OP_HASH160 :: t => loop(opHash160(program))
|
||||
//case OP_CHECKSIG :: t => opCheckSig(program.stack,program.script,fullScript)
|
||||
case OP_CHECKSIG :: t =>
|
||||
val newProgram = opCheckSig(program)
|
||||
if (t.isEmpty) newProgram.valid
|
||||
else loop(newProgram)
|
||||
case OP_SHA1 :: t => loop(opSha1(program))
|
||||
case OP_RIPEMD160 :: t => loop(opRipeMd160(program))
|
||||
case OP_SHA256 :: t => loop(opSha256(program))
|
||||
|
@ -10,7 +10,7 @@ import org.scalacoin.script.crypto.{OP_CHECKSIG, OP_HASH160}
|
||||
import org.scalacoin.script.interpreter.testprotocol.{CoreTestCaseProtocol, CoreTestCase}
|
||||
import org.scalacoin.script.reserved.OP_NOP
|
||||
import org.scalacoin.script.stack.OP_DUP
|
||||
import org.scalacoin.util.TestUtil
|
||||
import org.scalacoin.util.{TransactionTestUtil, TestUtil}
|
||||
import org.scalatest.{MustMatchers, FlatSpec}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
@ -18,7 +18,7 @@ import spray.json._
|
||||
/**
|
||||
* Created by chris on 1/6/16.
|
||||
*/
|
||||
class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterpreter {
|
||||
class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterpreter with TransactionTestUtil {
|
||||
|
||||
|
||||
private val logger = LoggerFactory.getLogger(this.getClass())
|
||||
@ -63,13 +63,15 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
val source = scala.io.Source.fromFile("src/test/scala/org/scalacoin/script/interpreter/script_valid.json")
|
||||
|
||||
//use this to represent a single test case from script_valid.json
|
||||
/*
|
||||
val lines =
|
||||
"""
|
||||
|
|
||||
|[["0", "0x21 0x02865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac0 CHECKSIG NOT", "STRICTENC"]]
|
||||
""".stripMargin
|
||||
*/
|
||||
|
||||
//val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
|
||||
val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
|
||||
val json = lines.parseJson
|
||||
val testCasesOpt : Seq[Option[CoreTestCase]] = json.convertTo[Seq[Option[CoreTestCase]]]
|
||||
val testCases : Seq[CoreTestCase] = testCasesOpt.flatten
|
||||
@ -77,6 +79,7 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
|
||||
for {
|
||||
testCase <- testCases
|
||||
tx = buildSpendingTransaction(testCase.scriptSig, buildCreditingTransaction(testCase.scriptPubKey))
|
||||
} yield {
|
||||
logger.info("Raw test case: " + testCase.raw)
|
||||
logger.info("Parsed ScriptSig: " + testCase.scriptSig)
|
||||
@ -84,7 +87,7 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
logger.info("Flags: " + testCase.flags)
|
||||
logger.info("Comments: " + testCase.comments)
|
||||
withClue(testCase.raw) {
|
||||
ScriptInterpreter.run(testCase.scriptSig, testCase.scriptPubKey,TestUtil.transaction) must equal (true)
|
||||
ScriptInterpreter.run(testCase.scriptSig, testCase.scriptPubKey, tx) must equal (true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ trait TransactionTestUtil {
|
||||
* @param tx
|
||||
*/
|
||||
def buildSpendingTransaction(scriptSignature : ScriptSignature, tx : Transaction) : Transaction = {
|
||||
|
||||
val outpoint = TransactionOutPointImpl(tx.txId,0)
|
||||
val input = TransactionInputImpl(outpoint,VarIntImpl(0,0),scriptSignature,0xFFFFFFFF)
|
||||
//empty script pubkey
|
||||
|
Loading…
Reference in New Issue
Block a user