tx · aor7LFVpHayLX9ZCExAuiPS5SXEm1MvkFMG2tmvqZr7 3NCCNgEjGtWKLt78jWc9DiA3Jd2jmfg7BZX: -0.10000000 Waves 2022.01.14 02:19 [1877836] smart account 3NCCNgEjGtWKLt78jWc9DiA3Jd2jmfg7BZX > SELF 0.00000000 Waves
{ "type": 13, "id": "aor7LFVpHayLX9ZCExAuiPS5SXEm1MvkFMG2tmvqZr7", "fee": 10000000, "feeAssetId": null, "timestamp": 1642116019471, "version": 2, "chainId": 84, "sender": "3NCCNgEjGtWKLt78jWc9DiA3Jd2jmfg7BZX", "senderPublicKey": "AcdhXSF5aWK6Lmdtv3cyCZ7vehbxsNNGagWCd2FpZo1M", "proofs": [ "53ikMgE9TE9sCmW6T1fZUTwRe1XWdkbv4FvGqNo4CCXGCH1ur5c4FbcPbSVwgPpXLuXNgnQVYcTZQmxngc6X8T3N" ], "script": "base64:AAIFAAAAAAAAABQIAhIFCgMIAQESABIHCgUBCAgICAAAAA8AAAAAE2dhbWVNYXN0ZXJQdWJsaWNLZXkBAAAAIF1t2Oq4Jp6DRGnJV2x+n66xACBB37xnTL7cQnLLqBNvAAAAAAlSU0FQVUJMSUMJAAJbAAAAAQIAAAGTYmFzZTY0Ok1JSUJJekFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUkFBTUlJQkN3S0NBUUlBK0NwYnpNQktwcSs3VmFyU0RITFcwd1FTb2gyTFRiZ2wxckFoZnJ1WkdDanQ2TU80bzF2MWlMcUt5TkgzRkpzdndsTFVxbXFFN0UyV2w3TGJJUEEyNlB4TzJYQ0RmdmowT1dwN2NFSmtVQkVpeVBZQ24raXVQWFVQd3Vkb0ZnTTRXSGYwSVBiREoyTzZPZ3pRbEJCbU51Nk93cjduYUlUaUpyUEF2YWtQZ0FkbVVQdjRyT3pjdTZCUjBUOEd3c3p3cHJ2d1dabEtGNkFkMDBvbUxGRG14NjZIdkJFNTFzUkJpWElSYkpuakRobG9waXplNExvUjFGSXJRYUF1MXNmczViRUh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ABmNhcmRzMgUAAAAGY2FyZHMzCQAAAgAAAAECAAAAEUluaXRHYW1lIFJlcXVpcmVkAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXnI2iCP", "height": 1877836, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Bx6s2W9sv91RCp19DALgsMeR5t43NJQC1ZZzZ68Ju6aE Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let gameMasterPublicKey = base58' | |
4 | + | let gameMasterPublicKey = base58'7Hi4o6vBstRs79NMVMjEove52dmP87RAcvNDAXN8C4Wi' | |
5 | 5 | ||
6 | - | let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi5zy1H6T2pQx7qgMph9s7/Wg819sob9AvQsGsc3Dzz5ZjTkhvNLQPf1wtQ+jVCIT8SAjgPVWWP3YI8ozGzKW49SqLiaSqmU5Gn4pjR9NYIqsNDJmX+9GMpF1dermPV5HEYxBMQ2NAkMsWA1XIYc/aIa0f/wVgMe209MUM2oUwyEKA1qAEJmsQkXCjJOAAkUQHi6HTyuoQqjt5OZloS+ix2wNyyftBj3wpNgQ8w+JaI6htg7Nml7/NeoukuIdtUSz9nJi4asGco9jYr7q0tgVDQl6NlBHMN6CNJahpPZN/YNAb+CzAitZGlNcWIawLFec1fZOO8hbaHTuQ843j6jVQIDAQAB") | |
7 | - | ||
8 | - | let gameToken = base58'AJRyxpsv9Z4v46eg9b5TpnVXn3DteJYPHRJSbMckYPWw' | |
6 | + | let RSAPUBLIC = fromBase64String("base64:MIIBIzANBgkqhkiG9w0BAQEFAAOCARAAMIIBCwKCAQIA+CpbzMBKpq+7VarSDHLW0wQSoh2LTbgl1rAhfruZGCjt6MO4o1v1iLqKyNH3FJsvwlLUqmqE7E2Wl7LbIPA26PxO2XCDfvj0OWp7cEJkUBEiyPYCn+iuPXUPwudoFgM4WHf0IPbDJ2O6OgzQlBBmNu6Owr7naITiJrPAvakPgAdmUPv4rOzcu6BR0T8GwszwprvwWZlKF6Ad00omLFDmx66HvBE51sRBiXIRbJnjDhlopize4LoR1FIrQaAu1sfs5bEHLA33jvKybne+IDawCsiINZYdPZV1WWcURC+XAFfBiYCw4PYyguxaBRHotzLc2dOsBV1HDNIjLKVoRknyt50CAwEAAQ==") | |
9 | 7 | ||
10 | 8 | let setupGamesCounterLabel = "G_SETUPGAMESCOUNTER" | |
11 | 9 | ||
15 | 13 | ||
16 | 14 | let gameMaxBetLabel = "G_MAXBET" | |
17 | 15 | ||
18 | - | let gameMinBetLabel = "G_MINBET" | |
19 | - | ||
20 | - | func gamesMaxBet () = getInteger(this, gameMaxBetLabel) | |
21 | - | ||
22 | - | ||
23 | - | func gamesMinBet () = getInteger(this, gameMinBetLabel) | |
24 | - | ||
25 | - | ||
26 | 16 | func gamesSetupGetCounter () = getInteger(this, setupGamesCounterLabel) | |
27 | 17 | ||
28 | 18 | ||
29 | 19 | func gamesUsedGetCounter () = getInteger(this, usedGamesCounterLabel) | |
30 | 20 | ||
31 | 21 | ||
32 | - | func getDealerQueue () = getString(this, dealerQueueLabel) | |
33 | - | ||
34 | - | ||
35 | 22 | func checkPermission (callerPublicKey) = (callerPublicKey != gameMasterPublicKey) | |
36 | 23 | ||
37 | 24 | ||
38 | - | func | |
25 | + | func getGameCardsSignatureLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARDSIGNATURE_") + toString(card)) | |
39 | 26 | ||
40 | 27 | ||
41 | - | func | |
28 | + | func getGameCardsSignature (gameNumber,card) = getString(this, getGameCardsSignatureLabel(gameNumber, card)) | |
42 | 29 | ||
43 | 30 | ||
44 | - | func getGamePlayerLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_PLAYER") | |
45 | - | ||
46 | - | ||
47 | - | func getGamePayoutLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_PAYOUT") | |
31 | + | func getGameCardsLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARD_") + toString(card)) | |
48 | 32 | ||
49 | 33 | ||
50 | 34 | func getGameStateLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_STATE") | |
53 | 37 | func getGameShuffelOffesetLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_OFFSET") | |
54 | 38 | ||
55 | 39 | ||
56 | - | func getGameCardsSignatureLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARDSIGNATURE_") + toString(card)) | |
57 | - | ||
58 | - | ||
59 | - | func getPlayerCurrentGameLabel (address) = (("P_" + address) + "_CURRENTGAME") | |
60 | - | ||
61 | - | ||
62 | - | func getPlayerCurrentGame (address) = getInteger(this, getPlayerCurrentGameLabel(address)) | |
63 | - | ||
64 | - | ||
65 | - | func getGameBetAmount (gameNumber) = getInteger(this, getGameBetAmountLabel(gameNumber)) | |
66 | - | ||
67 | - | ||
68 | - | func getGameTieAmount (gameNumber) = getInteger(this, getGameTieAmountLabel(gameNumber)) | |
69 | - | ||
70 | - | ||
71 | - | func getGameState (gameNumber) = getInteger(this, getGameStateLabel(gameNumber)) | |
72 | - | ||
73 | - | ||
74 | - | func getGamePlayer (gameNumber) = getString(this, getGamePlayerLabel(gameNumber)) | |
75 | - | ||
76 | - | ||
77 | - | func getGameCardsSignature (gameNumber,card) = getString(this, getGameCardsSignatureLabel(gameNumber, card)) | |
78 | - | ||
79 | - | ||
80 | - | func getGameCardsLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARD_") + toString(card)) | |
81 | - | ||
82 | - | ||
83 | 40 | func getGameSetup (gameNumber,randomizer,cards0,cards1,cards2,cards3) = [IntegerEntry(setupGamesCounterLabel, gameNumber), IntegerEntry(getGameStateLabel(gameNumber), 0), IntegerEntry(getGameShuffelOffesetLabel(gameNumber), randomizer), StringEntry(getGameCardsSignatureLabel(gameNumber, 0), cards0), StringEntry(getGameCardsSignatureLabel(gameNumber, 1), cards1), StringEntry(getGameCardsSignatureLabel(gameNumber, 2), cards2), StringEntry(getGameCardsSignatureLabel(gameNumber, 3), cards3)] | |
84 | 41 | ||
85 | 42 | ||
86 | - | func createGameMetadata (address,betAmount,tieAmount) = { | |
87 | - | let gameToReserve = (value(gamesUsedGetCounter()) + 1) | |
88 | - | let dealerQueue = value(getDealerQueue()) | |
89 | - | [IntegerEntry(usedGamesCounterLabel, gameToReserve), IntegerEntry(getPlayerCurrentGameLabel(address), gameToReserve), IntegerEntry(getGameStateLabel(gameToReserve), 1), IntegerEntry(getGameBetAmountLabel(gameToReserve), betAmount), IntegerEntry(getGameTieAmountLabel(gameToReserve), tieAmount), StringEntry(dealerQueueLabel, ((value(getDealerQueue()) + ",") + toString(gameToReserve))), StringEntry(getGamePlayerLabel(gameToReserve), address)] | |
90 | - | } | |
91 | - | ||
92 | - | ||
93 | - | func getCardValue (stringCard) = parseIntValue(take(stringCard, 2)) | |
94 | - | ||
95 | - | ||
96 | - | func getPayments (i) = if ((size(i.payments) == 0)) | |
97 | - | then throw("Payment must be attached") | |
98 | - | else if ((size(i.payments) == 1)) | |
99 | - | then { | |
100 | - | let pmt = i.payments[0] | |
101 | - | pmt.amount | |
102 | - | } | |
103 | - | else throw("There should be only one payment") | |
104 | - | ||
105 | - | ||
106 | - | func verifyCard (card,gameNumber,cardNumber) = rsaVerify_16Kb(SHA256, toBytes(card), fromBase64String(split(value(getGameCardsSignature(gameNumber, cardNumber)), " ")[0]), RSAPUBLIC) | |
107 | - | ||
108 | - | ||
109 | 43 | @Callable(i) | |
110 | - | func revealRound2 (currentGame,card2,card3) = if (checkPermission(i.callerPublicKey)) | |
111 | - | then throw("revealRound2_FORBBIDEN") | |
112 | - | else { | |
113 | - | let dealerQueue = value(getDealerQueue()) | |
114 | - | let nextGameToProcess = split(dealerQueue, ",")[1] | |
115 | - | if ((nextGameToProcess == toString(currentGame))) | |
116 | - | then if (if (if ((value(getGameState(currentGame)) == 3)) | |
117 | - | then verifyCard(card2, currentGame, 2) | |
118 | - | else false) | |
119 | - | then verifyCard(card3, currentGame, 3) | |
120 | - | else false) | |
121 | - | then { | |
122 | - | let cardPlayer = getCardValue(split(card2, "+")[2]) | |
123 | - | let cardCasino = getCardValue(split(card3, "+")[2]) | |
124 | - | if ((cardPlayer >= cardCasino)) | |
125 | - | then { | |
126 | - | let normalBet = value(getGameBetAmount(currentGame)) | |
127 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
128 | - | [StringEntry(getGameCardsLabel(currentGame, 2), card2), StringEntry(getGameCardsLabel(currentGame, 3), card3), IntegerEntry(getGameStateLabel(currentGame), 6), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, ((normalBet * 2) + (normalBet - i.fee)), unit)] | |
129 | - | } | |
130 | - | else [StringEntry(getGameCardsLabel(currentGame, 2), card2), StringEntry(getGameCardsLabel(currentGame, 3), card3), IntegerEntry(getGameStateLabel(currentGame), 6), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
131 | - | } | |
132 | - | else throw("One of the cards failed to be verified or game is not in state 1.") | |
133 | - | else throw(("The next game to process is " + nextGameToProcess)) | |
134 | - | } | |
135 | - | ||
136 | - | ||
137 | - | ||
138 | - | @Callable(i) | |
139 | - | func war () = { | |
140 | - | let address = toBase58String(i.caller.bytes) | |
141 | - | let currentGame = value(getPlayerCurrentGame(address)) | |
142 | - | if ((value(getGameState(currentGame)) != 2)) | |
143 | - | then throw("Game is not in correct state.") | |
144 | - | else { | |
145 | - | let betAmount = value(getGameBetAmount(currentGame)) | |
146 | - | let p = getPayments(i) | |
147 | - | if (((p + i.fee) != betAmount)) | |
148 | - | then throw((("Payment must me same as the original bet (" + toString(betAmount)) + ")")) | |
149 | - | else [IntegerEntry(getGameStateLabel(currentGame), 3), StringEntry(dealerQueueLabel, ((value(getDealerQueue()) + ",") + toString(currentGame)))] | |
150 | - | } | |
44 | + | func verifyCard (card,gameNumber,cardNumber) = { | |
45 | + | let t = rsaVerify_16Kb(SHA256, toBytes(card), fromBase64String(split(value(getGameCardsSignature(gameNumber, cardNumber)), " ")[0]), RSAPUBLIC) | |
46 | + | throw(toString(t)) | |
151 | 47 | } | |
152 | 48 | ||
153 | 49 | ||
154 | 50 | ||
155 | 51 | @Callable(i) | |
156 | - | func surrender () = { | |
157 | - | let address = toBase58String(i.caller.bytes) | |
158 | - | let currentGame = value(getPlayerCurrentGame(address)) | |
159 | - | if ((value(getGameState(currentGame)) != 2)) | |
160 | - | then throw("Game is not in correct state.") | |
161 | - | else { | |
162 | - | let betAmount = value(getGameBetAmount(currentGame)) | |
163 | - | let dealerQueue = value(getDealerQueue()) | |
164 | - | [IntegerEntry(getGameStateLabel(currentGame), 5), ScriptTransfer(i.caller, (betAmount / 2), unit)] | |
165 | - | } | |
52 | + | func initGame () = if (checkPermission(i.callerPublicKey)) | |
53 | + | then throw("initGame_FORBBIDEN") | |
54 | + | else match gamesSetupGetCounter() { | |
55 | + | case GAMESCOUNTER: Int => | |
56 | + | throw("INIT_ALREADY_DONE") | |
57 | + | case _ => | |
58 | + | [IntegerEntry(setupGamesCounterLabel, 0), IntegerEntry(usedGamesCounterLabel, 0), IntegerEntry(gameMaxBetLabel, 100000000), StringEntry(dealerQueueLabel, "")] | |
166 | 59 | } | |
167 | 60 | ||
168 | 61 | ||
169 | 62 | ||
170 | 63 | @Callable(i) | |
171 | - | func revealRound1 (currentGame,card0,card1) = if (checkPermission(i.callerPublicKey)) | |
172 | - | then throw("revealRound1_FORBBIDEN") | |
173 | - | else { | |
174 | - | let dealerQueue = value(getDealerQueue()) | |
175 | - | let nextGameToProcess = split(dealerQueue, ",")[1] | |
176 | - | if ((nextGameToProcess == toString(currentGame))) | |
177 | - | then if (if (if ((value(getGameState(currentGame)) == 1)) | |
178 | - | then verifyCard(card0, currentGame, 0) | |
179 | - | else false) | |
180 | - | then verifyCard(card1, currentGame, 1) | |
181 | - | else false) | |
182 | - | then { | |
183 | - | let cardPlayer = getCardValue(split(card0, "+")[2]) | |
184 | - | let cardCasino = getCardValue(split(card1, "+")[2]) | |
185 | - | if ((cardPlayer == cardCasino)) | |
186 | - | then { | |
187 | - | let tieBet = value(getGameTieAmount(currentGame)) | |
188 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
189 | - | if ((tieBet != 0)) | |
190 | - | then [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 2), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, ((tieBet * 10) + tieBet), unit)] | |
191 | - | else [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 2), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
192 | - | } | |
193 | - | else if ((cardPlayer > cardCasino)) | |
194 | - | then { | |
195 | - | let normalBet = value(getGameBetAmount(currentGame)) | |
196 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
197 | - | [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 4), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, normalBet, unit)] | |
198 | - | } | |
199 | - | else [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 4), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
200 | - | } | |
201 | - | else throw("One of the cards failed to be verified or game is not in state 1.") | |
202 | - | else throw(("The next game to process is " + nextGameToProcess)) | |
203 | - | } | |
204 | - | ||
205 | - | ||
206 | - | ||
207 | - | @Callable(i) | |
208 | - | func bet (normalBet,tieBet) = { | |
209 | - | let callerAddress = toBase58String(i.caller.bytes) | |
210 | - | let p = getPayments(i) | |
211 | - | let betAmount = (normalBet + i.fee) | |
212 | - | let tieAmount = tieBet | |
213 | - | let address = toBase58String(i.caller.bytes) | |
214 | - | if ((p != (normalBet + tieBet))) | |
215 | - | then throw("normal bet + tie bet should be equal to the payment") | |
216 | - | else if (if ((value(gamesMinBet()) > p)) | |
217 | - | then true | |
218 | - | else (p > value(gamesMaxBet()))) | |
219 | - | then throw((((("Payment needs to be in the following interval [" + toString(value(gamesMinBet()))) + " ") + toString(value(gamesMaxBet()))) + "]")) | |
220 | - | else if ((value(gamesUsedGetCounter()) >= value(gamesSetupGetCounter()))) | |
221 | - | then throw("No available set up games to use.") | |
222 | - | else match getPlayerCurrentGame(address) { | |
223 | - | case CURRENTGAME: Int => | |
224 | - | if ((4 > value(getGameState(CURRENTGAME)))) | |
225 | - | then throw((("Game " + toString(CURRENTGAME)) + " is still in progress.")) | |
226 | - | else createGameMetadata(address, betAmount, tieAmount) | |
227 | - | case _: Unit => | |
228 | - | createGameMetadata(address, betAmount, tieAmount) | |
229 | - | case _ => | |
230 | - | throw("Match error") | |
231 | - | } | |
232 | - | } | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func setupGame (gameNumber,card0,card1,card2,card3) = if (checkPermission(i.callerPublicKey)) | |
238 | - | then throw("setupGame_FORBBIDEN") | |
64 | + | func setupGame (gameNumber,cards0,cards1,cards2,cards3) = if (checkPermission(i.callerPublicKey)) | |
65 | + | then throw("setupGame_FORBIDEN") | |
239 | 66 | else match gamesSetupGetCounter() { | |
240 | 67 | case SETUPGAMESCOUNTER: Int => | |
241 | 68 | let randomizer = (toInt(sha256((take(lastBlock.generationSignature, 16) + take(i.transactionId, 16)))) % 2) | |
242 | 69 | let currentGame = (SETUPGAMESCOUNTER + 1) | |
243 | 70 | if ((gameNumber != currentGame)) | |
244 | 71 | then throw("Wrong game number.") | |
245 | - | else if (((randomizer % 2) == 1)) | |
246 | - | then getGameSetup(currentGame, randomizer, card3, card2, card1, card0) | |
247 | - | else getGameSetup(currentGame, randomizer, card0, card1, card2, card3) | |
72 | + | else getGameSetup(currentGame, randomizer, cards0, cards1, cards2, cards3) | |
248 | 73 | case _ => | |
249 | 74 | throw("InitGame Required") | |
250 | - | } | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(i) | |
255 | - | func initGame (maxBet,minBet) = if (checkPermission(i.callerPublicKey)) | |
256 | - | then throw("initGame_FORBBIDEN") | |
257 | - | else match gamesSetupGetCounter() { | |
258 | - | case GAMESCOUNTER: Int => | |
259 | - | throw("INIT_ALREADY_DONE") | |
260 | - | case _ => | |
261 | - | [IntegerEntry(setupGamesCounterLabel, 0), IntegerEntry(usedGamesCounterLabel, 0), IntegerEntry(gameMaxBetLabel, maxBet), IntegerEntry(gameMinBetLabel, minBet), StringEntry(dealerQueueLabel, "")] | |
262 | 75 | } | |
263 | 76 | ||
264 | 77 |
Old | New | Differences | |
---|---|---|---|
1 | - | {-# STDLIB_VERSION | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let gameMasterPublicKey = base58' | |
4 | + | let gameMasterPublicKey = base58'7Hi4o6vBstRs79NMVMjEove52dmP87RAcvNDAXN8C4Wi' | |
5 | 5 | ||
6 | - | let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi5zy1H6T2pQx7qgMph9s7/Wg819sob9AvQsGsc3Dzz5ZjTkhvNLQPf1wtQ+jVCIT8SAjgPVWWP3YI8ozGzKW49SqLiaSqmU5Gn4pjR9NYIqsNDJmX+9GMpF1dermPV5HEYxBMQ2NAkMsWA1XIYc/aIa0f/wVgMe209MUM2oUwyEKA1qAEJmsQkXCjJOAAkUQHi6HTyuoQqjt5OZloS+ix2wNyyftBj3wpNgQ8w+JaI6htg7Nml7/NeoukuIdtUSz9nJi4asGco9jYr7q0tgVDQl6NlBHMN6CNJahpPZN/YNAb+CzAitZGlNcWIawLFec1fZOO8hbaHTuQ843j6jVQIDAQAB") | |
7 | - | ||
8 | - | let gameToken = base58'AJRyxpsv9Z4v46eg9b5TpnVXn3DteJYPHRJSbMckYPWw' | |
6 | + | let RSAPUBLIC = fromBase64String("base64:MIIBIzANBgkqhkiG9w0BAQEFAAOCARAAMIIBCwKCAQIA+CpbzMBKpq+7VarSDHLW0wQSoh2LTbgl1rAhfruZGCjt6MO4o1v1iLqKyNH3FJsvwlLUqmqE7E2Wl7LbIPA26PxO2XCDfvj0OWp7cEJkUBEiyPYCn+iuPXUPwudoFgM4WHf0IPbDJ2O6OgzQlBBmNu6Owr7naITiJrPAvakPgAdmUPv4rOzcu6BR0T8GwszwprvwWZlKF6Ad00omLFDmx66HvBE51sRBiXIRbJnjDhlopize4LoR1FIrQaAu1sfs5bEHLA33jvKybne+IDawCsiINZYdPZV1WWcURC+XAFfBiYCw4PYyguxaBRHotzLc2dOsBV1HDNIjLKVoRknyt50CAwEAAQ==") | |
9 | 7 | ||
10 | 8 | let setupGamesCounterLabel = "G_SETUPGAMESCOUNTER" | |
11 | 9 | ||
12 | 10 | let usedGamesCounterLabel = "G_USEDGAMESCOUNTER" | |
13 | 11 | ||
14 | 12 | let dealerQueueLabel = "G_DEALERQUEUE" | |
15 | 13 | ||
16 | 14 | let gameMaxBetLabel = "G_MAXBET" | |
17 | 15 | ||
18 | - | let gameMinBetLabel = "G_MINBET" | |
19 | - | ||
20 | - | func gamesMaxBet () = getInteger(this, gameMaxBetLabel) | |
21 | - | ||
22 | - | ||
23 | - | func gamesMinBet () = getInteger(this, gameMinBetLabel) | |
24 | - | ||
25 | - | ||
26 | 16 | func gamesSetupGetCounter () = getInteger(this, setupGamesCounterLabel) | |
27 | 17 | ||
28 | 18 | ||
29 | 19 | func gamesUsedGetCounter () = getInteger(this, usedGamesCounterLabel) | |
30 | 20 | ||
31 | 21 | ||
32 | - | func getDealerQueue () = getString(this, dealerQueueLabel) | |
33 | - | ||
34 | - | ||
35 | 22 | func checkPermission (callerPublicKey) = (callerPublicKey != gameMasterPublicKey) | |
36 | 23 | ||
37 | 24 | ||
38 | - | func | |
25 | + | func getGameCardsSignatureLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARDSIGNATURE_") + toString(card)) | |
39 | 26 | ||
40 | 27 | ||
41 | - | func | |
28 | + | func getGameCardsSignature (gameNumber,card) = getString(this, getGameCardsSignatureLabel(gameNumber, card)) | |
42 | 29 | ||
43 | 30 | ||
44 | - | func getGamePlayerLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_PLAYER") | |
45 | - | ||
46 | - | ||
47 | - | func getGamePayoutLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_PAYOUT") | |
31 | + | func getGameCardsLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARD_") + toString(card)) | |
48 | 32 | ||
49 | 33 | ||
50 | 34 | func getGameStateLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_STATE") | |
51 | 35 | ||
52 | 36 | ||
53 | 37 | func getGameShuffelOffesetLabel (gameNumber) = (("G_" + toString(gameNumber)) + "_OFFSET") | |
54 | 38 | ||
55 | 39 | ||
56 | - | func getGameCardsSignatureLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARDSIGNATURE_") + toString(card)) | |
57 | - | ||
58 | - | ||
59 | - | func getPlayerCurrentGameLabel (address) = (("P_" + address) + "_CURRENTGAME") | |
60 | - | ||
61 | - | ||
62 | - | func getPlayerCurrentGame (address) = getInteger(this, getPlayerCurrentGameLabel(address)) | |
63 | - | ||
64 | - | ||
65 | - | func getGameBetAmount (gameNumber) = getInteger(this, getGameBetAmountLabel(gameNumber)) | |
66 | - | ||
67 | - | ||
68 | - | func getGameTieAmount (gameNumber) = getInteger(this, getGameTieAmountLabel(gameNumber)) | |
69 | - | ||
70 | - | ||
71 | - | func getGameState (gameNumber) = getInteger(this, getGameStateLabel(gameNumber)) | |
72 | - | ||
73 | - | ||
74 | - | func getGamePlayer (gameNumber) = getString(this, getGamePlayerLabel(gameNumber)) | |
75 | - | ||
76 | - | ||
77 | - | func getGameCardsSignature (gameNumber,card) = getString(this, getGameCardsSignatureLabel(gameNumber, card)) | |
78 | - | ||
79 | - | ||
80 | - | func getGameCardsLabel (gameNumber,card) = ((("G_" + toString(gameNumber)) + "_CARD_") + toString(card)) | |
81 | - | ||
82 | - | ||
83 | 40 | func getGameSetup (gameNumber,randomizer,cards0,cards1,cards2,cards3) = [IntegerEntry(setupGamesCounterLabel, gameNumber), IntegerEntry(getGameStateLabel(gameNumber), 0), IntegerEntry(getGameShuffelOffesetLabel(gameNumber), randomizer), StringEntry(getGameCardsSignatureLabel(gameNumber, 0), cards0), StringEntry(getGameCardsSignatureLabel(gameNumber, 1), cards1), StringEntry(getGameCardsSignatureLabel(gameNumber, 2), cards2), StringEntry(getGameCardsSignatureLabel(gameNumber, 3), cards3)] | |
84 | 41 | ||
85 | 42 | ||
86 | - | func createGameMetadata (address,betAmount,tieAmount) = { | |
87 | - | let gameToReserve = (value(gamesUsedGetCounter()) + 1) | |
88 | - | let dealerQueue = value(getDealerQueue()) | |
89 | - | [IntegerEntry(usedGamesCounterLabel, gameToReserve), IntegerEntry(getPlayerCurrentGameLabel(address), gameToReserve), IntegerEntry(getGameStateLabel(gameToReserve), 1), IntegerEntry(getGameBetAmountLabel(gameToReserve), betAmount), IntegerEntry(getGameTieAmountLabel(gameToReserve), tieAmount), StringEntry(dealerQueueLabel, ((value(getDealerQueue()) + ",") + toString(gameToReserve))), StringEntry(getGamePlayerLabel(gameToReserve), address)] | |
90 | - | } | |
91 | - | ||
92 | - | ||
93 | - | func getCardValue (stringCard) = parseIntValue(take(stringCard, 2)) | |
94 | - | ||
95 | - | ||
96 | - | func getPayments (i) = if ((size(i.payments) == 0)) | |
97 | - | then throw("Payment must be attached") | |
98 | - | else if ((size(i.payments) == 1)) | |
99 | - | then { | |
100 | - | let pmt = i.payments[0] | |
101 | - | pmt.amount | |
102 | - | } | |
103 | - | else throw("There should be only one payment") | |
104 | - | ||
105 | - | ||
106 | - | func verifyCard (card,gameNumber,cardNumber) = rsaVerify_16Kb(SHA256, toBytes(card), fromBase64String(split(value(getGameCardsSignature(gameNumber, cardNumber)), " ")[0]), RSAPUBLIC) | |
107 | - | ||
108 | - | ||
109 | 43 | @Callable(i) | |
110 | - | func revealRound2 (currentGame,card2,card3) = if (checkPermission(i.callerPublicKey)) | |
111 | - | then throw("revealRound2_FORBBIDEN") | |
112 | - | else { | |
113 | - | let dealerQueue = value(getDealerQueue()) | |
114 | - | let nextGameToProcess = split(dealerQueue, ",")[1] | |
115 | - | if ((nextGameToProcess == toString(currentGame))) | |
116 | - | then if (if (if ((value(getGameState(currentGame)) == 3)) | |
117 | - | then verifyCard(card2, currentGame, 2) | |
118 | - | else false) | |
119 | - | then verifyCard(card3, currentGame, 3) | |
120 | - | else false) | |
121 | - | then { | |
122 | - | let cardPlayer = getCardValue(split(card2, "+")[2]) | |
123 | - | let cardCasino = getCardValue(split(card3, "+")[2]) | |
124 | - | if ((cardPlayer >= cardCasino)) | |
125 | - | then { | |
126 | - | let normalBet = value(getGameBetAmount(currentGame)) | |
127 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
128 | - | [StringEntry(getGameCardsLabel(currentGame, 2), card2), StringEntry(getGameCardsLabel(currentGame, 3), card3), IntegerEntry(getGameStateLabel(currentGame), 6), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, ((normalBet * 2) + (normalBet - i.fee)), unit)] | |
129 | - | } | |
130 | - | else [StringEntry(getGameCardsLabel(currentGame, 2), card2), StringEntry(getGameCardsLabel(currentGame, 3), card3), IntegerEntry(getGameStateLabel(currentGame), 6), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
131 | - | } | |
132 | - | else throw("One of the cards failed to be verified or game is not in state 1.") | |
133 | - | else throw(("The next game to process is " + nextGameToProcess)) | |
134 | - | } | |
135 | - | ||
136 | - | ||
137 | - | ||
138 | - | @Callable(i) | |
139 | - | func war () = { | |
140 | - | let address = toBase58String(i.caller.bytes) | |
141 | - | let currentGame = value(getPlayerCurrentGame(address)) | |
142 | - | if ((value(getGameState(currentGame)) != 2)) | |
143 | - | then throw("Game is not in correct state.") | |
144 | - | else { | |
145 | - | let betAmount = value(getGameBetAmount(currentGame)) | |
146 | - | let p = getPayments(i) | |
147 | - | if (((p + i.fee) != betAmount)) | |
148 | - | then throw((("Payment must me same as the original bet (" + toString(betAmount)) + ")")) | |
149 | - | else [IntegerEntry(getGameStateLabel(currentGame), 3), StringEntry(dealerQueueLabel, ((value(getDealerQueue()) + ",") + toString(currentGame)))] | |
150 | - | } | |
44 | + | func verifyCard (card,gameNumber,cardNumber) = { | |
45 | + | let t = rsaVerify_16Kb(SHA256, toBytes(card), fromBase64String(split(value(getGameCardsSignature(gameNumber, cardNumber)), " ")[0]), RSAPUBLIC) | |
46 | + | throw(toString(t)) | |
151 | 47 | } | |
152 | 48 | ||
153 | 49 | ||
154 | 50 | ||
155 | 51 | @Callable(i) | |
156 | - | func surrender () = { | |
157 | - | let address = toBase58String(i.caller.bytes) | |
158 | - | let currentGame = value(getPlayerCurrentGame(address)) | |
159 | - | if ((value(getGameState(currentGame)) != 2)) | |
160 | - | then throw("Game is not in correct state.") | |
161 | - | else { | |
162 | - | let betAmount = value(getGameBetAmount(currentGame)) | |
163 | - | let dealerQueue = value(getDealerQueue()) | |
164 | - | [IntegerEntry(getGameStateLabel(currentGame), 5), ScriptTransfer(i.caller, (betAmount / 2), unit)] | |
165 | - | } | |
52 | + | func initGame () = if (checkPermission(i.callerPublicKey)) | |
53 | + | then throw("initGame_FORBBIDEN") | |
54 | + | else match gamesSetupGetCounter() { | |
55 | + | case GAMESCOUNTER: Int => | |
56 | + | throw("INIT_ALREADY_DONE") | |
57 | + | case _ => | |
58 | + | [IntegerEntry(setupGamesCounterLabel, 0), IntegerEntry(usedGamesCounterLabel, 0), IntegerEntry(gameMaxBetLabel, 100000000), StringEntry(dealerQueueLabel, "")] | |
166 | 59 | } | |
167 | 60 | ||
168 | 61 | ||
169 | 62 | ||
170 | 63 | @Callable(i) | |
171 | - | func revealRound1 (currentGame,card0,card1) = if (checkPermission(i.callerPublicKey)) | |
172 | - | then throw("revealRound1_FORBBIDEN") | |
173 | - | else { | |
174 | - | let dealerQueue = value(getDealerQueue()) | |
175 | - | let nextGameToProcess = split(dealerQueue, ",")[1] | |
176 | - | if ((nextGameToProcess == toString(currentGame))) | |
177 | - | then if (if (if ((value(getGameState(currentGame)) == 1)) | |
178 | - | then verifyCard(card0, currentGame, 0) | |
179 | - | else false) | |
180 | - | then verifyCard(card1, currentGame, 1) | |
181 | - | else false) | |
182 | - | then { | |
183 | - | let cardPlayer = getCardValue(split(card0, "+")[2]) | |
184 | - | let cardCasino = getCardValue(split(card1, "+")[2]) | |
185 | - | if ((cardPlayer == cardCasino)) | |
186 | - | then { | |
187 | - | let tieBet = value(getGameTieAmount(currentGame)) | |
188 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
189 | - | if ((tieBet != 0)) | |
190 | - | then [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 2), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, ((tieBet * 10) + tieBet), unit)] | |
191 | - | else [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 2), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
192 | - | } | |
193 | - | else if ((cardPlayer > cardCasino)) | |
194 | - | then { | |
195 | - | let normalBet = value(getGameBetAmount(currentGame)) | |
196 | - | let address = value(addressFromString(value(getGamePlayer(currentGame)))) | |
197 | - | [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 4), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame)))))), ScriptTransfer(address, normalBet, unit)] | |
198 | - | } | |
199 | - | else [StringEntry(getGameCardsLabel(currentGame, 0), card0), StringEntry(getGameCardsLabel(currentGame, 1), card1), IntegerEntry(getGameStateLabel(currentGame), 4), StringEntry(dealerQueueLabel, takeRight(dealerQueue, (size(dealerQueue) - (1 + size(toString(currentGame))))))] | |
200 | - | } | |
201 | - | else throw("One of the cards failed to be verified or game is not in state 1.") | |
202 | - | else throw(("The next game to process is " + nextGameToProcess)) | |
203 | - | } | |
204 | - | ||
205 | - | ||
206 | - | ||
207 | - | @Callable(i) | |
208 | - | func bet (normalBet,tieBet) = { | |
209 | - | let callerAddress = toBase58String(i.caller.bytes) | |
210 | - | let p = getPayments(i) | |
211 | - | let betAmount = (normalBet + i.fee) | |
212 | - | let tieAmount = tieBet | |
213 | - | let address = toBase58String(i.caller.bytes) | |
214 | - | if ((p != (normalBet + tieBet))) | |
215 | - | then throw("normal bet + tie bet should be equal to the payment") | |
216 | - | else if (if ((value(gamesMinBet()) > p)) | |
217 | - | then true | |
218 | - | else (p > value(gamesMaxBet()))) | |
219 | - | then throw((((("Payment needs to be in the following interval [" + toString(value(gamesMinBet()))) + " ") + toString(value(gamesMaxBet()))) + "]")) | |
220 | - | else if ((value(gamesUsedGetCounter()) >= value(gamesSetupGetCounter()))) | |
221 | - | then throw("No available set up games to use.") | |
222 | - | else match getPlayerCurrentGame(address) { | |
223 | - | case CURRENTGAME: Int => | |
224 | - | if ((4 > value(getGameState(CURRENTGAME)))) | |
225 | - | then throw((("Game " + toString(CURRENTGAME)) + " is still in progress.")) | |
226 | - | else createGameMetadata(address, betAmount, tieAmount) | |
227 | - | case _: Unit => | |
228 | - | createGameMetadata(address, betAmount, tieAmount) | |
229 | - | case _ => | |
230 | - | throw("Match error") | |
231 | - | } | |
232 | - | } | |
233 | - | ||
234 | - | ||
235 | - | ||
236 | - | @Callable(i) | |
237 | - | func setupGame (gameNumber,card0,card1,card2,card3) = if (checkPermission(i.callerPublicKey)) | |
238 | - | then throw("setupGame_FORBBIDEN") | |
64 | + | func setupGame (gameNumber,cards0,cards1,cards2,cards3) = if (checkPermission(i.callerPublicKey)) | |
65 | + | then throw("setupGame_FORBIDEN") | |
239 | 66 | else match gamesSetupGetCounter() { | |
240 | 67 | case SETUPGAMESCOUNTER: Int => | |
241 | 68 | let randomizer = (toInt(sha256((take(lastBlock.generationSignature, 16) + take(i.transactionId, 16)))) % 2) | |
242 | 69 | let currentGame = (SETUPGAMESCOUNTER + 1) | |
243 | 70 | if ((gameNumber != currentGame)) | |
244 | 71 | then throw("Wrong game number.") | |
245 | - | else if (((randomizer % 2) == 1)) | |
246 | - | then getGameSetup(currentGame, randomizer, card3, card2, card1, card0) | |
247 | - | else getGameSetup(currentGame, randomizer, card0, card1, card2, card3) | |
72 | + | else getGameSetup(currentGame, randomizer, cards0, cards1, cards2, cards3) | |
248 | 73 | case _ => | |
249 | 74 | throw("InitGame Required") | |
250 | - | } | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(i) | |
255 | - | func initGame (maxBet,minBet) = if (checkPermission(i.callerPublicKey)) | |
256 | - | then throw("initGame_FORBBIDEN") | |
257 | - | else match gamesSetupGetCounter() { | |
258 | - | case GAMESCOUNTER: Int => | |
259 | - | throw("INIT_ALREADY_DONE") | |
260 | - | case _ => | |
261 | - | [IntegerEntry(setupGamesCounterLabel, 0), IntegerEntry(usedGamesCounterLabel, 0), IntegerEntry(gameMaxBetLabel, maxBet), IntegerEntry(gameMinBetLabel, minBet), StringEntry(dealerQueueLabel, "")] | |
262 | 75 | } | |
263 | 76 | ||
264 | 77 | ||
265 | 78 | @Verifier(tx) | |
266 | 79 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
267 | 80 |
github/deemru/w8io/026f985 36.01 ms ◑