forked from Arseny271/tonGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcasino.fif
364 lines (364 loc) · 16.7 KB
/
casino.fif
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
"Asm.fif" include
// automatically generated from `/home/arsen/ton/crypto/smartcont/stdlib.fc` `/home/arsen/tonGame-master/casino_stable.fc`
PROGRAM{
DECLPROC bits_count
DECLPROC send_grams
DECLPROC send_out
DECLPROC ~store_base_info
DECLPROC ~store_game_state
DECLPROC preload_base_info
DECLPROC preload_game_data
DECLPROC recv_internal
DECLPROC get_prize_size
DECLPROC create_multipliers
DECLPROC create_prize_multipliers
DECLPROC game_end
DECLPROC recv_external
bits_count PROC:<{
// number
0 PUSHINT // number res=0
WHILE:<{
OVER // number res number
}>DO<{ // number res
OVER // number res number
DEC // number res _4
s1 s2 XCHG // res number _4
AND // res number
SWAP // number res
INC // number res
}> // number res
NIP // res
}>
send_grams PROC:<{
// addr grams mode
0 PUSHINT // addr grams mode _3=0
196 PUSHINT // addr grams mode _3=0 _4=196
NEWC // addr grams mode _3=0 _4=196 _5
9 STU // addr grams mode _3=0 _7
s0 s4 XCHG2 // _3=0 grams mode _7 addr
STSLICER // _3=0 grams mode _8
ROT // _3=0 mode _8 grams
STGRAMS // _3=0 mode _9
s1 s2 XCHG // mode _3=0 _9
107 STU // mode _11
ENDC // mode _12
SWAP // _12 mode
SENDRAWMSG
}>
send_out PROC:<{
// square_price players_cell final_hash
0 PUSHINT // square_price players_cell final_hash _3=0
96 PUSHINT // square_price players_cell final_hash _3=0 _4=96
NEWC // square_price players_cell final_hash _3=0 _4=96 _5
7 STU // square_price players_cell final_hash _3=0 _7
97 STU // square_price players_cell final_hash _9
s1 s3 XCHG // final_hash players_cell square_price _9
64 STU // final_hash players_cell _11
STREF // final_hash _12
256 STU // _14
ENDC // _15
3 PUSHINT // _15 _16=3
SENDRAWMSG
}>
~store_base_info PROC:<{
// ds seqno subid public_key
s2 s3 XCHG2 // public_key subid seqno ds
32 STU // public_key subid ds
32 STU // public_key ds
256 STU // ds
}>
~store_game_state PROC:<{
// ds endgame_time square_price squares_free players_list
s3 s4 XCHG2 // players_list squares_free square_price endgame_time ds
32 STU // players_list squares_free square_price ds
64 STU // players_list squares_free ds
64 STU // players_list ds
STREF // _14
}>
preload_base_info PROC:<{
// ds
32 LDU // _1 ds
32 LDU // _1 _4 ds
256 PLDU // _1 _4 _8
}>
preload_game_data PROC:<{
// ds
LDREF // _1 ds
32 LDU // _1 _3 ds
64 LDU // _1 _3 _6 ds
64 PLDU // _1 _3 _6 _10
}>
recv_internal PROC:<{
// msg_value msg_cell msg_body
NIP // msg_value msg_body
c4 PUSH // msg_value msg_body _4
CTOS // msg_value msg_body ds
320 PUSHINT // msg_value msg_body ds _8=320
LDSLICEX // msg_value msg_body base_info ds
4 LDU // msg_value msg_body base_info status ds
SWAP // msg_value msg_body base_info ds status
1 EQINT // msg_value msg_body base_info ds _16
33 THROWIFNOT
preload_game_data CALLDICT // msg_value msg_body base_info players_list end_time square_price squares_free
NOW // msg_value msg_body base_info players_list end_time square_price squares_free _25
s3 s(-1) PUXC // msg_value msg_body base_info players_list end_time square_price squares_free end_time _25
LESS // msg_value msg_body base_info players_list end_time square_price squares_free _26
37 THROWIF
s0 s5 XCHG // msg_value squares_free base_info players_list end_time square_price msg_body
64 LDU // msg_value squares_free base_info players_list end_time square_price squares_ordered msg_body
264 PUSHINT // msg_value squares_free base_info players_list end_time square_price squares_ordered msg_body _33=264
PLDSLICEX // msg_value squares_free base_info players_list end_time square_price squares_ordered address
s1 s6 PUSH2 // msg_value squares_free base_info players_list end_time square_price squares_ordered address squares_ordered squares_free
AND // msg_value squares_free base_info players_list end_time square_price squares_ordered address squares_buyed
s7 s7 XCPU // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free squares_buyed
XOR // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free
s7 PUSH // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free squares_buyed
bits_count CALLDICT // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free squares_buyed_count
s4 PUSH // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free squares_buyed_count square_price
MUL // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free total_price
DUP // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free total_price total_price
0 EQINT // msg_value squares_buyed base_info players_list end_time square_price squares_ordered address squares_free total_price _44
39 THROWIF
s1 s9 XCHG // squares_free squares_buyed base_info players_list end_time square_price squares_ordered address msg_value total_price
SUB // squares_free squares_buyed base_info players_list end_time square_price squares_ordered address balance
DUP // squares_free squares_buyed base_info players_list end_time square_price squares_ordered address balance balance
0 LESSINT // squares_free squares_buyed base_info players_list end_time square_price squares_ordered address balance _50
35 THROWIF
s2 s7 XCPU // squares_free squares_buyed base_info players_list end_time square_price balance address squares_ordered squares_buyed
NEQ // squares_free squares_buyed base_info players_list end_time square_price balance address _52
IF:<{ // squares_free squares_buyed base_info players_list end_time square_price balance address
s0 s1 PUXC
2 PUSHINT // squares_free squares_buyed base_info players_list end_time square_price address address balance _53=2
send_grams CALLDICT
}>ELSE<{
NIP // squares_free squares_buyed base_info players_list end_time square_price address
}>
s0 s5 XCHG
NEWC // squares_free address base_info players_list end_time square_price squares_buyed _55
64 STU // squares_free address base_info players_list end_time square_price _57
s0 s5 XCHG2 // squares_free square_price base_info players_list end_time _57 address
STSLICER // squares_free square_price base_info players_list end_time _58
s1 s2 XCHG // squares_free square_price base_info end_time players_list _58
STREF // squares_free square_price base_info end_time _59
ENDC // squares_free square_price base_info end_time players_list
1 PUSHINT // squares_free square_price base_info end_time players_list _61=1
SWAP
NEWC // squares_free square_price base_info end_time _61=1 players_list _62
STREF // squares_free square_price base_info end_time _61=1 _63
s0 s3 XCHG2 // squares_free square_price _61=1 end_time _63 base_info
STSLICER // squares_free square_price _61=1 end_time _64
s1 s2 XCHG // squares_free square_price end_time _61=1 _64
4 STU // squares_free square_price end_time _66
32 STU // squares_free square_price _68
64 STU // squares_free _70
64 STU // _72
ENDC // _73
c4 POP
}>
get_prize_size PROC:<{
// prizes square_price squares
0 PUSHINT // prizes square_price squares prize=0
DUP // prizes square_price squares prize=0 i=0
WHILE:<{
s2 PUSH // prizes square_price squares prize i squares
}>DO<{ // prizes square_price squares prize i
s2 PUSH
1 PUSHINT // prizes square_price squares prize i squares _7=1
AND // prizes square_price squares prize i _8
IF:<{ // prizes square_price squares prize i
s4 s0 PUSH2 // prizes square_price squares prize i prizes i
INDEXVAR // prizes square_price squares prize i _9
s1 s2 XCHG // prizes square_price squares i prize _9
ADD // prizes square_price squares i prize
SWAP // prizes square_price squares prize i
}> // prizes square_price squares prize i
s0 s2 XCHG // prizes square_price i prize squares
1 RSHIFT# // prizes square_price i prize squares
s0 s2 XCHG // prizes square_price squares prize i
INC // prizes square_price squares prize i
}> // prizes square_price squares prize i
DROP
NIP
1 2 BLKDROP2
100 PUSHINT // square_price prize _15=100
MULDIVR // _16
}>
create_multipliers PROC:<{
//
0 TUPLE // arr
0 PUSHINT // arr i=0
16 PUSHINT // arr i=0 _4=16
REPEAT:<{ // arr i
s0 s0 PUSH2 // arr i i i
MUL // arr i _6
OVER // arr i _6 i
MUL // arr i _7
13 PUSHINT // arr i _7 _8=13
DIV // arr i _9
s1 s2 XCHG // i arr _9
TPUSH // i arr
SWAP // arr i
INC // arr i
}>
DROP // arr
}>
create_prize_multipliers PROC:<{
// hash
0 PUSHINT // hash main_winner=0
0 TUPLE // hash main_winner=0 arr
create_multipliers CALLDICT // hash main_winner=0 arr multipliers
s0 s3 XCHG // multipliers main_winner=0 arr hash
64 PUSHINT // multipliers main_winner=0 arr hash _9=64
REPEAT:<{ // multipliers main_winner arr hash
DUP
15 PUSHINT // multipliers main_winner arr hash hash _11=15
AND // multipliers main_winner arr hash mult
s4 s0 PUSH2 // multipliers main_winner arr hash mult multipliers mult
INDEXVAR // multipliers main_winner arr hash mult _14
s1 s3 XCHG // multipliers main_winner mult hash arr _14
TPUSH // multipliers main_winner mult hash arr
2SWAP // multipliers hash arr main_winner mult
ADD // multipliers hash arr main_winner
s0 s2 XCHG // multipliers main_winner arr hash
4 RSHIFT# // multipliers main_winner arr hash
}>
DROP
s2 POP // arr main_winner
63 PUSHINT // arr main_winner _19=63
AND // arr main_winner
2DUP // arr main_winner arr main_winner
INDEXVAR // arr main_winner _22
1000 PUSHINT // arr main_winner _22 _23=1000
ADD // arr main_winner _24
SWAP // arr _24 main_winner
SETINDEXVAR // arr
}>
game_end PROC:<{
// ds base_info
SWAP // base_info ds
64 LDU // base_info square_price ds
PLDREF // base_info square_price players_cell
DUP // base_info square_price players_cell players_cell
HASHCU RANDSEED XOR // base_info square_price players_cell final_hash
s2 s1 s0 PUSH3 // base_info square_price players_cell final_hash square_price players_cell final_hash
send_out CALLDICT
DUP // base_info square_price players_cell final_hash final_hash
create_prize_multipliers CALLDICT // base_info square_price players_cell final_hash prize_multipliers
s2 PUSH // base_info square_price players_cell final_hash prize_multipliers players_cell
CTOS // base_info square_price players_cell final_hash prize_multipliers players_list
WHILE:<{
DUP // base_info square_price players_cell final_hash prize_multipliers players_list players_list
SBITS // base_info square_price players_cell final_hash prize_multipliers players_list _15
}>DO<{ // base_info square_price players_cell final_hash prize_multipliers players_list
64 LDU // base_info square_price players_cell final_hash prize_multipliers squares_buyed players_list
s2 s5 s1 PU2XC // base_info square_price players_cell final_hash prize_multipliers players_list prize_multipliers square_price squares_buyed
get_prize_size CALLDICT // base_info square_price players_cell final_hash prize_multipliers players_list prize_size
SWAP
264 PUSHINT // base_info square_price players_cell final_hash prize_multipliers prize_size players_list _24=264
LDSLICEX // base_info square_price players_cell final_hash prize_multipliers prize_size address players_list
s0 s2 XCHG
3 PUSHINT // base_info square_price players_cell final_hash prize_multipliers players_list address prize_size _26=3
send_grams CALLDICT
PLDREF // base_info square_price players_cell final_hash prize_multipliers _28
CTOS // base_info square_price players_cell final_hash prize_multipliers players_list
}> // base_info square_price players_cell final_hash prize_multipliers players_list
2DROP // base_info square_price players_cell final_hash
0 PUSHINT // base_info square_price players_cell final_hash _30=0
NEWC // base_info square_price players_cell final_hash _30=0 _31
s0 s5 XCHG2 // _30=0 square_price players_cell final_hash _31 base_info
STSLICER // _30=0 square_price players_cell final_hash _32
s1 s4 XCHG // final_hash square_price players_cell _30=0 _32
4 STU // final_hash square_price players_cell _34
s1 s2 XCHG // final_hash players_cell square_price _34
64 STU // final_hash players_cell _36
STREF // final_hash _37
256 STU // _39
ENDC // _40
c4 POP
}>
recv_external PROC:<{
// in_msg
c4 PUSH // in_msg _2
CTOS // in_msg ds
320 PUSHINT // in_msg ds _6=320
LDSLICEX // in_msg base_info ds
4 LDU // in_msg base_info status ds
SWAP // in_msg base_info ds status
0 EQINT // in_msg base_info ds _13
IF:<{ // in_msg base_info ds
DROP // in_msg base_info
SWAP
9 PUSHPOW2 // base_info in_msg _16=512
LDSLICEX // base_info signature in_msg
DUP // base_info signature in_msg cs
32 LDU // base_info signature in_msg msg_subid cs
32 LDU // base_info signature in_msg msg_subid msg_seqno cs
s0 s5 XCHG // cs signature in_msg msg_subid msg_seqno base_info
preload_base_info CALLDICT // cs signature in_msg msg_subid msg_seqno stored_seqno stored_subid public_key
s3 s2 XCPU // cs signature in_msg msg_subid public_key stored_seqno stored_subid msg_seqno stored_seqno
EQUAL // cs signature in_msg msg_subid public_key stored_seqno stored_subid _32
33 THROWIFNOT
s3 s3 XCPU // cs signature in_msg stored_subid public_key stored_seqno msg_subid stored_subid
EQUAL // cs signature in_msg stored_subid public_key stored_seqno _35
34 THROWIFNOT
s0 s3 XCHG // cs signature stored_seqno stored_subid public_key in_msg
HASHSU // cs signature stored_seqno stored_subid public_key _38
s0 s4 s4 XC2PU // cs public_key stored_seqno stored_subid _38 signature public_key
CHKSIGNU // cs public_key stored_seqno stored_subid _39
35 THROWIFNOT
ACCEPT
NEWC // cs public_key stored_seqno stored_subid new_ds
s0 s2 XCHG // cs public_key new_ds stored_subid stored_seqno
INC // cs public_key new_ds stored_subid _46
s0 s1 s3 XCHG3 // cs new_ds _46 stored_subid public_key
~store_base_info CALLDICT // cs new_ds
s1 s0 XCPU // new_ds cs cs
SREMPTY // new_ds cs _50
IF:<{ // new_ds cs
32 LDU // new_ds endgame_time cs
64 PLDU // new_ds endgame_time square_price
DUP // new_ds endgame_time square_price square_price
116 MULCONST // new_ds endgame_time square_price reserve_balance
BALANCE FIRST // new_ds endgame_time square_price reserve_balance current_balance
GREATER // new_ds endgame_time square_price _64
36 THROWIF
1 PUSHINT // new_ds endgame_time square_price _67=1
s0 s3 XCHG2 // square_price endgame_time _67=1 new_ds
4 STU // square_price endgame_time new_ds
64 PUSHPOW2DEC // square_price endgame_time new_ds _75
NEWC // square_price endgame_time new_ds _75 _76
ENDC // square_price endgame_time new_ds _75 _77
s2 s4 XCHG // new_ds endgame_time square_price _75 _77
~store_game_state CALLDICT // new_ds
}>ELSE<{ // new_ds cs
8 LDU // new_ds mode cs
OVER
8 PUSHPOW2DEC // new_ds mode cs mode _83=255
NEQ // new_ds mode cs _84
IF:<{ // new_ds mode cs
PLDREF // new_ds mode _85
SWAP // new_ds _85 mode
SENDRAWMSG
}>ELSE<{
2DROP // new_ds
}>
0 PUSHINT // new_ds _88=0
SWAP // _88=0 new_ds
4 STU // new_ds
}>
ENDC // _91
c4 POP
}>ELSE<{ // in_msg base_info ds
1 2 BLKDROP2 // base_info ds
32 LDU // base_info endgame_time ds
NOW // base_info endgame_time ds _98
-60 ADDCONST // base_info endgame_time ds _100
s1 s2 XCHG // base_info ds endgame_time _100
LESS // base_info ds _101
37 THROWIFNOT
ACCEPT
SWAP // ds base_info
game_end CALLDICT
}>
}>
}END>c