-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathescrow.0.sopx.exp
130 lines (93 loc) · 4.11 KB
/
escrow.0.sopx.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Lexon-generated Sophia code
code: Escrow
file: lexon/escrow.0.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 --all-auxiliaries
INSTRUCTIONS FOR USE:
Deploy this smart contract to the Aeternity blockchain or testchain. An easy way to
get started is to copy-paste this code into https://studio.aepps.com. Replace the
<parameters> with literal values to interact with the contract via terminal.
LIKE ALL SMART CONTRACTS THIS CODE MUST BE AUDITED BEFORE USING IT IN PRODUCTION.
Note that the instructions below reflect your Lexon code, as well as the options
used during compilation of the code: different clauses and options will result from
different input code. Some functions are 'built-in' but only appear when needed as
per compiler options used during compilation – a list of options is available with
lexon -h. The functions are given in the order of appearance, in the Lexon source.
The required caller is noted in double angle brackets << >>. Some functions can be
called by anyone. Note that roles are being defined by using an account for it for
the first time. This will require for the same account to be used for the same role
after this point. Else, the call will revert, i.e. cancelled and not go through.
Some clauses of the original Lexon source text do not appear in the comments below.
Namely, those without permission phrase, wherefore they are regarded as internal.
These are the constructor parameters for deployment. If you are using Aestudio, the
fields under the deploy button are where your values for them go before deploying.
<payee : option(address)>, <arbiter : option(address)>, <fee : option(int)>
These are the state progress functions that allow to interact with the contract:
• <<Arbiter>> ⟶ pay_out()
• <<Arbiter>> ⟶ pay_back()
*/
@compiler >=6
include "Option.aes"
/**
**
** Main Escrow contract system
**
**/
/** LEX Escrow.
*
* "Payer" is a person.
* "Payee" is a person.
* "Arbiter" is a person.
* "Amount" is an amount.
* "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 : option(address),
payee : option(address),
arbiter : option(address),
amount : option(int),
fee : option(int)
}
entrypoint init(payee : address, arbiter : address, fee : int) = {
payer = Some(Call.caller),
payee = Some(payee),
arbiter = Some(arbiter),
amount = Some(Call.value),
fee = Some(fee)
}
/* safe transfer */
stateful function transfer(to : address, amount : int) =
Chain.spend(to, amount)
/* built-in caller assertion */
function permit(authorized : option(address), name : string) =
require(Call.caller == force(authorized, name), StringInternal.concat("no access for ", name))
/* built-in option type force function */
function force(o : option('a), name : string) : 'a =
switch(o)
None => abort(StringInternal.concat(name, " not fixed"))
Some(a) => a
/* 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, "Arbiter")
transfer(state.arbiter, force(state.fee, "Fee"))
transfer(force(state.payee, "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, "Arbiter")
transfer(state.arbiter, force(state.fee, "Fee"))
transfer(force(state.payer, "Payer"), Contract.balance)
/* end */