mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
adding stack operations
This commit is contained in:
parent
a0f4bb4365
commit
5137d193ab
3 changed files with 229 additions and 0 deletions
142
src/main/scala/org/scalacoin/script/stack/StackOperations.scala
Normal file
142
src/main/scala/org/scalacoin/script/stack/StackOperations.scala
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
package org.scalacoin.script.stack
|
||||||
|
|
||||||
|
import org.scalacoin.script.ScriptOperation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by chris on 1/6/16.
|
||||||
|
*/
|
||||||
|
sealed trait StackOperation extends ScriptOperation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the input onto the top of the alt stack. Removes it from the main stack.
|
||||||
|
*/
|
||||||
|
case object OP_TOALTSTACK extends StackOperation {
|
||||||
|
override def opCode = 107
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the input onto the top of the main stack. Removes it from the alt stack.
|
||||||
|
*/
|
||||||
|
case object OP_FROMALTSTACK extends StackOperation {
|
||||||
|
override def opCode = 108
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the top stack value is not 0, duplicate it.
|
||||||
|
*/
|
||||||
|
case object OP_IFDUP extends StackOperation {
|
||||||
|
override def opCode = 115
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the number of stack items onto the stack.
|
||||||
|
*/
|
||||||
|
case object OP_DEPTH extends StackOperation {
|
||||||
|
override def opCode = 116
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the top stack item
|
||||||
|
*/
|
||||||
|
case object OP_DROP extends StackOperation {
|
||||||
|
override def opCode = 117
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates the top stack item.
|
||||||
|
*/
|
||||||
|
case object OP_DUP extends StackOperation {
|
||||||
|
override def opCode = 118
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the second-to-top stack item.
|
||||||
|
*/
|
||||||
|
case object OP_NIP extends StackOperation {
|
||||||
|
override def opCode = 119
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the second-to-top stack item to the top.
|
||||||
|
*/
|
||||||
|
case object OP_OVER extends StackOperation {
|
||||||
|
override def opCode = 120
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item n back in the stack is copied to the top.
|
||||||
|
*/
|
||||||
|
case object OP_PICK extends StackOperation {
|
||||||
|
override def opCode = 121
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item n back in the stack is moved to the top.
|
||||||
|
*/
|
||||||
|
case object OP_ROLL extends StackOperation {
|
||||||
|
override def opCode = 122
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The top three items on the stack are rotated to the left.
|
||||||
|
*/
|
||||||
|
case object OP_ROT extends StackOperation {
|
||||||
|
override def opCode = 123
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The top two items on the stack are swapped.
|
||||||
|
*/
|
||||||
|
case object OP_SWAP extends StackOperation {
|
||||||
|
override def opCode = 124
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item at the top of the stack is copied and inserted before the second-to-top item.
|
||||||
|
*/
|
||||||
|
case object OP_TUCK extends StackOperation {
|
||||||
|
override def opCode = 125
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the top two stack items.
|
||||||
|
*/
|
||||||
|
case object OP_2DROP extends StackOperation {
|
||||||
|
override def opCode = 109
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates the top two stack items
|
||||||
|
*/
|
||||||
|
case object OP_2DUP extends StackOperation {
|
||||||
|
override def opCode = 110
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates the top 3 stack items
|
||||||
|
*/
|
||||||
|
case object OP_3DUP extends StackOperation {
|
||||||
|
override def opCode = 111
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the pair of items two spaces back in the stack to the front.
|
||||||
|
*/
|
||||||
|
case object OP_2OVER extends StackOperation {
|
||||||
|
override def opCode = 112
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The fifth and sixth items back are moved to the top of the stack.
|
||||||
|
*/
|
||||||
|
case object OP_2ROT extends StackOperation {
|
||||||
|
override def opCode = 113
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the top two pairs of items.
|
||||||
|
*/
|
||||||
|
case object OP_2SWAP extends StackOperation {
|
||||||
|
override def opCode = 114
|
||||||
|
}
|
||||||
|
|
|
@ -30,4 +30,5 @@ class ControlOperationsTest extends FlatSpec with MustMatchers {
|
||||||
it must "define an OP_RETURN" in {
|
it must "define an OP_RETURN" in {
|
||||||
OP_RETURN.opCode must be (106)
|
OP_RETURN.opCode must be (106)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package org.scalacoin.script.stack
|
||||||
|
|
||||||
|
import org.scalatest.{MustMatchers, FlatSpec}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by chris on 1/6/16.
|
||||||
|
*/
|
||||||
|
class StackOperationsTest extends FlatSpec with MustMatchers {
|
||||||
|
|
||||||
|
"StackOperations" must "define OP_TOALTSTACK" in {
|
||||||
|
OP_TOALTSTACK.opCode must be (107)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_FROMALTSTACK" in {
|
||||||
|
OP_FROMALTSTACK.opCode must be (108)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_IFDUP" in {
|
||||||
|
OP_IFDUP.opCode must be (115)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_DEPTH" in {
|
||||||
|
OP_DEPTH.opCode must be (116)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_DROP" in {
|
||||||
|
OP_DROP.opCode must be (117)
|
||||||
|
}
|
||||||
|
it must "define OP_DUP" in {
|
||||||
|
OP_DUP.opCode must be (118)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_NIP" in {
|
||||||
|
OP_NIP.opCode must be (119)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_OVER" in {
|
||||||
|
OP_OVER.opCode must be (120)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_PICK" in {
|
||||||
|
OP_PICK.opCode must be (121)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_ROLL" in {
|
||||||
|
OP_ROLL.opCode must be (122)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_ROT" in {
|
||||||
|
OP_ROT.opCode must be (123)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_SWAP" in {
|
||||||
|
OP_SWAP.opCode must be (124)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_TUCK" in {
|
||||||
|
OP_TUCK.opCode must be (125)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_2DROP" in {
|
||||||
|
OP_2DROP.opCode must be (109)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_2DUP" in {
|
||||||
|
OP_2DUP.opCode must be (110)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_3DUP" in {
|
||||||
|
OP_3DUP.opCode must be (111)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_2OVER" in {
|
||||||
|
OP_2OVER.opCode must be (112)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_2ROT" in {
|
||||||
|
OP_2ROT.opCode must be (113)
|
||||||
|
}
|
||||||
|
|
||||||
|
it must "define OP_2SWAP" in {
|
||||||
|
OP_2SWAP.opCode must be (114)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue