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