Basic
Basic escrow process with state machine
This first example is a toy contract which defines a very basic escrow process.
It is mainly a state machine with 5 states and 4 transitions illustrated in the state diagram:
Note that role values must be provided at declaration for security reason.
escrow_basic.arl
1
archetype escrow_basic
2
3
variable buyer : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk
4
5
variable seller : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
6
7
variable oracle : role = @tz1iawHeddgggn6P5r5jtq2wDRqcJVksGVSa
8
9
variable price : tez = 10tz
10
11
(* action deadline *)
12
variable deadline : date = 2019-06-01T00:00:00
13
14
(* state machine *)
15
states =
16
| Created initial
17
| Aborted with { i1 : balance = 0tz; }
18
| Confirmed with { i2 : balance = price; }
19
| Canceled with { i3 : balance = 0tz; }
20
| Completed with { i4 : balance = 0tz; }
21
22
transition abort () {
23
called by buyer or seller
24
25
from Created
26
to Aborted
27
}
28
29
transition confirm () {
30
from Created
31
to Confirmed when { balance = price }
32
}
33
34
transition complete () {
35
called by oracle
36
37
from Confirmed
38
to Completed when { now < deadline }
39
with effect {
40
transfer price to seller
41
}
42
}
43
44
transition cancel () {
45
called by oracle
46
47
from Confirmed
48
to Canceled
49
with effect {
50
transfer price to buyer
51
}
52
}
53
Copied!
Last modified 1yr ago
Export as PDF
Copy link