-
Notifications
You must be signed in to change notification settings - Fork 0
/
649.se
189 lines (166 loc) · 5.82 KB
/
649.se
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
shared:
BETTING_BLOCK = 1
ENROLLED = 2
POOL = 3
WINNINGNUM = 4
START_POINT = 12
BET = 1000000000
PERIOD = 1
SELECTION = 20
FEE = 50
REWARD6 = 685
REWARD5B = 50
REWARD5 = 40
REWARD4 = 75
REWARDG = 100
init:
contract.storage[BETTING_BLOCK] = block.number
contract.storage[ENROLLED] = 0
contract.storage[POOL] = 0
code:
sender = msg.sender
enrolled = contract.storage[ENROLLED]
pool = contract.storage[POOL]
if block.number <= contract.storage[BETTING_BLOCK]:
contract.storage[POOL] = pool + msg.value
if msg.value < BET:
return(0)
else:
pos = START_POINT + enrolled * 7
contract.storage[pos] = sender
contract.storage[ENROLLED] = enrolled + 1
pos += 1
# pick 6 numbers
num = 6
if msg.data[0] < 6:
num = msg.data[0]
numbers = array(6)
used = array(SELECTION)
count = 0
i = 0
while i < num:
n = msg.data[i + 1]
if (n >=0 and n<= 49) and used[n] == 0:
used[n] = 1
numbers[count] = n
contract.storage[pos] = n
count += 1
pos += 1
i += 1
h = sha3(block.prevhash + msg.sender + enrolled)
while count < 6:
n = h % SELECTION
if (n >=0 and n<= 49) and used[n] == 0:
used[n] = 1
numbers[count] = n
contract.storage[pos] = n
count += 1
pos += 1
h = sha3(h + count)
numbers[count] = enrolled
return(numbers, 7)
else:
selected = array(8)
if enrolled > 0 :
match6 = 0
winner6 = array(10)
match5b = 0
winner5b = array(100)
match5 = 0
winner5 = array(10000)
match4 = 0
winner4 = array(100000)
match3 = 0
match2b = 0
match2 = 0
h = sha3(block.prevhash + enrolled)
numbers = array(SELECTION)
n = (h % SELECTION + SELECTION) % SELECTION
numbers[n] = 2
selected[6] = n
contract.storage[WINNINGNUM + 6] = n
i = 0
while i < 6:
h = sha3(h + i)
n = (h % SELECTION + SELECTION) % SELECTION
if numbers[n] == 0:
numbers[n] = 1
selected[i] = n
contract.storage[WINNINGNUM + i] = n
i += 1
h = sha3(h + i)
n = (h % enrolled + enrolled) % enrolled
posG = START_POINT + 7*n
winnerG = contract.storage[posG]
selected[7] = h % enrolled
contract.storage[WINNINGNUM + 7] = winnerG
i = 0
while i < enrolled:
bonus = 0
match = 0
j = 1
pos = START_POINT + i * 7
while j <= 6:
n = contract.storage[pos + j]
if numbers[n] == 2:
bonus = 1
if numbers[n] == 1:
match += 1
j +=1
addr = contract.storage[pos]
if match == 6:
winner6[match6] = addr
match6 += 1
if match == 5 and bonus == 1:
winner5b[match5b] = addr
match5b += 1
if match == 5 and bonus == 0:
winner5[match5] = addr
match5 += 1
if match == 4:
winner4[match4] = addr
match4 += 1
if match == 3:
send(addr, 3 * BET)
match3 += 1
if match == 2 and bonus == 1:
send(addr, 2 * BET)
match2b += 1
if match == 2 and bonus == 0:
send(addr, BET)
match2 += 1
i += 1
contract.storage[10000012] = pool
pool = pool - 3*BET*match3 - 2*BET*match2b - BET*match2
rewardg = REWARDG * pool / 1000
minefee = FEE * pool / 1000
send(winnerG, rewardg)
#send(miner, minefee)
if match6 > 0:
i = 0
reward = (pool * REWARD6 / 1000) / match6
while i < match6:
send(winner6[i], reward)
pool -= (pool * REWARD5b / 1000)
if match5b > 0:
i = 0
reward = (pool * REWARD5b / 1000) / match5b
while i < match5b:
send(winner5b[i], reward)
pool -= (pool * REWARD5b / 1000)
if match5 > 0:
i = 0
reward = (pool * REWARD5 / 1000) / match5
while i < match5:
send(winner5[i], reward)
pool -= (pool * REWARD5 / 1000)
if match4 > 0:
i = 0
reward = (pool * REWARD4 / 1000) / match4
while i < match4:
send(winner4[i], reward)
pool -=(pool * REWARD4 / 1000)
contract.storage[BETTING_BLOCK] = block.number + PERIOD
contract.storage[ENROLLED] = 0
contract.storage[POOL] = pool
return(selected, 8)