-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathescrow.aes.exp
87 lines (62 loc) · 1.87 KB
/
escrow.aes.exp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Lexon-generated Sophia code
code: Escrow
file: escrow.lex
compiler: lexon 0.3 alpha 93 U
grammar: 0.2.20 / subset 0.3.8 alpha 79 - English / Reyes
backend: sophia 0.3.93 U
target: sophia 6+
options: --sophia --comment
*/
@compiler >=6
/**
**
** Main Escrow contract system
**
**/
/** LEX Escrow.
*
* "Payer" is a person.
* "Payee" is a person.
* "Arbiter" is a person.
* "Fee" is an amount.
*
* The Payer pays an amount into escrow, appoints the Payee, appoints the Arbiter, and fixes the Fee.
**/
main contract Escrow =
record state = {
payer : address,
payee : address,
arbiter : address,
fee : int
}
entrypoint init(payee : address, arbiter : address, fee : int) = {
payer = Call.caller,
payee = payee,
arbiter = arbiter,
fee = fee
}
/* safe transfer */
stateful function transfer(to : address, amount : int) =
Chain.spend(to, amount)
/* built-in caller assertion */
function permit(authorized : address) =
require(Call.caller == authorized, "access")
/* Pay Out clause */
/*
* CLAUSE: Pay Out.
* The Arbiter may pay from escrow the Fee to themselves, and afterwards pay the remainder of the escrow to the Payee.
*/
stateful entrypoint pay_out() =
permit(state.arbiter)
transfer(state.arbiter, state.fee)
transfer(state.payee, Contract.balance)
/* Pay Back clause */
/*
* CLAUSE: Pay Back.
* The Arbiter may pay from escrow the Fee to themselves, and afterwards return the remainder of the escrow to the Payer.
*/
stateful entrypoint pay_back() =
permit(state.arbiter)
transfer(state.arbiter, state.fee)
transfer(state.payer, Contract.balance)
/* end */