-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExample.hs
155 lines (124 loc) · 3.52 KB
/
Example.hs
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{-# LANGUAGE DamlSyntax #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module Example where
{-
This file contains an example of a DAML template which can be compiled, desugared, and type-check:
$ ./_build/stage1/bin/ghc ./Example.hs
A minimal environment (to support the code generated by desugaring) is provided in:
./DA/Internal/Desugar.hs
./GHC/Types.hs
-}
import DA.Internal.Desugar
import GHC.Types
template HasAuthority
with
party: Party
where
signatory party
template ProposeConsortiumAuthority
with
proposer: Party
accepted: [Party]
obs: [Party]
consortiumParty: Party
where
signatory proposer, accepted
observer obs
choice Accept : ContractId ProposeConsortiumAuthority
with
who: Party
where
controller who
do
create this with accepted = who :: accepted
choice Ratify : ContractId HasAuthority
where
controller proposer
do
exercise self Ratify1
choice Ratify1 : ContractId HasAuthority
where
controller proposer
authority accepted -- restrict authority
do
exercise self Ratify2
choice Ratify2 : ContractId HasAuthority
where
controller accepted
authority consortiumParty -- gain authority
do
create HasAuthority with party = consortiumParty
_CONTROLLER : [Party]
_CONTROLLER = undefined
_OBSERVER : [Party]
_OBSERVER = undefined
_AUTHORITY : [Party]
_AUTHORITY = undefined
_BODY : Update ()
_BODY = undefined
template TrySyntax
with
p: Party
where
signatory p
choice X_old_just_controller : ()
controller _CONTROLLER
do _BODY
choice X_old_observer_and_controller : ()
observer _OBSERVER
controller _CONTROLLER
do _BODY
choice X_new_just_controllerX : () where { controller _CONTROLLER } do _BODY
choice X_new_just_controller : ()
where
controller _CONTROLLER
do _BODY
choice X_new_observer_and_controllerX : () where { observer _OBSERVER; controller _CONTROLLER } do _BODY
choice X_new_observer_and_controller : ()
where
observer _OBSERVER
controller _CONTROLLER
do _BODY
choice X_new_controller_and_observer : ()
where
controller _CONTROLLER
observer _OBSERVER
do _BODY
choice X_new_authority_and_controller : ()
where
authority _AUTHORITY
controller _CONTROLLER
do _BODY
choice X_new_observer_authority_and_controllerX : ()
where { observer _OBSERVER; authority _AUTHORITY; controller _CONTROLLER } do _BODY
choice X_new_observer_authority_and_controller : ()
where
observer _OBSERVER
authority _AUTHORITY
controller _CONTROLLER
do _BODY
choice X_new_authority_observer_and_controller : () -- switch the order of A/O
where
authority _AUTHORITY
observer _OBSERVER
controller _CONTROLLER
do _BODY
choice X_new_controller_authority_observer : () -- controller first
where
controller _CONTROLLER
authority _AUTHORITY
observer _OBSERVER
do _BODY
choice X_new_authority_controller_observer : () -- controller in middle
where
authority _AUTHORITY
controller _CONTROLLER
observer _OBSERVER
do _BODY