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
archetype escrow_basic
variable buyer : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk
variable seller : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
variable oracle : role = @tz1iawHeddgggn6P5r5jtq2wDRqcJVksGVSa
variable price : tez = 10tz
(* action deadline *)
variable deadline : date = 2019-06-01T00:00:00
(* state machine *)
states =
| Created initial
| Aborted with { i1 : balance = 0tz; }
| Confirmed with { i2 : balance = price; }
| Canceled with { i3 : balance = 0tz; }
| Completed with { i4 : balance = 0tz; }
transition abort () {
called by buyer or seller
from Created
to Aborted
}
transition confirm () {
from Created
to Confirmed when { balance = price }
}
transition complete () {
called by oracle
from Confirmed
to Completed when { now < deadline }
with effect {
transfer price to seller
}
}
transition cancel () {
called by oracle
from Confirmed
to Canceled
with effect {
transfer price to buyer
}
}
Edit on GitHub