mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-25 07:17:32 +01:00
factories deprecated: bitwiseOp, controlOp, cryptoOp, reservedOp, spliceOp
This commit is contained in:
parent
19f552dd15
commit
93f5eee1b7
11 changed files with 59 additions and 34 deletions
|
@ -2,13 +2,13 @@ package org.scalacoin.script
|
|||
|
||||
//import org.scalacoin.script.arithmetic.{ArithmeticOperations}
|
||||
import org.scalacoin.script.arithmetic.ArithmeticOperation
|
||||
import org.scalacoin.script.bitwise.BitwiseOperationsFactory
|
||||
import org.scalacoin.script.bitwise.BitwiseOperation
|
||||
import org.scalacoin.script.constant._
|
||||
import org.scalacoin.script.control.ControlOperationsFactory
|
||||
import org.scalacoin.script.crypto.CryptoOperationFactory
|
||||
import org.scalacoin.script.control.ControlOperations
|
||||
import org.scalacoin.script.crypto.CryptoOperation
|
||||
import org.scalacoin.script.locktime.LocktimeOperation
|
||||
import org.scalacoin.script.reserved.ReservedOperationFactory
|
||||
import org.scalacoin.script.splice.SpliceOperationsFactory
|
||||
import org.scalacoin.script.reserved.ReservedOperation
|
||||
import org.scalacoin.script.splice.SpliceOperation
|
||||
import org.scalacoin.script.stack.StackOperation
|
||||
import org.scalacoin.util.{BitcoinSUtil, BitcoinSLogger}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -81,8 +81,8 @@ trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
|
|||
object ScriptOperation extends ScriptOperationFactory[ScriptOperation] {
|
||||
|
||||
lazy val operations = ScriptNumberOperation.operations ++ Seq(OP_FALSE,OP_PUSHDATA1, OP_PUSHDATA2,OP_PUSHDATA4,OP_TRUE) ++ StackOperation.operations ++ LocktimeOperation.operations ++
|
||||
CryptoOperationFactory.operations ++ ControlOperationsFactory.operations ++ BitwiseOperationsFactory.operations ++
|
||||
ArithmeticOperation.operations ++ BytesToPushOntoStack.operations ++ SpliceOperationsFactory.operations ++
|
||||
ReservedOperationFactory.operations
|
||||
CryptoOperation.operations ++ ControlOperations.operations ++ BitwiseOperation.operations ++
|
||||
ArithmeticOperation.operations ++ BytesToPushOntoStack.operations ++ SpliceOperation.operations ++
|
||||
ReservedOperation.operations
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.scalacoin.script.bitwise
|
||||
|
||||
import org.scalacoin.script.ScriptOperationFactory
|
||||
import org.scalacoin.script.constant.ScriptOperation
|
||||
|
||||
/**
|
||||
|
@ -49,3 +50,6 @@ case object OP_XOR extends BitwiseOperation {
|
|||
override def opCode = 134
|
||||
}
|
||||
|
||||
object BitwiseOperation extends ScriptOperationFactory[BitwiseOperation] {
|
||||
override def operations = Seq(OP_EQUAL, OP_EQUALVERIFY, OP_INVERT, OP_AND, OP_OR, OP_XOR)
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.scalacoin.script.control
|
||||
|
||||
import org.scalacoin.script.ScriptOperationFactory
|
||||
import org.scalacoin.script.constant.ScriptOperation
|
||||
|
||||
/**
|
||||
|
@ -57,4 +58,8 @@ case object OP_VERIFY extends ControlOperations {
|
|||
*/
|
||||
case object OP_RETURN extends ControlOperations {
|
||||
override def opCode = 106
|
||||
}
|
||||
|
||||
object ControlOperations extends ScriptOperationFactory[ControlOperations] {
|
||||
override def operations = Seq(OP_ELSE, OP_ENDIF, OP_IF, OP_NOTIF, OP_RETURN, OP_VERIFY)
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.scalacoin.script.crypto
|
||||
|
||||
import org.scalacoin.script.ScriptOperationFactory
|
||||
import org.scalacoin.script.constant.ScriptOperation
|
||||
|
||||
/**
|
||||
|
@ -92,4 +93,9 @@ case object OP_CHECKMULTISIG extends CryptoSignatureEvaluation {
|
|||
*/
|
||||
case object OP_CHECKMULTISIGVERIFY extends CryptoSignatureEvaluation {
|
||||
override def opCode = 175
|
||||
}
|
||||
|
||||
object CryptoOperation extends ScriptOperationFactory[CryptoOperation] {
|
||||
override def operations = Seq(OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY, OP_CHECKSIG, OP_CHECKSIGVERIFY,
|
||||
OP_CODESEPARATOR, OP_HASH160, OP_HASH256, OP_RIPEMD160, OP_SHA1, OP_SHA256)
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.scalacoin.script.reserved
|
||||
|
||||
import org.scalacoin.script.ScriptOperationFactory
|
||||
import org.scalacoin.script.constant.ScriptOperation
|
||||
|
||||
/**
|
||||
|
@ -96,4 +97,8 @@ case object OP_NOP10 extends NOP {
|
|||
|
||||
case class UndefinedOP_NOP(opCode : Int) extends ReservedOperation
|
||||
|
||||
|
||||
object ReservedOperation extends ScriptOperationFactory[ReservedOperation] {
|
||||
lazy val undefinedOpCodes = for {i <- 0xba to 0xff} yield UndefinedOP_NOP(i)
|
||||
def operations = Seq(OP_RESERVED,OP_VER,OP_VERIF,OP_VERNOTIF,OP_RESERVED, OP_RESERVED1, OP_RESERVED2,
|
||||
OP_NOP, OP_NOP1,OP_NOP3,OP_NOP4,OP_NOP5,OP_NOP6,OP_NOP7,OP_NOP8, OP_NOP9, OP_NOP10) ++ undefinedOpCodes
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.scalacoin.script.splice
|
||||
|
||||
import org.scalacoin.script.ScriptOperationFactory
|
||||
import org.scalacoin.script.constant.ScriptOperation
|
||||
|
||||
/**
|
||||
|
@ -26,4 +27,8 @@ case object OP_RIGHT extends SpliceOperation {
|
|||
|
||||
case object OP_SIZE extends SpliceOperation {
|
||||
override def opCode = 130
|
||||
}
|
||||
|
||||
object SpliceOperation extends ScriptOperationFactory[SpliceOperation] {
|
||||
def operations = Seq(OP_CAT, OP_LEFT, OP_RIGHT, OP_SIZE, OP_SUBSTR)
|
||||
}
|
|
@ -5,11 +5,11 @@ import org.scalatest.{FlatSpec, MustMatchers}
|
|||
/**
|
||||
* Created by chris on 1/8/16.
|
||||
*/
|
||||
class BitwiseOperationsFactoryTest extends FlatSpec with MustMatchers with BitwiseOperationsFactory {
|
||||
class BitwiseOperationsFactoryTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"BitwiseOperationsFactory" must "match strings with bitwise operations" in {
|
||||
fromString("OP_EQUAL") must be (Some(OP_EQUAL))
|
||||
fromString("OP_EQUALVERIFY") must be (Some(OP_EQUALVERIFY))
|
||||
fromString("RANDOM") must be (None)
|
||||
BitwiseOperation.fromString("OP_EQUAL") must be (Some(OP_EQUAL))
|
||||
BitwiseOperation.fromString("OP_EQUALVERIFY") must be (Some(OP_EQUALVERIFY))
|
||||
BitwiseOperation.fromString("RANDOM") must be (None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ import org.scalatest.{MustMatchers, FlatSpec}
|
|||
/**
|
||||
* Created by chris on 1/8/16.
|
||||
*/
|
||||
class ControlOperationsFactoryTest extends FlatSpec with MustMatchers with ControlOperationsFactory {
|
||||
class ControlOperationsFactoryTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"ControlOperationsFactory" must "match a string with a control operation" in {
|
||||
fromString("OP_ELSE") must be (Some(OP_ELSE))
|
||||
fromString("OP_ENDIF") must be (Some(OP_ENDIF))
|
||||
fromString("OP_IF") must be (Some(OP_IF))
|
||||
fromString("OP_NOTIF") must be (Some(OP_NOTIF))
|
||||
fromString("OP_RETURN") must be (Some(OP_RETURN))
|
||||
fromString("OP_VERIFY") must be (Some(OP_VERIFY))
|
||||
fromString("RANDOM") must be (None)
|
||||
ControlOperations.fromString("OP_ELSE") must be (Some(OP_ELSE))
|
||||
ControlOperations.fromString("OP_ENDIF") must be (Some(OP_ENDIF))
|
||||
ControlOperations.fromString("OP_IF") must be (Some(OP_IF))
|
||||
ControlOperations.fromString("OP_NOTIF") must be (Some(OP_NOTIF))
|
||||
ControlOperations.fromString("OP_RETURN") must be (Some(OP_RETURN))
|
||||
ControlOperations.fromString("OP_VERIFY") must be (Some(OP_VERIFY))
|
||||
ControlOperations.fromString("RANDOM") must be (None)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import org.scalatest.{MustMatchers, FlatSpec}
|
|||
/**
|
||||
* Created by chris on 1/8/16.
|
||||
*/
|
||||
class CryptoOperationsFactoryTest extends FlatSpec with MustMatchers with CryptoOperationFactory {
|
||||
class CryptoOperationsFactoryTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"CryptoOperationsFactory" must "match strings with crypto operations" in {
|
||||
fromString("OP_CHECKSIG") must be (Some(OP_CHECKSIG))
|
||||
fromString("OP_HASH160") must be (Some(OP_HASH160))
|
||||
fromString("OP_SHA256") must be (Some(OP_SHA256))
|
||||
fromString("RANDOM") must be (None)
|
||||
CryptoOperation.fromString("OP_CHECKSIG") must be (Some(OP_CHECKSIG))
|
||||
CryptoOperation.fromString("OP_HASH160") must be (Some(OP_HASH160))
|
||||
CryptoOperation.fromString("OP_SHA256") must be (Some(OP_SHA256))
|
||||
CryptoOperation.fromString("RANDOM") must be (None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ import org.scalatest.{FlatSpec, MustMatchers}
|
|||
class ReservedOperationsFactoryTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"ReservedOperationsFactory" must "instantiate reserved operations" in {
|
||||
ReservedOperationFactory.fromHex("50") must be (Some(OP_RESERVED))
|
||||
ReservedOperationFactory.fromHex("62") must be (Some(OP_VER))
|
||||
ReservedOperation("50") must be (Some(OP_RESERVED))
|
||||
ReservedOperation("62") must be (Some(OP_VER))
|
||||
}
|
||||
|
||||
it must "find OP_NOP1 from its hex value" in {
|
||||
ReservedOperationFactory.fromHex("b0") must be (Some(OP_NOP1))
|
||||
ReservedOperation("b0") must be (Some(OP_NOP1))
|
||||
}
|
||||
it must "find an undefined operation from its hex value" in {
|
||||
ReservedOperationFactory.fromHex("ba").isDefined must be (true)
|
||||
ReservedOperation("ba").isDefined must be (true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ import org.scalatest.{MustMatchers, FlatSpec}
|
|||
class SpliceOperationFactoryTest extends FlatSpec with MustMatchers {
|
||||
|
||||
"SpliceOperationFactory" must "instantiate the splice operations from hex" in {
|
||||
SpliceOperationsFactory.fromHex("7e") must be (Some(OP_CAT))
|
||||
SpliceOperationsFactory.fromHex("7f") must be (Some(OP_SUBSTR))
|
||||
SpliceOperation("7e") must be (Some(OP_CAT))
|
||||
SpliceOperation("7f") must be (Some(OP_SUBSTR))
|
||||
}
|
||||
|
||||
it must "instantiate splice operations from their byte values" in {
|
||||
SpliceOperationsFactory.fromByte(126.toByte) must be (Some(OP_CAT))
|
||||
SpliceOperationsFactory.fromByte(127.toByte) must be (Some(OP_SUBSTR))
|
||||
SpliceOperation(126.toByte) must be (Some(OP_CAT))
|
||||
SpliceOperation(127.toByte) must be (Some(OP_SUBSTR))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue