1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "__" |
---|
5 | | - | |
---|
6 | | - | func b () = "%s__managerPublicpKey" |
---|
7 | | - | |
---|
8 | | - | |
---|
9 | | - | func c () = "%s__pendingManagerPublicKey" |
---|
10 | | - | |
---|
11 | | - | |
---|
12 | | - | func d () = throw("The block's height is too big for this proposal") |
---|
13 | | - | |
---|
14 | | - | |
---|
15 | | - | func e () = throw("You have already voted") |
---|
16 | | - | |
---|
17 | | - | |
---|
18 | | - | func f () = throw("You have not already voted") |
---|
19 | | - | |
---|
20 | | - | |
---|
21 | | - | func g () = makeString(["%s", "gwxContractAddress"], a) |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | func h () = makeString(["%s", "currentIndex"], a) |
---|
25 | | - | |
---|
26 | | - | |
---|
27 | | - | func i (j) = makeString(["%s%d", "proposalInfo", toString(j)], a) |
---|
28 | | - | |
---|
29 | | - | |
---|
30 | | - | func k (j,l) = makeString(["%s%d%s", "userVoteOnProposal", toString(j), l], a) |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | func m () = getIntegerValue(this, h()) |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | func n (o,p,q,r,s,t) = makeString(["%d%d%d%d%d%d", o, p, q, r, s, t], a) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func u (v,w) = makeString(["%d%d", v, w], a) |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | func x (y) = { |
---|
43 | | - | let z = y |
---|
44 | | - | if ($isInstanceOf(z, "Int")) |
---|
45 | | - | then { |
---|
46 | | - | let A = z |
---|
47 | | - | A |
---|
48 | | - | } |
---|
49 | | - | else throw("fail to cast into Int") |
---|
50 | | - | } |
---|
51 | | - | |
---|
52 | | - | |
---|
53 | | - | func B () = { |
---|
54 | | - | let z = getString(b()) |
---|
55 | | - | if ($isInstanceOf(z, "String")) |
---|
56 | | - | then { |
---|
57 | | - | let C = z |
---|
58 | | - | fromBase58String(C) |
---|
59 | | - | } |
---|
60 | | - | else if ($isInstanceOf(z, "Unit")) |
---|
61 | | - | then unit |
---|
62 | | - | else throw("Match error") |
---|
63 | | - | } |
---|
64 | | - | |
---|
65 | | - | |
---|
66 | | - | func D () = { |
---|
67 | | - | let z = getString(c()) |
---|
68 | | - | if ($isInstanceOf(z, "String")) |
---|
69 | | - | then { |
---|
70 | | - | let C = z |
---|
71 | | - | fromBase58String(C) |
---|
72 | | - | } |
---|
73 | | - | else if ($isInstanceOf(z, "Unit")) |
---|
74 | | - | then unit |
---|
75 | | - | else throw("Match error") |
---|
76 | | - | } |
---|
77 | | - | |
---|
78 | | - | |
---|
79 | | - | func E (F) = { |
---|
80 | | - | let z = B() |
---|
81 | | - | if ($isInstanceOf(z, "ByteVector")) |
---|
82 | | - | then { |
---|
83 | | - | let G = z |
---|
84 | | - | (F.callerPublicKey == G) |
---|
85 | | - | } |
---|
86 | | - | else if ($isInstanceOf(z, "Unit")) |
---|
87 | | - | then (F.caller == this) |
---|
88 | | - | else throw("Match error") |
---|
89 | | - | } |
---|
90 | | - | |
---|
91 | | - | |
---|
92 | | - | func H (F) = if (E(F)) |
---|
93 | | - | then true |
---|
94 | | - | else throw("permission denied") |
---|
95 | | - | |
---|
96 | | - | |
---|
97 | | - | @Callable(F) |
---|
98 | | - | func startNewVote (o,p,I,r) = { |
---|
99 | | - | let J = [H(F)] |
---|
100 | | - | if ((J == J)) |
---|
101 | | - | then { |
---|
102 | | - | let K = m() |
---|
103 | | - | [IntegerEntry(h(), (K + 1)), StringEntry(i(K), n(o, p, toString((lastBlock.height + I)), toString(r), "0", "0"))] |
---|
104 | | - | } |
---|
105 | | - | else throw("Strict value is not equal to itself.") |
---|
106 | | - | } |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | |
---|
110 | | - | @Callable(F) |
---|
111 | | - | func voteFor (L,M) = { |
---|
112 | | - | let N = "EMPTY" |
---|
113 | | - | let O = valueOrElse(getString(this, i(L)), N) |
---|
114 | | - | let P = split(O, a) |
---|
115 | | - | let Q = valueOrElse(getString(this, k(L, toString(F.caller))), N) |
---|
116 | | - | let J = [if ((O != N)) |
---|
117 | | - | then true |
---|
118 | | - | else throw("No such vote"), if ((value(parseInt(P[3])) > lastBlock.height)) |
---|
119 | | - | then true |
---|
120 | | - | else d(), if ((Q == N)) |
---|
121 | | - | then true |
---|
122 | | - | else e()] |
---|
123 | | - | if ((J == J)) |
---|
124 | | - | then { |
---|
125 | | - | let w = x(invoke(addressFromStringValue(getStringValue(g())), "getUserGwxAmountAtHeightREADONLY", [toString(F.caller), value(parseInt(P[3]))], nil)) |
---|
126 | | - | let R = if (M) |
---|
127 | | - | then { |
---|
128 | | - | let S = StringEntry(i(L), n(P[1], P[2], P[3], P[4], toString((value(parseInt(P[5])) + w)), P[6])) |
---|
129 | | - | let T = StringEntry(k(L, toString(F.caller)), u("1", toString(w))) |
---|
130 | | - | $Tuple2(S, T) |
---|
131 | | - | } |
---|
132 | | - | else { |
---|
133 | | - | let S = StringEntry(i(L), n(P[1], P[2], P[3], P[4], P[5], toString((value(parseInt(P[6])) + w)))) |
---|
134 | | - | let T = StringEntry(k(L, toString(F.caller)), u("0", toString(w))) |
---|
135 | | - | $Tuple2(S, T) |
---|
136 | | - | } |
---|
137 | | - | let S = R._1 |
---|
138 | | - | let T = R._2 |
---|
139 | | - | [S, T] |
---|
140 | | - | } |
---|
141 | | - | else throw("Strict value is not equal to itself.") |
---|
142 | | - | } |
---|
143 | | - | |
---|
144 | | - | |
---|
145 | | - | |
---|
146 | | - | @Callable(F) |
---|
147 | | - | func deleteVote (L) = { |
---|
148 | | - | let N = "EMPTY" |
---|
149 | | - | let O = valueOrElse(getString(this, i(L)), N) |
---|
150 | | - | let P = split(O, a) |
---|
151 | | - | let Q = valueOrElse(getString(this, k(L, toString(F.caller))), N) |
---|
152 | | - | let U = split(Q, a) |
---|
153 | | - | let J = [if ((O != N)) |
---|
154 | | - | then true |
---|
155 | | - | else throw("No such vote"), if ((value(parseInt(P[3])) > lastBlock.height)) |
---|
156 | | - | then true |
---|
157 | | - | else d(), if ((Q != N)) |
---|
158 | | - | then true |
---|
159 | | - | else f()] |
---|
160 | | - | if ((J == J)) |
---|
161 | | - | then { |
---|
162 | | - | let V = if ((U[1] == "1")) |
---|
163 | | - | then StringEntry(i(L), n(P[1], P[2], P[3], P[4], toString((value(parseInt(P[5])) - value(parseInt(U[2])))), P[6])) |
---|
164 | | - | else StringEntry(i(L), n(P[1], P[2], P[3], P[4], P[5], toString((value(parseInt(P[6])) - value(parseInt(U[2])))))) |
---|
165 | | - | [V, DeleteEntry(k(L, toString(F.caller)))] |
---|
166 | | - | } |
---|
167 | | - | else throw("Strict value is not equal to itself.") |
---|
168 | | - | } |
---|
169 | | - | |
---|
170 | | - | |
---|
171 | | - | |
---|
172 | | - | @Callable(F) |
---|
173 | | - | func changeVote (L,M) = { |
---|
174 | | - | let N = "EMPTY" |
---|
175 | | - | let O = valueOrElse(getString(this, i(L)), N) |
---|
176 | | - | let P = split(O, a) |
---|
177 | | - | let Q = valueOrElse(getString(this, k(L, toString(F.caller))), N) |
---|
178 | | - | let U = split(Q, a) |
---|
179 | | - | let J = [if ((O != N)) |
---|
180 | | - | then true |
---|
181 | | - | else throw("No such vote"), if ((value(parseInt(P[3])) > lastBlock.height)) |
---|
182 | | - | then true |
---|
183 | | - | else d(), if ((Q != N)) |
---|
184 | | - | then true |
---|
185 | | - | else f()] |
---|
186 | | - | if ((J == J)) |
---|
187 | | - | then { |
---|
188 | | - | let w = x(invoke(addressFromStringValue(getStringValue(g())), "getUserGwxAmountAtHeightREADONLY", [toString(F.caller), value(parseInt(P[3]))], nil)) |
---|
189 | | - | let W = if (M) |
---|
190 | | - | then { |
---|
191 | | - | let X = w |
---|
192 | | - | let Y = 0 |
---|
193 | | - | let Z = 1 |
---|
194 | | - | $Tuple3(X, Y, Z) |
---|
195 | | - | } |
---|
196 | | - | else { |
---|
197 | | - | let X = 0 |
---|
198 | | - | let Y = w |
---|
199 | | - | let Z = 0 |
---|
200 | | - | $Tuple3(X, Y, Z) |
---|
201 | | - | } |
---|
202 | | - | let aa = W._1 |
---|
203 | | - | let ab = W._2 |
---|
204 | | - | let ac = W._3 |
---|
205 | | - | let V = if ((U[1] == "1")) |
---|
206 | | - | then StringEntry(i(L), n(P[1], P[2], P[3], P[4], toString(((value(parseInt(P[5])) - value(parseInt(U[2]))) + aa)), toString((value(parseInt(P[6])) + ab)))) |
---|
207 | | - | else StringEntry(i(L), n(P[1], P[2], P[3], P[4], toString((value(parseInt(P[5])) + aa)), toString(((value(parseInt(P[6])) - value(parseInt(U[2]))) + ab)))) |
---|
208 | | - | [V, StringEntry(k(L, toString(F.caller)), u(toString(ac), toString(w)))] |
---|
209 | | - | } |
---|
210 | | - | else throw("Strict value is not equal to itself.") |
---|
211 | | - | } |
---|
212 | | - | |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | @Callable(F) |
---|
216 | | - | func getResultREADONLY (L) = { |
---|
217 | | - | let N = "EMPTY" |
---|
218 | | - | let O = valueOrElse(getString(this, i(L)), N) |
---|
219 | | - | let P = split(O, a) |
---|
220 | | - | let J = [if ((O != N)) |
---|
221 | | - | then true |
---|
222 | | - | else throw("No such vote")] |
---|
223 | | - | if ((J == J)) |
---|
224 | | - | then { |
---|
225 | | - | let s = P[5] |
---|
226 | | - | let t = P[6] |
---|
227 | | - | let r = P[4] |
---|
228 | | - | $Tuple2(nil, [s, t, r]) |
---|
229 | | - | } |
---|
230 | | - | else throw("Strict value is not equal to itself.") |
---|
231 | | - | } |
---|
232 | | - | |
---|
233 | | - | |
---|
234 | | - | |
---|
235 | | - | @Callable(F) |
---|
236 | | - | func setManager (ad) = { |
---|
237 | | - | let ae = H(F) |
---|
238 | | - | if ((ae == ae)) |
---|
239 | | - | then { |
---|
240 | | - | let af = fromBase58String(ad) |
---|
241 | | - | if ((af == af)) |
---|
242 | | - | then [StringEntry(c(), ad)] |
---|
243 | | - | else throw("Strict value is not equal to itself.") |
---|
244 | | - | } |
---|
245 | | - | else throw("Strict value is not equal to itself.") |
---|
246 | | - | } |
---|
247 | | - | |
---|
248 | | - | |
---|
249 | | - | |
---|
250 | | - | @Callable(F) |
---|
251 | | - | func confirmManager () = { |
---|
252 | | - | let ag = D() |
---|
253 | | - | let ah = if (isDefined(ag)) |
---|
254 | | - | then true |
---|
255 | | - | else throw("no pending manager") |
---|
256 | | - | if ((ah == ah)) |
---|
257 | | - | then { |
---|
258 | | - | let ai = if ((F.callerPublicKey == value(ag))) |
---|
259 | | - | then true |
---|
260 | | - | else throw("you are not pending manager") |
---|
261 | | - | if ((ai == ai)) |
---|
262 | | - | then [StringEntry(b(), toBase58String(value(ag))), DeleteEntry(c())] |
---|
263 | | - | else throw("Strict value is not equal to itself.") |
---|
264 | | - | } |
---|
265 | | - | else throw("Strict value is not equal to itself.") |
---|
266 | | - | } |
---|
267 | | - | |
---|
268 | | - | |
---|
269 | | - | @Verifier(aj) |
---|
270 | | - | func ak () = { |
---|
271 | | - | let al = { |
---|
272 | | - | let z = B() |
---|
273 | | - | if ($isInstanceOf(z, "ByteVector")) |
---|
274 | | - | then { |
---|
275 | | - | let G = z |
---|
276 | | - | G |
---|
277 | | - | } |
---|
278 | | - | else if ($isInstanceOf(z, "Unit")) |
---|
279 | | - | then aj.senderPublicKey |
---|
280 | | - | else throw("Match error") |
---|
281 | | - | } |
---|
282 | | - | sigVerify(aj.bodyBytes, aj.proofs[0], al) |
---|
283 | | - | } |
---|
284 | | - | |
---|
| 1 | + | # no script |
---|