1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let a = "__" |
---|
5 | | - | |
---|
6 | | - | let b = base58'WAVES' |
---|
7 | | - | |
---|
8 | | - | let c = 100000000 |
---|
9 | | - | |
---|
10 | | - | let d = "Card of the Day" |
---|
11 | | - | |
---|
12 | | - | let e = 40 |
---|
13 | | - | |
---|
14 | | - | let f = 1 |
---|
15 | | - | |
---|
16 | | - | func g (h,i) = valueOrErrorMessage(getString(h, i), makeString(["mandatory ", toString(h), ".", i, " is not defined"], "")) |
---|
17 | | - | |
---|
18 | | - | |
---|
19 | | - | func j (h,i) = valueOrErrorMessage(getInteger(h, i), makeString(["mandatory ", toString(h), ".", i, " is not defined"], "")) |
---|
20 | | - | |
---|
21 | | - | |
---|
22 | | - | func k (h,i) = valueOrErrorMessage(getBoolean(h, i), makeString(["mandatory ", toString(h), ".", i, " is not defined"], "")) |
---|
23 | | - | |
---|
24 | | - | |
---|
25 | | - | let l = "%s%s__cfg__allowedAssets" |
---|
26 | | - | |
---|
27 | | - | let m = "%s%s__cfg__assetsDecimals" |
---|
28 | | - | |
---|
29 | | - | let n = "%s%s__cfg__assetsBetDividers" |
---|
30 | | - | |
---|
31 | | - | let o = "%s%s__cfg__rsaPublic64" |
---|
32 | | - | |
---|
33 | | - | let p = "%s%s__cfg__benzAddress" |
---|
34 | | - | |
---|
35 | | - | let q = "%s%s__cfg__withdrawTimeFrame" |
---|
36 | | - | |
---|
37 | | - | let r = "%s%s__runtime__gameNum" |
---|
38 | | - | |
---|
39 | | - | let s = "%s%s__runtime__contractIsBlocked" |
---|
40 | | - | |
---|
41 | | - | func t (i) = { |
---|
42 | | - | let u = g(this, i) |
---|
43 | | - | func v (w,x) = (w :+ parseIntValue(x)) |
---|
44 | | - | |
---|
45 | | - | let y = split(u, a) |
---|
46 | | - | let z = size(y) |
---|
47 | | - | let A = nil |
---|
48 | | - | func B (C,D) = if ((D >= z)) |
---|
49 | | - | then C |
---|
50 | | - | else v(C, y[D]) |
---|
51 | | - | |
---|
52 | | - | func E (C,D) = if ((D >= z)) |
---|
53 | | - | then C |
---|
54 | | - | else throw("List size exceeds 10") |
---|
55 | | - | |
---|
56 | | - | E(B(B(B(B(B(B(B(B(B(B(A, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
57 | | - | } |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | let F = split(g(this, l), a) |
---|
61 | | - | |
---|
62 | | - | let G = t(m) |
---|
63 | | - | |
---|
64 | | - | let H = t(n) |
---|
65 | | - | |
---|
66 | | - | func I (J) = ("$RESERVED_AMOUNT_" + J) |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func K (L) = I(F[L]) |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | let M = ((5 * c) / 1000) |
---|
73 | | - | |
---|
74 | | - | let N = 0 |
---|
75 | | - | |
---|
76 | | - | let O = 1 |
---|
77 | | - | |
---|
78 | | - | let P = 2 |
---|
79 | | - | |
---|
80 | | - | let Q = 1 |
---|
81 | | - | |
---|
82 | | - | let R = 2 |
---|
83 | | - | |
---|
84 | | - | let S = 4 |
---|
85 | | - | |
---|
86 | | - | let T = 8 |
---|
87 | | - | |
---|
88 | | - | let U = 14 |
---|
89 | | - | |
---|
90 | | - | let V = 10000 |
---|
91 | | - | |
---|
92 | | - | let W = 100000 |
---|
93 | | - | |
---|
94 | | - | let X = [R] |
---|
95 | | - | |
---|
96 | | - | let Y = 0 |
---|
97 | | - | |
---|
98 | | - | let Z = 1 |
---|
99 | | - | |
---|
100 | | - | let aa = 2 |
---|
101 | | - | |
---|
102 | | - | let ab = 3 |
---|
103 | | - | |
---|
104 | | - | let ac = 4 |
---|
105 | | - | |
---|
106 | | - | let ad = 5 |
---|
107 | | - | |
---|
108 | | - | let ae = "SUBMITTED" |
---|
109 | | - | |
---|
110 | | - | let af = "WON" |
---|
111 | | - | |
---|
112 | | - | let ag = "LOST" |
---|
113 | | - | |
---|
114 | | - | func ah (i) = valueOrErrorMessage(getString(this, i), (i + " key is not specified in this.state")) |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | let ai = fromBase64String(ah(o)) |
---|
118 | | - | |
---|
119 | | - | let aj = addressFromStringValue(ah(p)) |
---|
120 | | - | |
---|
121 | | - | let ak = valueOrElse(getInteger(this, q), 7200) |
---|
122 | | - | |
---|
123 | | - | func al (i,am) = if (isDefined(getInteger(i))) |
---|
124 | | - | then getIntegerValue(i) |
---|
125 | | - | else am |
---|
126 | | - | |
---|
127 | | - | |
---|
128 | | - | func an (i,ao) = IntegerEntry(i, ao) |
---|
129 | | - | |
---|
130 | | - | |
---|
131 | | - | func ap (i) = an(i, (al(i, -1) + 1)) |
---|
132 | | - | |
---|
133 | | - | |
---|
134 | | - | func aq (i,ar) = an(i, (al(i, 0) + ar)) |
---|
135 | | - | |
---|
136 | | - | |
---|
137 | | - | func as (at) = { |
---|
138 | | - | let au = at |
---|
139 | | - | if ($isInstanceOf(au, "ByteVector")) |
---|
140 | | - | then { |
---|
141 | | - | let av = au |
---|
142 | | - | toBase58String(av) |
---|
143 | | - | } |
---|
144 | | - | else "WAVES" |
---|
145 | | - | } |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | func aw (ax) = if ((ax == "WAVES")) |
---|
149 | | - | then unit |
---|
150 | | - | else fromBase58String(ax) |
---|
151 | | - | |
---|
152 | | - | |
---|
153 | | - | func ay (at) = { |
---|
154 | | - | let au = at |
---|
155 | | - | if ($isInstanceOf(au, "ByteVector")) |
---|
156 | | - | then { |
---|
157 | | - | let az = au |
---|
158 | | - | assetBalance(this, az) |
---|
159 | | - | } |
---|
160 | | - | else wavesBalance(this).available |
---|
161 | | - | } |
---|
162 | | - | |
---|
163 | | - | |
---|
164 | | - | func aA (aB,L) = { |
---|
165 | | - | let ax = F[L] |
---|
166 | | - | let aC = (al(K(L), 0) + aB) |
---|
167 | | - | if ((aC > ay(aw(ax)))) |
---|
168 | | - | then throw((("Insufficient funds on " + d) + " account. Transaction was rejected for your safety.")) |
---|
169 | | - | else aC |
---|
170 | | - | } |
---|
171 | | - | |
---|
172 | | - | |
---|
173 | | - | func aD (aE,L,aB) = if ((0 > (al(K(L), 0) - aB))) |
---|
174 | | - | then throw((("Invalid " + d) + " account state - reserved amount is less than 0")) |
---|
175 | | - | else aq(K(L), -(aB)) |
---|
176 | | - | |
---|
177 | | - | |
---|
178 | | - | func aF (ax) = { |
---|
179 | | - | let aG = indexOf(F, ax) |
---|
180 | | - | if (!(isDefined(aG))) |
---|
181 | | - | then throw("Invalid payment asset") |
---|
182 | | - | else value(aG) |
---|
183 | | - | } |
---|
184 | | - | |
---|
185 | | - | |
---|
186 | | - | func aH (aI,aJ,aK) = { |
---|
187 | | - | let aL = size(aK) |
---|
188 | | - | func aM (u,aN) = if (u) |
---|
189 | | - | then true |
---|
190 | | - | else (aI == ((aN * G[aJ]) / H[aJ])) |
---|
191 | | - | |
---|
192 | | - | if (!({ |
---|
193 | | - | let y = X |
---|
194 | | - | let z = size(y) |
---|
195 | | - | let A = false |
---|
196 | | - | func B (C,D) = if ((D >= z)) |
---|
197 | | - | then C |
---|
198 | | - | else aM(C, y[D]) |
---|
199 | | - | |
---|
200 | | - | func E (C,D) = if ((D >= z)) |
---|
201 | | - | then C |
---|
202 | | - | else throw("List size exceeds 5") |
---|
203 | | - | |
---|
204 | | - | E(B(B(B(B(B(A, 0), 1), 2), 3), 4), 5) |
---|
205 | | - | })) |
---|
206 | | - | then throw("Bet amount is not valid") |
---|
207 | | - | else if ((parseInt(aK) == unit)) |
---|
208 | | - | then throw("Invalid player's choice") |
---|
209 | | - | else if ((aL != f)) |
---|
210 | | - | then throw("Invalid length of player's choice") |
---|
211 | | - | else fraction(aI, W, V) |
---|
212 | | - | } |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | func aO (aE,aP,aK) = { |
---|
216 | | - | let aQ = rsaVerify_16Kb(SHA256, toBytes(aE), aP, ai) |
---|
217 | | - | if (!(aQ)) |
---|
218 | | - | then throw("Invalid RSA signature") |
---|
219 | | - | else { |
---|
220 | | - | let aR = (toInt(sha256((aP + toBytes(aK)))) % e) |
---|
221 | | - | toString(aR) |
---|
222 | | - | } |
---|
223 | | - | } |
---|
224 | | - | |
---|
225 | | - | |
---|
226 | | - | func aS (aK,aT) = if ((size(aK) == f)) |
---|
227 | | - | then (aK == aT) |
---|
228 | | - | else false |
---|
229 | | - | |
---|
230 | | - | |
---|
231 | | - | func aU (aV,aK,aW,aX,aB,L,aY) = makeString([aV, aK, aW, aX, aB, L, if ((aY == "")) |
---|
232 | | - | then "" |
---|
233 | | - | else aY], "_") |
---|
234 | | - | |
---|
235 | | - | |
---|
236 | | - | func aZ (aV,aK,aW,aX,aB,L,aY) = aU(aV, aK, aW, toString(aX), toString(aB), toString(L), aY) |
---|
237 | | - | |
---|
238 | | - | |
---|
239 | | - | func ba (bb,aV,aR,bc) = { |
---|
240 | | - | let ba = aU(aV, bb[Z], bb[aa], bb[ab], bb[ac], bb[ad], aR) |
---|
241 | | - | if (bc) |
---|
242 | | - | then (ba + "_TIMEOUT") |
---|
243 | | - | else ba |
---|
244 | | - | } |
---|
245 | | - | |
---|
246 | | - | |
---|
247 | | - | func bd (aE) = split({ |
---|
248 | | - | let au = getString(this, aE) |
---|
249 | | - | if ($isInstanceOf(au, "String")) |
---|
250 | | - | then { |
---|
251 | | - | let be = au |
---|
252 | | - | be |
---|
253 | | - | } |
---|
254 | | - | else throw((("Game: " + aE) + " not found.")) |
---|
255 | | - | }, "_") |
---|
256 | | - | |
---|
257 | | - | |
---|
258 | | - | @Callable(bf) |
---|
259 | | - | func constructorV1 (bg,bh,bi,bj) = if ((bf.caller != aj)) |
---|
260 | | - | then throw("not authorized") |
---|
261 | | - | else { |
---|
262 | | - | func bk (w,bl) = { |
---|
263 | | - | let bm = split(bl, ":") |
---|
264 | | - | if ((size(bm) != 4)) |
---|
265 | | - | then throw("Invalid asset record") |
---|
266 | | - | else $Tuple3((w._1 :+ bm[N]), (w._2 :+ bm[O]), (w._3 :+ bm[P])) |
---|
267 | | - | } |
---|
268 | | - | |
---|
269 | | - | let bn = { |
---|
270 | | - | let y = split_4C(bj, "_") |
---|
271 | | - | let z = size(y) |
---|
272 | | - | let A = $Tuple3(nil, nil, nil) |
---|
273 | | - | func B (C,D) = if ((D >= z)) |
---|
274 | | - | then C |
---|
275 | | - | else bk(C, y[D]) |
---|
276 | | - | |
---|
277 | | - | func E (C,D) = if ((D >= z)) |
---|
278 | | - | then C |
---|
279 | | - | else throw("List size exceeds 10") |
---|
280 | | - | |
---|
281 | | - | E(B(B(B(B(B(B(B(B(B(B(A, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
282 | | - | } |
---|
283 | | - | [StringEntry(o, bg), StringEntry(p, bh), IntegerEntry(q, bi), StringEntry(l, makeString_2C(bn._1, a)), StringEntry(m, makeString(bn._2, a)), StringEntry(n, makeString(bn._3, a))] |
---|
284 | | - | } |
---|
285 | | - | |
---|
286 | | - | |
---|
287 | | - | |
---|
288 | | - | @Callable(bf) |
---|
289 | | - | func maintenance (bo) = if ((bf.caller != aj)) |
---|
290 | | - | then throw("not authorized") |
---|
291 | | - | else [BooleanEntry(s, bo)] |
---|
292 | | - | |
---|
293 | | - | |
---|
294 | | - | |
---|
295 | | - | @Callable(bf) |
---|
296 | | - | func bet (aK) = if (valueOrElse(getBoolean(s), false)) |
---|
297 | | - | then throw("Game is stopped for maintenence") |
---|
298 | | - | else { |
---|
299 | | - | let aE = toBase58String(bf.transactionId) |
---|
300 | | - | if ((1 >= size(bf.payments))) |
---|
301 | | - | then throw("2 payments must be attached") |
---|
302 | | - | else if (isDefined(getString(this, aE))) |
---|
303 | | - | then throw((("Bet for: " + aE) + " was already made.")) |
---|
304 | | - | else { |
---|
305 | | - | let bp = value(bf.payments[0]) |
---|
306 | | - | let bq = value(bf.payments[1]) |
---|
307 | | - | if (isDefined(bq.assetId)) |
---|
308 | | - | then throw("feePmt (2nd payment) assetId must be in Waves") |
---|
309 | | - | else if ((M > bq.amount)) |
---|
310 | | - | then throw("feePmt (2nd payment) must be >= 0.005 Waves") |
---|
311 | | - | else { |
---|
312 | | - | let ax = as(bp.assetId) |
---|
313 | | - | let aJ = aF(ax) |
---|
314 | | - | let br = bq.amount |
---|
315 | | - | let aB = aH(bp.amount, aJ, aK) |
---|
316 | | - | let aW = toBase58String(bf.callerPublicKey) |
---|
317 | | - | let bs = aZ(ae, aK, aW, height, aB, aJ, "") |
---|
318 | | - | [IntegerEntry(K(aJ), aA(aB, aJ)), ap(r), StringEntry(aE, bs), ScriptTransfer(aj, br, bq.assetId)] |
---|
319 | | - | } |
---|
320 | | - | } |
---|
321 | | - | } |
---|
322 | | - | |
---|
323 | | - | |
---|
324 | | - | |
---|
325 | | - | @Callable(bf) |
---|
326 | | - | func withdraw (aE,aP) = { |
---|
327 | | - | let bs = bd(aE) |
---|
328 | | - | let bt = bs[Y] |
---|
329 | | - | let aK = bs[Z] |
---|
330 | | - | let aX = parseIntValue(bs[ab]) |
---|
331 | | - | let aB = parseIntValue(bs[ac]) |
---|
332 | | - | let L = parseIntValue(bs[ad]) |
---|
333 | | - | let aW = bs[aa] |
---|
334 | | - | let bu = addressFromPublicKey(fromBase58String(aW)) |
---|
335 | | - | if ((bt != ae)) |
---|
336 | | - | then throw("Invalid game state for passed gameId") |
---|
337 | | - | else if ((bf.caller != aj)) |
---|
338 | | - | then throw("Regular withdraw can be done by server only") |
---|
339 | | - | else { |
---|
340 | | - | let bc = ((height - aX) > ak) |
---|
341 | | - | let aT = if (bc) |
---|
342 | | - | then aK |
---|
343 | | - | else aO(aE, aP, aK) |
---|
344 | | - | let bv = aS(aK, aT) |
---|
345 | | - | let bw = if (bv) |
---|
346 | | - | then af |
---|
347 | | - | else ag |
---|
348 | | - | let bx = ba(bs, bw, aT, bc) |
---|
349 | | - | ([StringEntry(aE, bx), aD(aE, L, aB)] ++ (if (bv) |
---|
350 | | - | then [ScriptTransfer(bu, aB, aw(F[L]))] |
---|
351 | | - | else nil)) |
---|
352 | | - | } |
---|
353 | | - | } |
---|
354 | | - | |
---|
355 | | - | |
---|
| 1 | + | # no script |
---|