2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqlAiANSmBpDHYKP9sKgeN/l1bAb28g/tGlgDkwT5FiMN4X3pwdvdxE7mvSR8/41dU9rx4jG+6tZpb1ULVDPs431tR2IRaTXw5Cj+Ac2vhL+5JamCerGD1UW+bh/EGQtxo8W3YLDrofXB5QHJx4Pkz2Kgf+oS/C8hHuB/U4krO76U0507GTjZPP9kRQ0uLSMeqQXt8wXS+nMp5wajqxPpDLMaSREgsKwv/AEkP4dzpTYbikLBYl4qtdJsD84HLFSkiwd3BhcOrPjoIYmLxQuBD5TIMKTKD3sdZgaY9rsyqx3A00innyxD6zp3b4gFpUOX8JxKZdEC2myEqleNgg7GzwIDAQAB") |
---|
5 | | - | |
---|
6 | | - | let b = addressFromStringValue("3NCiG28LmWyTigWG13E5QnvdHBsZFYXSS2j") |
---|
7 | | - | |
---|
8 | | - | let c = ((100 * 1000) * 1000) |
---|
9 | | - | |
---|
10 | | - | let d = 44 |
---|
11 | | - | |
---|
12 | | - | let e = ((5 * c) / 1000) |
---|
13 | | - | |
---|
14 | | - | let f = 14 |
---|
15 | | - | |
---|
16 | | - | let g = "INIT" |
---|
17 | | - | |
---|
18 | | - | let h = "READY" |
---|
19 | | - | |
---|
20 | | - | let i = "FINISHED" |
---|
21 | | - | |
---|
22 | | - | let j = 0 |
---|
23 | | - | |
---|
24 | | - | let k = 1 |
---|
25 | | - | |
---|
26 | | - | let l = 2 |
---|
27 | | - | |
---|
28 | | - | let m = 3 |
---|
29 | | - | |
---|
30 | | - | let n = 4 |
---|
31 | | - | |
---|
32 | | - | let o = 5 |
---|
33 | | - | |
---|
34 | | - | let p = 6 |
---|
35 | | - | |
---|
36 | | - | let q = 7 |
---|
37 | | - | |
---|
38 | | - | let r = 8 |
---|
39 | | - | |
---|
40 | | - | let s = 13 |
---|
41 | | - | |
---|
42 | | - | func t (u) = if ((0 > u)) |
---|
43 | | - | then -(u) |
---|
44 | | - | else u |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | func v (w,x,y,z,A,B,C,D,E,F,G,H,I,J) = { |
---|
48 | | - | let K = ((((((((((((((((((((((((w + "_") + x) + "_") + y) + "_") + z) + "_") + A) + "_") + B) + "_") + C) + "_") + D) + "_") + E) + "_") + F) + "_") + G) + "_") + H) + "_") + I) |
---|
49 | | - | if ((J == "")) |
---|
50 | | - | then ((K + "_") + "-") |
---|
51 | | - | else ((K + "_") + J) |
---|
52 | | - | } |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func L (M) = { |
---|
56 | | - | let N = getStringValue(this, M) |
---|
57 | | - | split(N, "_") |
---|
58 | | - | } |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func O (P,Q,R,B,S) = { |
---|
62 | | - | let T = ((t(toInt(S)) % P) + Q) |
---|
63 | | - | let U = toString(T) |
---|
64 | | - | let V = isDefined(indexOf(R, U)) |
---|
65 | | - | if (if (!(V)) |
---|
66 | | - | then (B > 0) |
---|
67 | | - | else false) |
---|
68 | | - | then [((R + "-") + U), "yes"] |
---|
69 | | - | else [R, ""] |
---|
70 | | - | } |
---|
71 | | - | |
---|
72 | | - | |
---|
73 | | - | func W (M,X,Y,Z,R,B,aa,ab,ac,ad,ae) = { |
---|
74 | | - | let af = if (((aa + 1) > 87)) |
---|
75 | | - | then if ((ae > 241)) |
---|
76 | | - | then [0, (ab + 1), (ac + 1), 0, 1] |
---|
77 | | - | else [0, ab, ac, (ad + 1), (ae + 1)] |
---|
78 | | - | else [(aa + 1), ab, ac, ad, ae] |
---|
79 | | - | let ag = af[0] |
---|
80 | | - | let ah = af[1] |
---|
81 | | - | let ai = af[2] |
---|
82 | | - | let aj = af[3] |
---|
83 | | - | let ak = af[4] |
---|
84 | | - | let al = (((((((take(drop(Z, ah), 1) + take(drop(Z, 1), 1)) + take(drop(Z, aj), 1)) + take(drop(Z, 3), 1)) + take(drop(Z, ai), 1)) + take(drop(Z, 5), 1)) + take(drop(Z, 6), 1)) + take(drop(Z, ak), 1)) |
---|
85 | | - | let am = ((sha256(al) + blake2b256(al)) + keccak256(al)) |
---|
86 | | - | let P = ((Y - X) + 1) |
---|
87 | | - | let an = O(P, X, R, B, drop(am, ag)) |
---|
88 | | - | let ao = if ((an[1] != "")) |
---|
89 | | - | then (B - 1) |
---|
90 | | - | else B |
---|
91 | | - | let ap = O(P, X, an[0], ao, drop(am, (ag + 1))) |
---|
92 | | - | let aq = if ((ap[1] != "")) |
---|
93 | | - | then (ao - 1) |
---|
94 | | - | else ao |
---|
95 | | - | let ar = O(P, X, ap[0], aq, drop(am, (ag + 2))) |
---|
96 | | - | let as = if ((ar[1] != "")) |
---|
97 | | - | then (aq - 1) |
---|
98 | | - | else aq |
---|
99 | | - | let at = O(P, X, ar[0], as, drop(am, (ag + 3))) |
---|
100 | | - | let au = if ((at[1] != "")) |
---|
101 | | - | then (as - 1) |
---|
102 | | - | else as |
---|
103 | | - | let av = O(P, X, at[0], au, drop(am, (ag + 4))) |
---|
104 | | - | let aw = if ((av[1] != "")) |
---|
105 | | - | then (au - 1) |
---|
106 | | - | else au |
---|
107 | | - | let ax = O(P, X, av[0], aw, drop(am, (ag + 5))) |
---|
108 | | - | let ay = if ((ax[1] != "")) |
---|
109 | | - | then (aw - 1) |
---|
110 | | - | else aw |
---|
111 | | - | let az = O(P, X, ax[0], ay, drop(am, (ag + 6))) |
---|
112 | | - | let aA = if ((az[1] != "")) |
---|
113 | | - | then (ay - 1) |
---|
114 | | - | else ay |
---|
115 | | - | let aB = O(P, X, az[0], aA, drop(am, (ag + 7))) |
---|
116 | | - | let aC = if ((aB[1] != "")) |
---|
117 | | - | then (aA - 1) |
---|
118 | | - | else aA |
---|
119 | | - | let aD = O(P, X, aB[0], aC, drop(am, (ag + 8))) |
---|
120 | | - | let aE = if ((aD[1] != "")) |
---|
121 | | - | then (aC - 1) |
---|
122 | | - | else aC |
---|
123 | | - | let aF = O(P, X, aD[0], aE, drop(am, (ag + 9))) |
---|
124 | | - | let aG = if ((aF[1] != "")) |
---|
125 | | - | then (aE - 1) |
---|
126 | | - | else aE |
---|
127 | | - | let aH = O(P, X, aF[0], aG, drop(am, (ag + 10))) |
---|
128 | | - | let aI = if ((aH[1] != "")) |
---|
129 | | - | then (aG - 1) |
---|
130 | | - | else aG |
---|
131 | | - | [aH[0], if ((aI == 0)) |
---|
132 | | - | then "0" |
---|
133 | | - | else toString(aI), toString((ag + 10)), toString(ah), toString(ai), toString(aj), toString(ak)] |
---|
134 | | - | } |
---|
135 | | - | |
---|
136 | | - | |
---|
137 | | - | func aJ (M,C,aK) = { |
---|
138 | | - | let aL = split(aK.key, "_") |
---|
139 | | - | if ((size(aL) != 2)) |
---|
140 | | - | then throw("Invalid data key format. It must follow to ${sessionId}_${num}") |
---|
141 | | - | else { |
---|
142 | | - | let aM = aL[0] |
---|
143 | | - | let aN = aL[1] |
---|
144 | | - | if ((M != aM)) |
---|
145 | | - | then throw(((("Several data keys have different sessionId: " + M) + " and ") + aM)) |
---|
146 | | - | else if (isDefined(getString(this, aK.key))) |
---|
147 | | - | then throw(("One of the data keys has already presented in account state: key=" + aK.key)) |
---|
148 | | - | else if ((size(aN) > 4)) |
---|
149 | | - | then throw("Invalid data key format. It must follow to ${sessionId}_${num} where ${num} length couldn't be greater than 4") |
---|
150 | | - | else if ((take(aN, 1) == "0")) |
---|
151 | | - | then throw("Invalid data key format. It must follow to ${sessionId}_${num} where ${num} couldn't start from 0") |
---|
152 | | - | else { |
---|
153 | | - | let aO = parseInt(aN) |
---|
154 | | - | if (isDefined(aO)) |
---|
155 | | - | then { |
---|
156 | | - | let aP = extract(aO) |
---|
157 | | - | if (if ((1 > aP)) |
---|
158 | | - | then true |
---|
159 | | - | else (aP > C)) |
---|
160 | | - | then throw((((("Invalid data key format. It must follow to ${sessionId}_${num}" + " where ${num} must be a valid int value from 1 to ") + toString(C)) + " but actualNum=") + toString(aP))) |
---|
161 | | - | else { |
---|
162 | | - | let aQ = aK.value |
---|
163 | | - | if ($isInstanceOf(aQ, "String")) |
---|
164 | | - | then { |
---|
165 | | - | let aR = aQ |
---|
166 | | - | true |
---|
167 | | - | } |
---|
168 | | - | else throw((M + " draw: only String type is accepted for data transactions")) |
---|
169 | | - | } |
---|
170 | | - | } |
---|
171 | | - | else throw((("Invalid data key format. It must follow to ${sessionId}_${num}" + " where ${num} must be a valid int value from 1 to 7145 but actualNum=") + aN)) |
---|
172 | | - | } |
---|
173 | | - | } |
---|
174 | | - | } |
---|
175 | | - | |
---|
176 | | - | |
---|
177 | | - | func aS (A,aT,aU) = { |
---|
178 | | - | let aV = 1000 |
---|
179 | | - | let aW = ((13 * c) / 100) |
---|
180 | | - | let aX = 50 |
---|
181 | | - | let aY = ((8 * c) / 100) |
---|
182 | | - | let aZ = 5000 |
---|
183 | | - | let ba = ((297 * c) / 100) |
---|
184 | | - | let bb = 1000 |
---|
185 | | - | let bc = ((143 * c) / 100) |
---|
186 | | - | let bd = 50000 |
---|
187 | | - | let be = ((1427 * c) / 100) |
---|
188 | | - | let bf = 5000 |
---|
189 | | - | let bg = ((705 * c) / 100) |
---|
190 | | - | let bh = if ((aV > A)) |
---|
191 | | - | then (aW + ((A / aX) * aY)) |
---|
192 | | - | else if ((aZ > A)) |
---|
193 | | - | then (ba + (((A / bb) - 1) * bc)) |
---|
194 | | - | else if ((bd > A)) |
---|
195 | | - | then (be + (((A / bf) - 1) * bg)) |
---|
196 | | - | else throw("Please contact our sales team to generate more than 50k rands") |
---|
197 | | - | let bi = (bh + aU) |
---|
198 | | - | if (isDefined(aT.assetId)) |
---|
199 | | - | then throw("Only WAVES can be used as a payment for rands generation") |
---|
200 | | - | else if ((bi > aT.amount)) |
---|
201 | | - | then throw(((((("Attached payment is to small to generate " + toString(A)) + " unique randoms numbers and upload at least 1 data tx: actualPmt=") + toString(aT.amount)) + " but minPmt is ") + toString(bi))) |
---|
202 | | - | else bh |
---|
203 | | - | } |
---|
204 | | - | |
---|
205 | | - | |
---|
206 | | - | @Callable(bj) |
---|
207 | | - | func initDraw (y,z,A) = { |
---|
208 | | - | let M = toBase58String(bj.transactionId) |
---|
209 | | - | let bk = ((z - y) + 1) |
---|
210 | | - | let bl = (bk / 2) |
---|
211 | | - | let bm = size(toString((z - 1))) |
---|
212 | | - | let bn = size(toString(A)) |
---|
213 | | - | let bo = (((2 * bm) + (2 * bn)) + 4) |
---|
214 | | - | let bp = (((32767 - 126) - bo) / (bm + 1)) |
---|
215 | | - | if (if ((0 >= y)) |
---|
216 | | - | then true |
---|
217 | | - | else (0 >= z)) |
---|
218 | | - | then throw("randFrom and randTo must be greater than 0") |
---|
219 | | - | else if ((y >= z)) |
---|
220 | | - | then throw("randFrom must be strict less then randTo") |
---|
221 | | - | else if ((A > bk)) |
---|
222 | | - | then throw(((((((("Impossible to generate " + toString(A)) + " unique numbers for provided random range [") + toString(y)) + ", ") + toString(z)) + "] with actual size ") + toString(bk))) |
---|
223 | | - | else if ((A > bl)) |
---|
224 | | - | then throw(((((((((("randsCount must be less then 50% of passed range length: range=[" + toString(y)) + ", ") + toString(z)) + "], rangeLength=") + toString(bk)) + " randsCount=") + toString(A)) + " allowedRandsCount=") + toString(bl))) |
---|
225 | | - | else if ((A > bp)) |
---|
226 | | - | then throw(((((("randsCount couldn't be kept in 1 data entry: 1_randNumSpace=" + toString((bm + 1))) + " maxAllowedRandsCount=") + toString(bp)) + " actualRandsCount=") + toString(A))) |
---|
227 | | - | else if (!(isDefined(bj.payment))) |
---|
228 | | - | then throw("Please provide payment to generate unique random numbers") |
---|
229 | | - | else { |
---|
230 | | - | let aT = extract(bj.payment) |
---|
231 | | - | let aU = ((5 * c) / 1000) |
---|
232 | | - | let bq = aS(A, aT, aU) |
---|
233 | | - | let br = (aT.amount - bq) |
---|
234 | | - | let bs = (br / aU) |
---|
235 | | - | let C = (bs * 5) |
---|
236 | | - | let x = toBase58String(bj.callerPublicKey) |
---|
237 | | - | let bt = toString(A) |
---|
238 | | - | let bu = v(g, x, toString(y), toString(z), bt, bt, toString(C), "null", "0", "0", "1", "0", "1", "") |
---|
239 | | - | ScriptResult(WriteSet([DataEntry(M, bu)]), TransferSet([ScriptTransfer(b, bq, unit)])) |
---|
240 | | - | } |
---|
241 | | - | } |
---|
242 | | - | |
---|
243 | | - | |
---|
244 | | - | |
---|
245 | | - | @Callable(bj) |
---|
246 | | - | func ready (M) = { |
---|
247 | | - | let bv = L(M) |
---|
248 | | - | let w = bv[j] |
---|
249 | | - | let x = bv[k] |
---|
250 | | - | let bt = bv[n] |
---|
251 | | - | let bw = bv[o] |
---|
252 | | - | let bx = bv[l] |
---|
253 | | - | let by = bv[m] |
---|
254 | | - | let C = bv[p] |
---|
255 | | - | let bz = fromBase58String(x) |
---|
256 | | - | if ((w != g)) |
---|
257 | | - | then throw((M + " draw: moving into READY state is allowed only from INIT state")) |
---|
258 | | - | else if ((bz != bj.callerPublicKey)) |
---|
259 | | - | then throw((M + "draw: moving into READY state is allowed for organizer only")) |
---|
260 | | - | else { |
---|
261 | | - | let bA = v(h, x, bx, by, bt, bw, C, toBase58String(bj.transactionId), "0", "0", "1", "0", "1", "") |
---|
262 | | - | WriteSet([DataEntry(M, bA)]) |
---|
263 | | - | } |
---|
264 | | - | } |
---|
265 | | - | |
---|
266 | | - | |
---|
267 | | - | |
---|
268 | | - | @Callable(bj) |
---|
269 | | - | func random (M,Z) = { |
---|
270 | | - | let bv = L(M) |
---|
271 | | - | let w = bv[j] |
---|
272 | | - | let x = bv[k] |
---|
273 | | - | let bt = bv[n] |
---|
274 | | - | let bB = parseIntValue(bv[o]) |
---|
275 | | - | let aa = parseIntValue(bv[r]) |
---|
276 | | - | let R = bv[s] |
---|
277 | | - | let bx = bv[l] |
---|
278 | | - | let by = bv[m] |
---|
279 | | - | let D = bv[q] |
---|
280 | | - | let F = parseIntValue(bv[9]) |
---|
281 | | - | let G = parseIntValue(bv[10]) |
---|
282 | | - | let H = parseIntValue(bv[11]) |
---|
283 | | - | let I = parseIntValue(bv[12]) |
---|
284 | | - | let X = parseIntValue(bx) |
---|
285 | | - | let Y = parseIntValue(by) |
---|
286 | | - | let bz = fromBase58String(x) |
---|
287 | | - | if ((w != h)) |
---|
288 | | - | then throw((M + " draw: it must be in READY state to generate random numbers")) |
---|
289 | | - | else if (!(rsaVerify(SHA256, (toBytes(M) + toBytes(D)), Z, a))) |
---|
290 | | - | then throw("Invalid RSA signature") |
---|
291 | | - | else { |
---|
292 | | - | let bC = W(M, X, Y, Z, R, bB, aa, F, G, H, I) |
---|
293 | | - | let bD = bC[1] |
---|
294 | | - | let bE = if ((bD == "0")) |
---|
295 | | - | then i |
---|
296 | | - | else h |
---|
297 | | - | WriteSet([DataEntry(M, v(bE, x, bx, by, bt, bD, bv[p], D, bC[2], bC[3], bC[4], bC[5], bC[6], bC[0]))]) |
---|
298 | | - | } |
---|
299 | | - | } |
---|
300 | | - | |
---|
301 | | - | |
---|
302 | | - | @Verifier(bF) |
---|
303 | | - | func bG () = { |
---|
304 | | - | let aQ = bF |
---|
305 | | - | if ($isInstanceOf(aQ, "DataTransaction")) |
---|
306 | | - | then { |
---|
307 | | - | let bH = aQ |
---|
308 | | - | let bI = bH.data[0] |
---|
309 | | - | let M = take(bI.key, d) |
---|
310 | | - | let bv = L(M) |
---|
311 | | - | let w = bv[j] |
---|
312 | | - | let x = bv[k] |
---|
313 | | - | let C = parseIntValue(bv[p]) |
---|
314 | | - | let bz = fromBase58String(x) |
---|
315 | | - | let bJ = size(bH.data) |
---|
316 | | - | let bK = sigVerify(bF.bodyBytes, bF.proofs[0], bz) |
---|
317 | | - | let bL = (bJ == 5) |
---|
318 | | - | let bM = (bH.fee == ((c * 5) / 1000)) |
---|
319 | | - | let bN = if (if (if (if (aJ(M, C, bI)) |
---|
320 | | - | then aJ(M, C, bH.data[1]) |
---|
321 | | - | else false) |
---|
322 | | - | then aJ(M, C, bH.data[2]) |
---|
323 | | - | else false) |
---|
324 | | - | then aJ(M, C, bH.data[3]) |
---|
325 | | - | else false) |
---|
326 | | - | then aJ(M, C, bH.data[4]) |
---|
327 | | - | else false |
---|
328 | | - | if (if (if (if ((w == g)) |
---|
329 | | - | then bK |
---|
330 | | - | else false) |
---|
331 | | - | then bM |
---|
332 | | - | else false) |
---|
333 | | - | then bL |
---|
334 | | - | else false) |
---|
335 | | - | then bN |
---|
336 | | - | else false |
---|
337 | | - | } |
---|
338 | | - | else if ($isInstanceOf(aQ, "SetScriptTransaction")) |
---|
339 | | - | then { |
---|
340 | | - | let bO = aQ |
---|
341 | | - | true |
---|
342 | | - | } |
---|
343 | | - | else if ($isInstanceOf(aQ, "TransferTransaction")) |
---|
344 | | - | then { |
---|
345 | | - | let bP = aQ |
---|
346 | | - | true |
---|
347 | | - | } |
---|
348 | | - | else false |
---|
349 | | - | } |
---|
350 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|