Basic
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 = @tz1KmuhR6P52hw6xs5P69BXJYAURaznhvN1k
4
5
variable seller : role = @tz1XJYAURaznhvN1khR6P52hw6xs5P691Kmu
6
7
variable oracle : role = @tz15P69BXJYAURaznhvN1k1KmuhR6P52hw6x
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[%onlyonce%] 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[%onlyonce%] cancel () {
45
called by oracle
46
47
from Confirmed
48
to Canceled
49
with effect {
50
transfer price to buyer
51
}
52
}
53
54
security {
55
s1 : only_by_role (transfers, oracle)
56
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link
Edit on GitHub