mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 18:24:48 +01:00
Fixing bug in serialization for p2sh signature
This commit is contained in:
parent
a83b04e63b
commit
eb2beb9b69
@ -80,7 +80,9 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
||||
}
|
||||
val hashTypeByte = if (signature.bytes.nonEmpty) signature.bytes.last else 0x00.toByte
|
||||
val hashType = HashType(Seq(0.toByte, 0.toByte, 0.toByte, hashTypeByte))
|
||||
val hashForSignature = TransactionSignatureSerializer.hashForSignature(txSignatureComponent,hashType)
|
||||
val hashForSignature = TransactionSignatureSerializer.hashForSignature(txSignatureComponent.transaction,
|
||||
txSignatureComponent.inputIndex,
|
||||
sigsRemovedScript, hashType)
|
||||
logger.info("Hash for signature: " + BitcoinSUtil.encodeHex(hashForSignature.bytes))
|
||||
val isValid = pubKey.verify(hashForSignature,signature)
|
||||
if (isValid) SignatureValidationSuccess else SignatureValidationFailureIncorrectSignatures
|
||||
|
@ -330,8 +330,9 @@ object ScriptProgram {
|
||||
|
||||
/** Creates a fresh instance of [[org.bitcoins.core.script.PreExecutionScriptProgram]] */
|
||||
def apply(transaction: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32, flags: Seq[ScriptFlag]): PreExecutionScriptProgram = {
|
||||
val t = TransactionSignatureComponent(transaction,inputIndex,scriptPubKey, flags)
|
||||
ScriptProgram(t)
|
||||
val t = TransactionSignatureComponent(transaction,inputIndex,scriptPubKey,flags)
|
||||
val script = t.scriptSignature.asm
|
||||
PreExecutionScriptProgramImpl(t,Nil,script.toList,script.toList,Nil,t.flags)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,7 +164,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
else if (evaluated.stackTopIsFalse) ScriptProgram(evaluated,ScriptErrorEvalFalse)
|
||||
else evaluated
|
||||
case Right(err) =>
|
||||
val program = ScriptProgram(witnessTxSigComponent)
|
||||
val program = ScriptProgram.toExecutionInProgress(ScriptProgram(witnessTxSigComponent))
|
||||
ScriptProgram(program,err)
|
||||
}
|
||||
case UnassignedWitness =>
|
||||
|
@ -28,7 +28,7 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
|
||||
|
||||
//use this to represent a single test case from script_valid.json
|
||||
val lines =
|
||||
/* val lines =
|
||||
"""
|
||||
| [ [
|
||||
[
|
||||
@ -42,8 +42,8 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
"OK",
|
||||
"Basic P2WSH"
|
||||
]]
|
||||
""".stripMargin
|
||||
//val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
|
||||
""".stripMargin*/
|
||||
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
|
||||
@ -62,7 +62,7 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
||||
val witness = testCase.witness
|
||||
logger.info("Flags after parsing: " + flags)
|
||||
logger.info("Witness after parsing: " + witness)
|
||||
val program = witness match {
|
||||
val program = witness match {
|
||||
case Some((w, amount)) => ScriptProgram(tx, scriptPubKey, inputIndex,flags,w,amount)
|
||||
case None => ScriptProgram(tx, scriptPubKey, inputIndex, flags)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user