8 | | - | let kRound = "round" |
---|
9 | | - | |
---|
10 | | - | let kPlayer = "player" |
---|
11 | | - | |
---|
12 | | - | let kTotal = "total" |
---|
13 | | - | |
---|
14 | | - | let kCount = "count" |
---|
15 | | - | |
---|
16 | | - | let kPot = "pot" |
---|
17 | | - | |
---|
18 | | - | let kAsset = "asset" |
---|
19 | | - | |
---|
20 | | - | let kBet = "bet" |
---|
21 | | - | |
---|
22 | | - | let kMin = "min" |
---|
23 | | - | |
---|
24 | | - | let kMax = "max" |
---|
25 | | - | |
---|
26 | | - | let kNext = "next" |
---|
27 | | - | |
---|
28 | | - | let kLast = "last" |
---|
29 | | - | |
---|
30 | | - | let kBankroll = "bankroll" |
---|
31 | | - | |
---|
32 | | - | let kBank = "bank" |
---|
33 | | - | |
---|
34 | | - | let kDefault = "default" |
---|
35 | | - | |
---|
36 | | - | let kStatus = "status" |
---|
37 | | - | |
---|
38 | | - | let kBalance = "balance" |
---|
39 | | - | |
---|
40 | | - | func getGameKey (gameId) = makeString([kGame, gameId], separator) |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | func getGamePlayerKey (gameId,playerAddress) = makeString([getGameKey(gameId), kPlayer, playerAddress], separator) |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func getGamePlayerCounterKey (gameId) = makeString([getGameKey(gameId), kPlayer, kCount], separator) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func getGamePlayerTotalKey (gameId) = makeString([getGameKey(gameId), kPlayer, kTotal], separator) |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | func getNextBetPlayerKey (gameId) = makeString([getGameKey(gameId), kNext, kBet, kPlayer], separator) |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | func getGamePlayerStatusKey (gameId,playerAddress) = makeString([getGameKey(gameId), kStatus, kPlayer, playerAddress], separator) |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | func getGameRoundKey (gameId) = makeString([getGameKey(gameId), kRound], separator) |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | func getGamePotKey (gameId) = makeString([getGameKey(gameId), kPot], separator) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func getGameAssetKey (gameId) = makeString([getGameKey(gameId), kAsset], separator) |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func getGameMinBetKey (gameId) = makeString([getGameKey(gameId), kMin, kBet], separator) |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | func getGameLastBetKey (gameId) = makeString([getGameKey(gameId), kLast, kBet], separator) |
---|
71 | | - | |
---|
72 | | - | |
---|
73 | | - | func getGameBankrollKey (gameId) = makeString([getGameKey(gameId), kBankroll], separator) |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | func getGameBankKey (gameId) = makeString([getGameKey(gameId), kBank], separator) |
---|
77 | | - | |
---|
78 | | - | |
---|
79 | | - | func getGamePlayerBalanceKey (gameId,playerAddress) = makeString([getGameKey(gameId), kPlayer, playerAddress, kBalance], separator) |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | func setGame (gameId,flag) = BooleanEntry(getGameKey(gameId), flag) |
---|
83 | | - | |
---|
84 | | - | |
---|
85 | | - | func setGamePlayer (gameId,playerAddress,playerId) = IntegerEntry(getGamePlayerKey(gameId, playerAddress), playerId) |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | func setGamePlayerCounter (gameId,counter) = IntegerEntry(getGamePlayerCounterKey(gameId), counter) |
---|
89 | | - | |
---|
90 | | - | |
---|
91 | | - | func setGamePlayerTotal (gameId,totalPlayers) = IntegerEntry(getGamePlayerTotalKey(gameId), totalPlayers) |
---|
92 | | - | |
---|
93 | | - | |
---|
94 | | - | func setNextBetPlayer (gameId,playerId) = IntegerEntry(getNextBetPlayerKey(gameId), playerId) |
---|
95 | | - | |
---|
96 | | - | |
---|
97 | | - | func setGamePlayerStatus (gameId,playerAddress,flag) = BooleanEntry(getGamePlayerStatusKey(gameId, playerAddress), flag) |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | func setGameRound (gameId,round) = IntegerEntry(getGameRoundKey(gameId), round) |
---|
101 | | - | |
---|
102 | | - | |
---|
103 | | - | func setGamePot (gameId,pot) = IntegerEntry(getGamePotKey(gameId), pot) |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | func setGameLastBet (gameId,lastBet) = IntegerEntry(getGameLastBetKey(gameId), lastBet) |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | func setGameAsset (gameId,gameAsset) = match gameAsset { |
---|
110 | | - | case token: ByteVector => |
---|
111 | | - | StringEntry(getGameAssetKey(gameId), toBase58String(token)) |
---|
112 | | - | case _ => |
---|
113 | | - | StringEntry(getGameAssetKey(gameId), "WAVES") |
---|
114 | | - | } |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | func setGameMinBet (gameId,minBet) = IntegerEntry(getGameMinBetKey(gameId), minBet) |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | func setGameBankroll (gameId,bankroll) = IntegerEntry(getGameBankrollKey(gameId), bankroll) |
---|
121 | | - | |
---|
122 | | - | |
---|
123 | | - | func setGameBank (gameId,bank) = IntegerEntry(getGameBankrollKey(gameId), bank) |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | func setGamePlayerBalance (gameId,playerAddress,currentBalance) = IntegerEntry(getGamePlayerBalanceKey(gameId, playerAddress), currentBalance) |
---|
127 | | - | |
---|
128 | | - | |
---|
129 | | - | func getGame (gameId) = getBoolean(this, getGameKey(gameId)) |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | func getGamePlayer (gameId,playerAddress) = getStringValue(this, getGamePlayerKey(gameId, playerAddress)) |
---|
133 | | - | |
---|
134 | | - | |
---|
135 | | - | func getGamePlayerCounter (gameId) = valueOrElse(getInteger(this, getGamePlayerCounterKey(gameId)), 0) |
---|
136 | | - | |
---|
137 | | - | |
---|
138 | | - | func getGamePlayerTotal (gameId) = getIntegerValue(this, getGamePlayerTotalKey(gameId)) |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | func getNextBetPlayer (gameId) = getInteger(this, getNextBetPlayerKey(gameId)) |
---|
142 | | - | |
---|
143 | | - | |
---|
144 | | - | func getGamePlayerStatus (gameId,playerAddress) = getBoolean(this, getGamePlayerStatusKey(gameId, playerAddress)) |
---|
145 | | - | |
---|
146 | | - | |
---|
147 | | - | func getGameRound (gameId) = getInteger(this, getGameRoundKey(gameId)) |
---|
148 | | - | |
---|
149 | | - | |
---|
150 | | - | func getGamePot (gameId) = getIntegerValue(this, getGamePotKey(gameId)) |
---|
151 | | - | |
---|
152 | | - | |
---|
153 | | - | func getGameLastBet (gameId) = getInteger(this, getGameLastBetKey(gameId)) |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | func getGameAsset (gameId) = getStringValue(this, getGameAssetKey(gameId)) |
---|
157 | | - | |
---|
158 | | - | |
---|
159 | | - | func getGameMinBet (gameId) = getInteger(this, getGameMinBetKey(gameId)) |
---|
160 | | - | |
---|
161 | | - | |
---|
162 | | - | func getGameBankroll (gameId) = getIntegerValue(this, getGameBankrollKey(gameId)) |
---|
163 | | - | |
---|
164 | | - | |
---|
165 | | - | func getGameBank (gameId) = getIntegerValue(this, getGameBankKey(gameId)) |
---|
166 | | - | |
---|
167 | | - | |
---|
168 | | - | func getGamePlayerBalance (gameId,playerAddress) = getInteger(this, getGamePlayerBalanceKey(gameId, playerAddress)) |
---|
169 | | - | |
---|
170 | | - | |
---|
171 | | - | func isGameExist (gameId) = isDefined(getGame(gameId)) |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | func isGameStarted (gameId) = valueOrElse(getGame(gameId), false) |
---|
175 | | - | |
---|
176 | | - | |
---|
177 | | - | func isRequiredPlayer (gameId) = (getGamePlayerTotal(gameId) > getGamePlayerCounter(gameId)) |
---|
178 | | - | |
---|
179 | | - | |
---|
180 | | - | func isCorrectAsset (gameId,asset) = { |
---|
181 | | - | let gameAsset = getGameAsset(gameId) |
---|
182 | | - | if ((gameAsset == "WAVES")) |
---|
183 | | - | then (asset == unit) |
---|
184 | | - | else (asset == fromBase58String(gameAsset)) |
---|
| 8 | + | func randomize (bytes,range) = { |
---|
| 9 | + | let hash = sha256(bytes) |
---|
| 10 | + | let index = toInt(hash) |
---|
| 11 | + | (index % range) |
---|
220 | | - | func move (action,gameId,amount) = { |
---|
221 | | - | let gamePlayer = getGamePlayer(gameId, toString(i.caller)) |
---|
222 | | - | let lastBet = valueOrErrorMessage(getGameLastBet(gameId), "") |
---|
223 | | - | let playerBalance = valueOrErrorMessage(getGamePlayerBalance(gameId, toString(i.caller)), "") |
---|
224 | | - | let playerStatus = valueOrErrorMessage(getGamePlayerStatus(gameId, toString(i.caller)), "") |
---|
225 | | - | let playerTotal = getGamePlayerTotal(gameId) |
---|
226 | | - | if ((action == "fold")) |
---|
227 | | - | then { |
---|
228 | | - | let $t073477428 = fold(gameId, playerTotal, i.caller) |
---|
229 | | - | let structPlayerStatus = $t073477428._1 |
---|
230 | | - | let playerTotalStruct = $t073477428._2 |
---|
231 | | - | [structPlayerStatus, playerTotalStruct] |
---|
| 34 | + | func startGame () = { |
---|
| 35 | + | let amount = value(i.payments[0].amount) |
---|
| 36 | + | if ((i.payments[0].assetId != unit)) |
---|
| 37 | + | then throw("Pay in waves") |
---|
| 38 | + | else { |
---|
| 39 | + | let nullInitStore = invoke(this, "parseStruct", nil, nil) |
---|
| 40 | + | if ((nullInitStore == nullInitStore)) |
---|
| 41 | + | then { |
---|
| 42 | + | let won = valueOrErrorMessage(getBoolean(this, kWon), "Storage read error") |
---|
| 43 | + | if (won) |
---|
| 44 | + | then [ScriptTransfer(i.caller, (amount * 2), unit)] |
---|
| 45 | + | else nil |
---|
| 46 | + | } |
---|
| 47 | + | else throw("Strict value is not equal to itself.") |
---|