Smart Contract is like Finite State Machine structurally switching fro

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
/**
* 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)
}