mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-25 07:17:32 +01:00
Refactoring BytesToPushOntoStackImpl into it's factory object
This commit is contained in:
parent
49020bb236
commit
8450d6ef18
17 changed files with 83 additions and 71 deletions
|
@ -90,7 +90,7 @@ trait ScriptParser extends Factory[List[ScriptToken]] with BitcoinSLogger {
|
|||
case size if size < Int.MaxValue =>
|
||||
List(scriptNumber,OP_PUSHDATA4)
|
||||
}
|
||||
case false => List(BytesToPushOntoStack(bytes.size).get)
|
||||
case false => List(BytesToPushOntoStack(bytes.size))
|
||||
}
|
||||
|
||||
loop(t, bytes.toList ++ bytesToPushOntoStack.flatMap(_.bytes) ++ accum)
|
||||
|
@ -110,14 +110,14 @@ trait ScriptParser extends Factory[List[ScriptToken]] with BitcoinSLogger {
|
|||
case h :: t if (tryParsingLong(h)) =>
|
||||
logger.debug("Found a decimal number")
|
||||
val hexLong = BitcoinSUtil.flipEndianess(BitcoinSUtil.longToHex(h.toLong))
|
||||
val bytesToPushOntoStack = BytesToPushOntoStack(hexLong.size / 2).get
|
||||
val bytesToPushOntoStack = BytesToPushOntoStack(hexLong.size / 2)
|
||||
//convert the string to int, then convert to hex
|
||||
loop(t, BitcoinSUtil.decodeHex(hexLong) ++ bytesToPushOntoStack.bytes ++ accum)
|
||||
//means that it must be a BytesToPushOntoStack followed by a script constant
|
||||
case h :: t =>
|
||||
logger.debug("Generic h :: t")
|
||||
//find the size of the string in bytes
|
||||
val bytesToPushOntoStack = BytesToPushOntoStackImpl(h.size / 2)
|
||||
val bytesToPushOntoStack = BytesToPushOntoStack(h.size / 2)
|
||||
loop(t, BitcoinSUtil.decodeHex(BitcoinSUtil.flipEndianess(h)) ++ bytesToPushOntoStack.bytes ++ accum)
|
||||
case Nil => accum
|
||||
}
|
||||
|
|
|
@ -248,8 +248,8 @@ object ScriptSignature extends Factory[ScriptSignature] with BitcoinSLogger {
|
|||
def factory(signature : ECDigitalSignature, pubKey : ECPublicKey) : ScriptSignature = {
|
||||
val signatureBytesToPushOntoStack = BytesToPushOntoStack(signature.bytes.size)
|
||||
val pubKeyBytesToPushOntoStack = BytesToPushOntoStack(pubKey.bytes.size)
|
||||
val asm : Seq[ScriptToken] = Seq(signatureBytesToPushOntoStack.get, ScriptConstant(signature.hex),
|
||||
pubKeyBytesToPushOntoStack.get, ScriptConstant(pubKey.hex))
|
||||
val asm : Seq[ScriptToken] = Seq(signatureBytesToPushOntoStack, ScriptConstant(signature.hex),
|
||||
pubKeyBytesToPushOntoStack, ScriptConstant(pubKey.hex))
|
||||
fromAsm(asm)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,24 +8,34 @@ import org.bitcoins.script.ScriptOperationFactory
|
|||
*/
|
||||
trait BytesToPushOntoStack extends ScriptOperation
|
||||
|
||||
case class BytesToPushOntoStackImpl(num : Int) extends BytesToPushOntoStack {
|
||||
/* //see the 'Constants; section in https://en.bitcoin.it/wiki/Script
|
||||
require(num >= -1 && num <= 75, "A valid script number is between 1 and 75, the number passed in was: " + num)*/
|
||||
require(num >= 0, "BytesToPushOntoStackImpl cannot be negative")
|
||||
override def opCode = num
|
||||
}
|
||||
|
||||
object BytesToPushOntoStack extends ScriptOperationFactory[BytesToPushOntoStack] {
|
||||
/**
|
||||
* Represents that zero bytes need to be pushed onto the stack
|
||||
* this really means we need to push an empty byte vector on the stack
|
||||
*/
|
||||
lazy val zero : BytesToPushOntoStack = apply(0).get
|
||||
lazy val zero : BytesToPushOntoStack = apply(0)
|
||||
|
||||
private case class BytesToPushOntoStackImpl(num : Int) extends BytesToPushOntoStack {
|
||||
/* //see the 'Constants; section in https://en.bitcoin.it/wiki/Script
|
||||
require(num >= -1 && num <= 75, "A valid script number is between 1 and 75, the number passed in was: " + num)*/
|
||||
require(num >= 0, "BytesToPushOntoStackImpl cannot be negative")
|
||||
override def opCode = num
|
||||
}
|
||||
|
||||
override def operations : Seq[BytesToPushOntoStack] =
|
||||
(for { i <- 0 to 75 } yield BytesToPushOntoStackImpl(i)).toList
|
||||
|
||||
def fromNumber(num : Int) : Option[BytesToPushOntoStack] = operations.find(_.opCode == num)
|
||||
def fromNumber(num : Int) : BytesToPushOntoStack = {
|
||||
if (num > 75) throw new IllegalArgumentException("We cannot have a BytesToPushOntoStack for greater than 75 bytes")
|
||||
else {
|
||||
val bytesToPushOntoStackOpt = operations.find(_.opCode == num)
|
||||
bytesToPushOntoStackOpt match {
|
||||
case Some(bytesToPushOntoStack) => bytesToPushOntoStack
|
||||
case None => throw new IllegalArgumentException("We cannot have a BytesToPushOntoStack for greater than 75 bytes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def apply(num : Int) : Option[BytesToPushOntoStack] = fromNumber(num)
|
||||
def apply(num : Int) : BytesToPushOntoStack = fromNumber(num)
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ trait BitcoinScriptUtil {
|
|||
case ScriptConstant.zero | ScriptConstant.negativeZero =>
|
||||
//weird case where OP_0 pushes an empty byte vector on the stack, NOT "00" or "81"
|
||||
//so we can push the constant "00" or "81" onto the stack with a BytesToPushOntoStack pushop
|
||||
pushOp == BytesToPushOntoStack(1).get
|
||||
pushOp == BytesToPushOntoStack(1)
|
||||
case _ : ScriptToken if ( token.bytes.size == 1 && ScriptNumberOperation.fromNumber(token.toLong.toInt).isDefined) =>
|
||||
//could have used the ScriptNumberOperation to push the number onto the stack
|
||||
false
|
||||
|
|
|
@ -17,7 +17,7 @@ class RawScriptPubKeyParserTest extends FlatSpec with MustMatchers with RawScrip
|
|||
|
||||
"RawScriptPubKeyParser" must "parse a hex string into a scriptPubKey" in {
|
||||
val scriptPubKey : ScriptPubKey = read(TestUtil.rawScriptPubKey)
|
||||
scriptPubKey.asm must be (Seq(OP_DUP,OP_HASH160, BytesToPushOntoStack(20).get,
|
||||
scriptPubKey.asm must be (Seq(OP_DUP,OP_HASH160, BytesToPushOntoStack(20),
|
||||
ScriptConstant("cbc20a7664f2f69e5355aa427045bc15e7c6c772"),OP_EQUALVERIFY,OP_CHECKSIG))
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class RawScriptPubKeyParserTest extends FlatSpec with MustMatchers with RawScrip
|
|||
it must "read a raw scriptPubKey and give us the expected asm" in {
|
||||
val scriptPubKey = read(TestUtil.rawP2PKHScriptPubKey)
|
||||
val expectedAsm : Seq[ScriptToken] =
|
||||
List(OP_DUP, OP_HASH160, BytesToPushOntoStack(20).get, ScriptConstant("31a420903c05a0a7de2de40c9f02ebedbacdc172"),
|
||||
List(OP_DUP, OP_HASH160, BytesToPushOntoStack(20), ScriptConstant("31a420903c05a0a7de2de40c9f02ebedbacdc172"),
|
||||
OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
scriptPubKey.asm must be (expectedAsm)
|
||||
|
||||
|
|
|
@ -32,22 +32,22 @@ class RawScriptSignatureParserTest extends FlatSpec with MustMatchers with RawSc
|
|||
|
||||
val scriptSig = RawScriptSignatureParser.read(TestUtil.rawScriptSig)
|
||||
|
||||
scriptSig.asm must be (Seq(BytesToPushOntoStackImpl(72), ScriptConstant("3045022100ad8e961fe3c22b2647d92b078f4c0cf81b3106ea5bf8b900ab8646aa4430216f022071d4edc2b5588be20ac4c2d07edd8ed069e10b2402d3dce2d3b835ccd075f28301"), BytesToPushOntoStackImpl(65), ScriptConstant("04fa79182bbc26c708b5d9f36b8635947d4a834ea356cf612ede08395c295f962e0b1dc2557aba34188640e51a58ed547f2c89c8265cd0c04ff890d8435648746e")))
|
||||
scriptSig.asm must be (Seq(BytesToPushOntoStack(72), ScriptConstant("3045022100ad8e961fe3c22b2647d92b078f4c0cf81b3106ea5bf8b900ab8646aa4430216f022071d4edc2b5588be20ac4c2d07edd8ed069e10b2402d3dce2d3b835ccd075f28301"), BytesToPushOntoStack(65), ScriptConstant("04fa79182bbc26c708b5d9f36b8635947d4a834ea356cf612ede08395c295f962e0b1dc2557aba34188640e51a58ed547f2c89c8265cd0c04ff890d8435648746e")))
|
||||
|
||||
}
|
||||
|
||||
|
||||
it must "parse a raw scriptSig for a p2sh address with a lot of signatures" in {
|
||||
TestUtil.p2shInputScriptLargeSignature.asm must be (Seq(OP_0,
|
||||
BytesToPushOntoStack(72).get,
|
||||
BytesToPushOntoStack(72),
|
||||
ScriptConstant("3045022100a077d4fe9a81411ecb796c254d8b4e0bc73ff86a42288bc3b3ecfa1ef26c00dd02202389bf96cf38c14c3a6ccb8c688339f3fd880b724322862547a8ee3b547a9df901"),
|
||||
BytesToPushOntoStack(71).get,
|
||||
BytesToPushOntoStack(71),
|
||||
ScriptConstant("304402207c0692464998e7f3869f8501cdd25bbcd9d32b6fd34ae8aeae643b422a8dfd42022057eb16f8ca1f34e88babc9f8beb4c2521eb5c4dea41f8902a70d045f1c132a4401"),
|
||||
BytesToPushOntoStack(71).get,
|
||||
BytesToPushOntoStack(71),
|
||||
ScriptConstant("3044022024233923253c73569f4b34723a5495698bc124b099c5542a5997d13fba7d18a802203c317bddc070276c6f6c79cb3415413e608af30e4759e31b0d53eab3ca0acd4e01"),
|
||||
BytesToPushOntoStack(72).get,
|
||||
BytesToPushOntoStack(72),
|
||||
ScriptConstant("30450221009b9f0d8b945717d2fca3685093d547a3928d122b8894903ed51e2248303213bc022008b376422c9f2cd713b9d10b5b106d1c56c5893dcc01ae300253ed2234bdb63f01"),
|
||||
BytesToPushOntoStack(71).get,
|
||||
BytesToPushOntoStack(71),
|
||||
ScriptConstant("30440220257b57cb09386d82c4328461f8fe200c2f381d6b635e2a2f4ea40c8d945e9ec102201ec67d58d51a309af4d8896e9147a42944e9f9833a456f733ea5fa6954ed2fed01"),
|
||||
OP_PUSHDATA1, ScriptNumber(241),
|
||||
ScriptConstant("55210269992fb441ae56968e5b77d46a3e53b69f136444ae65a94041fc937bdb28d93321021df31471281d4478df85bfce08a10aab82601dca949a79950f8ddf7002bd915a2102174c82021492c2c6dfcbfa4187d10d38bed06afb7fdcd72c880179fddd641ea121033f96e43d72c33327b6a4631ccaa6ea07f0b106c88b9dc71c9000bb6044d5e88a210313d8748790f2a86fb524579b46ce3c68fedd58d2a738716249a9f7d5458a15c221030b632eeb079eb83648886122a04c7bf6d98ab5dfb94cf353ee3e9382a4c2fab02102fb54a7fcaa73c307cfd70f3fa66a2e4247a71858ca731396343ad30c7c4009ce57ae")
|
||||
|
@ -69,10 +69,10 @@ class RawScriptSignatureParserTest extends FlatSpec with MustMatchers with RawSc
|
|||
|
||||
val scriptSig = RawScriptSignatureParser.read(rawScriptSig)
|
||||
|
||||
val expectedAsm = List(BytesToPushOntoStackImpl(71),
|
||||
val expectedAsm = List(BytesToPushOntoStack(71),
|
||||
ScriptConstant("30440220048e15422cf62349dc586ffb8c749d40280781edd5064ff27a5910ff5cf" +
|
||||
"225a802206a82685dbc2cf195d158c29309939d5a3cd41a889db6f766f3809fff3572230501"),
|
||||
BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant("03dcfc9882c1b3ae4e03fb6cac08bdb39e284e81d70c7aa8b27612457b2774509b"))
|
||||
|
||||
scriptSig.asm.head must be (expectedAsm.head)
|
||||
|
|
|
@ -62,12 +62,12 @@ class ScriptParserTest extends FlatSpec with MustMatchers with ScriptParser with
|
|||
|
||||
it must "parse a script constant from 'Az' EQUAL" in {
|
||||
val str = "'Az' EQUAL"
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2).get, ScriptConstant("417a"), OP_EQUAL))
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2), ScriptConstant("417a"), OP_EQUAL))
|
||||
}
|
||||
|
||||
it must "parse a script number that has a leading zero" in {
|
||||
val str = "0x02 0x0100"
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2).get, ScriptConstant("0100")))
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2), ScriptConstant("0100")))
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,8 +83,8 @@ class ScriptParserTest extends FlatSpec with MustMatchers with ScriptParser with
|
|||
|
||||
it must "parse a script that has a decimal and a hexadecimal number in it " in {
|
||||
val str = "32767 0x02 0xff7f EQUAL"
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2).get, ScriptConstant("ff7f"),
|
||||
BytesToPushOntoStackImpl(2), ScriptConstant("ff7f"), OP_EQUAL))
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(2), ScriptConstant("ff7f"),
|
||||
BytesToPushOntoStack(2), ScriptConstant("ff7f"), OP_EQUAL))
|
||||
}
|
||||
it must "parse an OP_1" in {
|
||||
val str = "0x51"
|
||||
|
@ -95,21 +95,21 @@ class ScriptParserTest extends FlatSpec with MustMatchers with ScriptParser with
|
|||
val str = "0x4b 0x417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a " +
|
||||
"'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' EQUAL"
|
||||
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(75).get,
|
||||
fromString(str) must equal (List(BytesToPushOntoStack(75),
|
||||
ScriptConstant("417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a"),
|
||||
BytesToPushOntoStack(75).get,
|
||||
BytesToPushOntoStack(75),
|
||||
ScriptConstant("417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a"), OP_EQUAL))
|
||||
}
|
||||
|
||||
it must "parse an OP_IF OP_ENDIF block" in {
|
||||
val str = "1 0x01 0x80 IF 0 ENDIF"
|
||||
fromString(str) must be (List(OP_1, BytesToPushOntoStackImpl(1), ScriptConstant("80"), OP_IF, OP_0, OP_ENDIF))
|
||||
fromString(str) must be (List(OP_1, BytesToPushOntoStack(1), ScriptConstant("80"), OP_IF, OP_0, OP_ENDIF))
|
||||
}
|
||||
|
||||
|
||||
it must "parse an OP_PUSHDATA1 correctly" in {
|
||||
val str = "'abcdefghijklmnopqrstuvwxyz' HASH160 0x4c 0x14 0xc286a1af0947f58d1ad787385b1c2c4a976f9e71 EQUAL"
|
||||
val expectedScript = List(BytesToPushOntoStack(26).get, ScriptConstant("6162636465666768696a6b6c6d6e6f707172737475767778797a"),OP_HASH160,
|
||||
val expectedScript = List(BytesToPushOntoStack(26), ScriptConstant("6162636465666768696a6b6c6d6e6f707172737475767778797a"),OP_HASH160,
|
||||
OP_PUSHDATA1, ScriptNumber(20), ScriptConstant("c286a1af0947f58d1ad787385b1c2c4a976f9e71"), OP_EQUAL)
|
||||
fromString(str) must be (expectedScript)
|
||||
}
|
||||
|
@ -166,10 +166,10 @@ class ScriptParserTest extends FlatSpec with MustMatchers with ScriptParser with
|
|||
//from b30d3148927f620f5b1228ba941c211fdabdae75d0ba0b688a58accbf018f3cc
|
||||
val rawScriptSig = "4730440220048e15422cf62349dc586ffb8c749d40280781edd5064ff27a5910ff5cf225a802206a82685dbc2cf195d158c29309939d5a3cd41a889db6f766f3809fff35722305012103dcfc9882c1b3ae4e03fb6cac08bdb39e284e81d70c7aa8b27612457b2774509b"
|
||||
|
||||
val expectedAsm = List(BytesToPushOntoStackImpl(71),
|
||||
val expectedAsm = List(BytesToPushOntoStack(71),
|
||||
ScriptConstant("30440220048e15422cf62349dc586ffb8c749d40280781edd5064ff27a5910ff5cf" +
|
||||
"225a802206a82685dbc2cf195d158c29309939d5a3cd41a889db6f766f3809fff3572230501"),
|
||||
BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant("03dcfc9882c1b3ae4e03fb6cac08bdb39e284e81d70c7aa8b27612457b2774509b"))
|
||||
|
||||
val scriptTokens : List[ScriptToken] = ScriptParser.fromHex(rawScriptSig)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.marshallers.transaction
|
||||
|
||||
|
||||
import org.bitcoins.protocol.transaction.{TransactionConstants, TransactionInput}
|
||||
import org.bitcoins.script.constant.{OP_1, BytesToPushOntoStackImpl, OP_0}
|
||||
import org.bitcoins.script.crypto.OP_CHECKMULTISIG
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
package org.bitcoins.marshallers.transaction
|
||||
|
||||
|
||||
|
@ -24,8 +25,8 @@ class RawTransactionOutputParserTest extends FlatSpec with MustMatchers with Raw
|
|||
val secondOutput = txOutput(1)
|
||||
firstOutput.value must be (CurrencyUnits.toSatoshis(Bitcoins(0.0002)))
|
||||
secondOutput.value must be (CurrencyUnits.toSatoshis(Bitcoins(0.02981145)))
|
||||
firstOutput.scriptPubKey.asm must be (Seq(OP_HASH160, BytesToPushOntoStackImpl(20),ScriptConstant("eda8ae08b5c9f973f49543e90a7c292367b3337c"), OP_EQUAL))
|
||||
secondOutput.scriptPubKey.asm must be (Seq(OP_HASH160,BytesToPushOntoStackImpl(20), ScriptConstant("be2319b9060429692ebeffaa3be38497dc5380c8"), OP_EQUAL))
|
||||
firstOutput.scriptPubKey.asm must be (Seq(OP_HASH160, BytesToPushOntoStack(20),ScriptConstant("eda8ae08b5c9f973f49543e90a7c292367b3337c"), OP_EQUAL))
|
||||
secondOutput.scriptPubKey.asm must be (Seq(OP_HASH160,BytesToPushOntoStack(20), ScriptConstant("be2319b9060429692ebeffaa3be38497dc5380c8"), OP_EQUAL))
|
||||
}
|
||||
|
||||
it must "seralialize a transaction output" in {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.protocol.script
|
||||
|
||||
|
||||
import org.bitcoins.crypto.{ECFactory, EmptyDigitalSignature}
|
||||
import org.bitcoins.script.constant.{BytesToPushOntoStackImpl, OP_0, ScriptConstant}
|
||||
import org.bitcoins.util.TransactionTestUtil
|
||||
|
@ -17,7 +18,7 @@ class MultiSignatureScriptSignatureTest extends FlatSpec with MustMatchers {
|
|||
}
|
||||
|
||||
it must "give us the empty signature back when it is encoded as an OP_0 (this pushes an empty signature onto the stack)" in {
|
||||
val multiSigScriptSignature = ScriptSignature.fromAsm(List(OP_0, BytesToPushOntoStackImpl(71),
|
||||
val multiSigScriptSignature = ScriptSignature.fromAsm(List(OP_0, BytesToPushOntoStack(71),
|
||||
ScriptConstant("30440220b119d67d389315308d1745f734a51ff3ec72e06081e84e236fdf9dc2f5d2a64802204b04e3bc38674c4422ea317231d642b56dc09d214a1ecbbf16ecca01ed996e2201"), OP_0))
|
||||
multiSigScriptSignature.signatures must be (Seq(
|
||||
ECFactory.digitalSignature("30440220b119d67d389315308d1745f734a51ff3ec72e06081e84e236fdf9dc2f5d2a64802204b04e3bc38674c4422ea317231d642b56dc09d214a1ecbbf16ecca01ed996e2201"),
|
||||
|
|
|
@ -32,8 +32,8 @@ class P2SHScriptSignatureTest extends FlatSpec with MustMatchers {
|
|||
}
|
||||
|
||||
p2shScriptSig.scriptSignatureNoRedeemScript.asm must be (Seq(
|
||||
OP_0, BytesToPushOntoStackImpl(71), ScriptConstant("304402207d764cb90c9fd84b74d33a47cf3a0ffead9ded98333776becd6acd32c4426dac02203905a0d064e7f53d07793e86136571b6e4f700c1cfb888174e84d78638335b8101"),
|
||||
BytesToPushOntoStackImpl(72),
|
||||
OP_0, BytesToPushOntoStack(71), ScriptConstant("304402207d764cb90c9fd84b74d33a47cf3a0ffead9ded98333776becd6acd32c4426dac02203905a0d064e7f53d07793e86136571b6e4f700c1cfb888174e84d78638335b8101"),
|
||||
BytesToPushOntoStack(72),
|
||||
ScriptConstant("3045022100906aaca39f022acd8b7a38fd2f92aca9e9f35cfeaee69a6f13e1d083ae18222602204c9ed96fc6c4de56fd85c679fc59c16ee1ccc80c42563b86174e1a506fc007c801")
|
||||
))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bitcoins.protocol.script
|
||||
|
||||
|
||||
import org.bitcoins.crypto.ECFactory
|
||||
import org.bitcoins.script.bitwise.OP_EQUALVERIFY
|
||||
import org.bitcoins.script.constant.{BytesToPushOntoStackImpl, ScriptConstant, ScriptToken}
|
||||
|
@ -16,7 +15,7 @@ class ScriptPubKeyTest extends FlatSpec with MustMatchers {
|
|||
|
||||
|
||||
val expectedAsm : Seq[ScriptToken] =
|
||||
List(OP_DUP, OP_HASH160, BytesToPushOntoStackImpl(20), ScriptConstant("31a420903c05a0a7de2de40c9f02ebedbacdc172"), OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
List(OP_DUP, OP_HASH160, BytesToPushOntoStack(20), ScriptConstant("31a420903c05a0a7de2de40c9f02ebedbacdc172"), OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
//from b30d3148927f620f5b1228ba941c211fdabdae75d0ba0b688a58accbf018f3cc
|
||||
val rawScriptPubKey = TestUtil.rawP2PKHScriptPubKey
|
||||
val scriptPubKey = ScriptPubKey(rawScriptPubKey)
|
||||
|
|
|
@ -41,13 +41,13 @@ class ScriptOperationFactoryTest extends FlatSpec with MustMatchers {
|
|||
it must "find a byte to push onto stack from its byte representation" in {
|
||||
val result = ScriptOperation(2.toByte)
|
||||
result.isDefined must be (true)
|
||||
result.get must be (BytesToPushOntoStackImpl(2))
|
||||
result.get must be (BytesToPushOntoStack(2))
|
||||
}
|
||||
|
||||
it must "find a script number from its hex representation" in {
|
||||
val result = ScriptOperation("02")
|
||||
result.isDefined must be (true)
|
||||
result.get must be (BytesToPushOntoStackImpl(2))
|
||||
result.get must be (BytesToPushOntoStack(2))
|
||||
}
|
||||
|
||||
it must "find undefined op codes"in {
|
||||
|
|
|
@ -9,27 +9,27 @@ class BytesToPushOntoStackFactoryTest extends FlatSpec with MustMatchers {
|
|||
|
||||
|
||||
"ScriptNumberFactory" must "represent the number 1" in {
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStackImpl(1)) must be (true)
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStackImpl(75)) must be (true)
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStack(1)) must be (true)
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStack(75)) must be (true)
|
||||
}
|
||||
|
||||
it must "find the number two" in {
|
||||
val result = BytesToPushOntoStack(2)
|
||||
result.isDefined must be (true)
|
||||
result.get.opCode must be (2)
|
||||
result.get must be (BytesToPushOntoStackImpl(2))
|
||||
|
||||
result.opCode must be (2)
|
||||
result must be (BytesToPushOntoStack(2))
|
||||
}
|
||||
|
||||
it must "find the number two from its byte representation" in {
|
||||
val result = BytesToPushOntoStack(0x02)
|
||||
result.isDefined must be (true)
|
||||
result.get.opCode must be (2)
|
||||
result.get must be (BytesToPushOntoStackImpl(2))
|
||||
|
||||
result.opCode must be (2)
|
||||
result must be (BytesToPushOntoStack(2))
|
||||
}
|
||||
|
||||
it must "not allow creation of the script number -2" in {
|
||||
intercept[IllegalArgumentException] {
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStackImpl(-2)) must be (false)
|
||||
BytesToPushOntoStack.operations.exists(_ == BytesToPushOntoStack(-2)) must be (false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class ConstantInterpreterTest extends FlatSpec with MustMatchers with ConstantIn
|
|||
|
||||
it must "push a constant 2 bytes onto the stack" in {
|
||||
val stack = List()
|
||||
val script = List(BytesToPushOntoStack(2).get, ScriptNumber.one, OP_0)
|
||||
val script = List(BytesToPushOntoStack(2), ScriptNumber.one, OP_0)
|
||||
val program = ScriptProgram(TestUtil.testProgram, stack,script)
|
||||
val newProgram = pushScriptNumberBytesToStack(program)
|
||||
newProgram.script.isEmpty must be (true)
|
||||
|
@ -68,20 +68,20 @@ class ConstantInterpreterTest extends FlatSpec with MustMatchers with ConstantIn
|
|||
|
||||
it must "push 0 bytes onto the stack which is OP_0" in {
|
||||
val stack = List()
|
||||
val script = List(OP_PUSHDATA1,BytesToPushOntoStack(0).get)
|
||||
val script = List(OP_PUSHDATA1,BytesToPushOntoStack(0))
|
||||
val program = ScriptProgram(ScriptProgram(TestUtil.testProgram, stack,script),Seq[ScriptFlag]())
|
||||
val newProgram = opPushData1(program)
|
||||
newProgram.stackTopIsFalse must be (true)
|
||||
newProgram.stack must be (List(ScriptNumber.zero))
|
||||
|
||||
val stack1 = List()
|
||||
val script1 = List(OP_PUSHDATA2,BytesToPushOntoStack(0).get)
|
||||
val script1 = List(OP_PUSHDATA2,BytesToPushOntoStack(0))
|
||||
val program1 = ScriptProgram(ScriptProgram(TestUtil.testProgram, stack1,script1),Seq[ScriptFlag]())
|
||||
val newProgram1 = opPushData2(program1)
|
||||
newProgram1.stack must be (List(ScriptNumber.zero))
|
||||
|
||||
val stack2 = List()
|
||||
val script2 = List(OP_PUSHDATA4,BytesToPushOntoStack(0).get)
|
||||
val script2 = List(OP_PUSHDATA4,BytesToPushOntoStack(0))
|
||||
val program2 = ScriptProgram(ScriptProgram(TestUtil.testProgram, stack2,script2),Seq[ScriptFlag]())
|
||||
val newProgram2 = opPushData4(program2)
|
||||
newProgram2.stack must be (List(ScriptNumber.zero))
|
||||
|
@ -90,7 +90,7 @@ class ConstantInterpreterTest extends FlatSpec with MustMatchers with ConstantIn
|
|||
|
||||
it must "mark a program as invalid if we have do not have enough bytes to be pushed onto the stack by the push operation" in {
|
||||
val stack = List()
|
||||
val script = List(OP_PUSHDATA1,BytesToPushOntoStack(1).get)
|
||||
val script = List(OP_PUSHDATA1,BytesToPushOntoStack(1))
|
||||
val program = ScriptProgram(ScriptProgram(TestUtil.testProgramExecutionInProgress, stack,script),Seq[ScriptFlag]())
|
||||
|
||||
val newProgram = ScriptProgramTestUtil.toExecutedScriptProgram(opPushData1(program))
|
||||
|
|
|
@ -98,7 +98,7 @@ class BitcoinScriptUtilTest extends FlatSpec with MustMatchers {
|
|||
}
|
||||
|
||||
it must "determine that the script is not push only if it contains an script number operation" in {
|
||||
BitcoinScriptUtil.isMinimalPush(BytesToPushOntoStack(1).get,OP_1) must be (false)
|
||||
BitcoinScriptUtil.isMinimalPush(BytesToPushOntoStack(1),OP_1) must be (false)
|
||||
}
|
||||
|
||||
it must "determine that a script is push only if it only contains pushing an empty script constant" in {
|
||||
|
|
|
@ -29,14 +29,14 @@ object TestUtil {
|
|||
val p2pkhInputScriptNotParsedAsm =
|
||||
"3044022016ffdbb7c57634903c5e018fcfc48d59f4e37dc4bc3bbc9ba4e6ee39150bca030220119c2241a931819bc1a75d3596e4029d803d1cd6de123bf8a1a1a2c3665e1fac01" +
|
||||
" 02af7dad03e682fcd0427b5c24140c220ac9d8abe286c15f8cf5bf77eed19c3652"
|
||||
val p2pkhInputScriptAsm : List[ScriptToken] = List(BytesToPushOntoStackImpl(71),
|
||||
val p2pkhInputScriptAsm : List[ScriptToken] = List(BytesToPushOntoStack(71),
|
||||
ScriptConstant("3044022016ffdbb7c57634903c5e018fcfc48d59f4e37dc4bc3bbc9ba4e6ee39150bca030220119c2241a931819bc1a75d3596e4029d803d1cd6de123bf8a1a1a2c3665e1fac01"),
|
||||
BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant("02af7dad03e682fcd0427b5c24140c220ac9d8abe286c15f8cf5bf77eed19c3652"))
|
||||
|
||||
val p2pkhOutputScript = "76a914e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b88ac"
|
||||
val p2pkhOutputScriptNotParsedAsm = "OP_DUP OP_HASH160 e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b OP_EQUALVERIFY OP_CHECKSIG"
|
||||
val p2pkhOutputScriptAsm = List(OP_DUP,OP_HASH160,BytesToPushOntoStackImpl(20), ScriptConstant("e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b"),OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
val p2pkhOutputScriptAsm = List(OP_DUP,OP_HASH160,BytesToPushOntoStack(20), ScriptConstant("e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b"),OP_EQUALVERIFY, OP_CHECKSIG)
|
||||
|
||||
|
||||
//tx id for p2sh inputs/outputs cad1082e674a7bd3bc9ab1bc7804ba8a57523607c876b8eb2cbe645f2b1803d6
|
||||
|
@ -47,16 +47,16 @@ object TestUtil {
|
|||
val p2shInputScript = ScriptSignature(rawP2shInputScript)
|
||||
val p2shInputScriptAsm = List(
|
||||
OP_0,
|
||||
BytesToPushOntoStackImpl(71),
|
||||
BytesToPushOntoStack(71),
|
||||
ScriptConstant("304402207df6dd8dad22d49c3c83d8031733c32a53719278eb7985d3b35b375d776f84f102207054f9209a1e87d55feafc90aa04c33008e5bae9191da22aeaa16efde96f41f001"),
|
||||
BytesToPushOntoStackImpl(37),
|
||||
BytesToPushOntoStack(37),
|
||||
ScriptConstant("512102b022902a0fdd71e831c37e4136c2754a59887be0618fb75336d7ab67e2982ff551ae")
|
||||
)
|
||||
|
||||
|
||||
val p2shOutputScript = "a914eda8ae08b5c9f973f49543e90a7c292367b3337c87"
|
||||
val p2shOutputScriptNotParsedAsm = "OP_HASH160 eda8ae08b5c9f973f49543e90a7c292367b3337c OP_EQUAL"
|
||||
val p2shOutputScriptAsm = List(OP_HASH160, BytesToPushOntoStackImpl(20), ScriptConstant("eda8ae08b5c9f973f49543e90a7c292367b3337c"), OP_EQUAL)
|
||||
val p2shOutputScriptAsm = List(OP_HASH160, BytesToPushOntoStack(20), ScriptConstant("eda8ae08b5c9f973f49543e90a7c292367b3337c"), OP_EQUAL)
|
||||
|
||||
//https://btc.blockr.io/api/v1/tx/raw/791fe035d312dcf9196b48649a5c9a027198f623c0a5f5bd4cc311b8864dd0cf
|
||||
val rawP2shInputScriptSigHashSingle = "00483045022100dfcfafcea73d83e1c54d444a19fb30d17317f922c19e2ff92dcda65ad09cba24022001e7a805c5672c49b222c5f2f1e67bb01f87215fb69df184e7c16f66c1f87c290347304402204a657ab8358a2edb8fd5ed8a45f846989a43655d2e8f80566b385b8f5a70dab402207362f870ce40f942437d43b6b99343419b14fb18fa69bee801d696a39b3410b8034c695221023927b5cd7facefa7b85d02f73d1e1632b3aaf8dd15d4f9f359e37e39f05611962103d2c0e82979b8aba4591fe39cffbf255b3b9c67b3d24f94de79c5013420c67b802103ec010970aae2e3d75eef0b44eaa31d7a0d13392513cd0614ff1c136b3b1020df53ae"
|
||||
|
@ -70,13 +70,13 @@ object TestUtil {
|
|||
val rawP2SH2Of2Tx = "0100000001d69b8ece3059c429a83707cde2db9d8a76897b5d418c4a784a5f52d40063518f00000000da0047304402207d764cb90c9fd84b74d33a47cf3a0ffead9ded98333776becd6acd32c4426dac02203905a0d064e7f53d07793e86136571b6e4f700c1cfb888174e84d78638335b8101483045022100906aaca39f022acd8b7a38fd2f92aca9e9f35cfeaee69a6f13e1d083ae18222602204c9ed96fc6c4de56fd85c679fc59c16ee1ccc80c42563b86174e1a506fc007c8014752210369d26ebd086523384a0f89f293d4c327a65fa73332d8efd1097cb35231295b832102480863e5c4a4e9763f5380c44fcfe6a3b7787397076cf9ea1049303a9d34f72152ae0000000001b7e4ca00000000001976a914c59529a317559cfa818ddd625b7b980435b333dc88acb6917056"
|
||||
def p2shInputScript2Of2 = ScriptSignature(rawP2shInputScript2Of2)
|
||||
def p2sh2Of2Tx = Transaction(rawP2SH2Of2Tx)
|
||||
def p2shInputScript2Of2Asm = Seq(OP_0, BytesToPushOntoStackImpl(71),
|
||||
def p2shInputScript2Of2Asm = Seq(OP_0, BytesToPushOntoStack(71),
|
||||
ScriptConstant("304402207d764cb90c9fd84b74d33a47cf3a0ffead9ded98333776becd6acd32c4426dac02203905a0d064e7f53d07793e86136571b6e4f700c1cfb888174e84d78638335b8101"),
|
||||
BytesToPushOntoStackImpl(72),
|
||||
BytesToPushOntoStack(72),
|
||||
ScriptConstant("3045022100906aaca39f022acd8b7a38fd2f92aca9e9f35cfeaee69a6f13e1d083ae18222602204c9ed96fc6c4de56fd85c679fc59c16ee1ccc80c42563b86174e1a506fc007c801"),
|
||||
BytesToPushOntoStackImpl(71), OP_2, BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(71), OP_2, BytesToPushOntoStack(33),
|
||||
ScriptConstant("0369d26ebd086523384a0f89f293d4c327a65fa73332d8efd1097cb35231295b83"),
|
||||
BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant("02480863e5c4a4e9763f5380c44fcfe6a3b7787397076cf9ea1049303a9d34f721"), OP_2, OP_CHECKMULTISIG)
|
||||
//https://tbtc.blockr.io/api/v1/tx/raw/8f516300d4525f4a784a8c415d7b89768a9ddbe2cd0737a829c45930ce8e9bd6
|
||||
def rawP2SH2Of2CreditingTx = "0100000001fef43d6ed62f34bd1502ae0569c0c125cb484d183f887a2857ec112e548b5ba8000000006a473044022010a8b76add9224782f2ac741e32b0467c523d27632b594ae679da991975b882d022019138d13753bc7713a72c8a32f9cec8fee8c9475d6b2e386dc31e70936099c93012103f62a2ce04da197ba3efa3bcd9ae0a4021227d75f854c22bdf49c65107c3e1e7fffffffff01c80bcb000000000017a9148bee4cf71fbefe568b173dc69ec951ea3f7a05278700000000"
|
||||
|
@ -165,9 +165,9 @@ object TestUtil {
|
|||
val rawScriptSigNotStrictDerEncoded = "173014020002107777777777777777777777777777777701"
|
||||
def scriptSigNotStrictDerEncoded = ScriptSignature(rawScriptSigNotStrictDerEncoded)
|
||||
|
||||
val p2pkhScriptSigNotStrictDerEncoded = ScriptSignature.fromAsm(List(BytesToPushOntoStackImpl(71),
|
||||
val p2pkhScriptSigNotStrictDerEncoded = ScriptSignature.fromAsm(List(BytesToPushOntoStack(71),
|
||||
ScriptConstant("173014020002107777777777777777777777777777777701"),
|
||||
BytesToPushOntoStackImpl(33),
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant("02af7dad03e682fcd0427b5c24140c220ac9d8abe286c15f8cf5bf77eed19c3652")))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue