trait State val name String trait InitState extends State trait Finish

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
trait State{
val name:String
}
trait InitState extends State
trait FinishState extends State
sealed trait Value[T]{
val value:T
}
case class StringValue(override val value:String) extends Value[String]
case class LongValue(override val value:Long) extends Value[Long]
case class DoubleValue(override val value:Double) extends Value[Double]
sealed trait Query
sealed trait Provider[Q <: Query]
trait Key[Q <: Query, V <: Value[_]]
sealed trait Predicate[V <: Value[_]]{
val value:V
val pattern:V
def matchPattern:Boolean
}
trait StringPredicate extends Predicate[StringValue]
trait LongPredicate extends Predicate[LongValue]
trait DoublePredicate extends Predicate[DoubleValue]
sealed trait Action
class ReleaseBitcoinsAction
/**
* Smart Contract is like Finite State Machine structurally switching from a state to another state if predicate
* returns true. From functional point of view SmartContract is mapping between [ss:State,p:Predicate]
* and [a:Action,sf:State] sets. The structure is immutable, the only way to get modified object is to call doStep()
* returning modified contract
*/
abstract class SmartContract{
type Clause = (State, Predicate[_], )
type Out = (Action,State)
val initState:InitState
val finishStates:Seq[FinishState]
val currentState:State
val transitions: Map[Clause,Out]
def doStep():SmartContract
protected def afterTransitionHook(p:Predicate, a:Action, s:State)
}