tx · SdbTsCAiPk8fsrHpmZBw4vnWT7PuWxbpYu8kK1Ysxim 3MsGBnTzBhrNe6w1KpLYPkzdDdxWudm4U89: -0.01400000 Waves 2019.08.21 09:36 [640528] smart account 3MsGBnTzBhrNe6w1KpLYPkzdDdxWudm4U89 > SELF 0.00000000 Waves
{ "type": 13, "id": "SdbTsCAiPk8fsrHpmZBw4vnWT7PuWxbpYu8kK1Ysxim", "fee": 1400000, "feeAssetId": null, "timestamp": 1566369422779, "version": 1, "sender": "3MsGBnTzBhrNe6w1KpLYPkzdDdxWudm4U89", "senderPublicKey": "FgbqvGasMMrXxbhwrsgEiCgJLjXPjgn8kHxsZiVmLrkb", "proofs": [ "eEcjgH8WVdveHJtyYHh3bAAKU1vHvFxFZQZXPzUA8B7KJJj2kGoEJTueYw6tnRuBXnpZ7BcyxdiU9Xqsgh1fNXN" ], "script": "base64:AAIDAAAAAAAAAAAAAAAgAAAAAAlSU0FQVUJMSUMJAAJbAAAAAQIAAAGPYmFzZTY0Ok1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBbGVtcjk1SjFqWlVzN2NKbXJtbWxONHpvN1lWc0JKekllSmRrOExERkdoVUtTSTZ5ZnMyMFp5SmUyMSs2R0p3Tm5LVVUxVXlvYzE3d1NXTUtrclowTU12WUUrWjVBaWlqdkJLNHNTSjNJZ0dqZFU4L05oSThDQkR1MEYreFJNOXEzVEIzTExiRHk1c0JkdWRZZkhmc1VPYytNVHZBRDY5bjI3ZGIyUmg4K3laUU10dWJrdVRRTnA4OXNwaEhRYUxHeVFGYU5sSy9OYTNsRng2b21xemFhMWdqb3BsVXI2cnZZS2dmQUlDVUIzelZtSlNoaUVpN3c3UjBoV2xOUkQzcWNaakNVT05TcEZvNFdiemtuR09henc4NEIrSU1JRm5JcFhXelFMOFJYMHZOY2ZzQnZMRGZNNmsyWmFjcXd5TUthTExxaWdkQmlHZEo3VyswbE9TdE9RSURBUUFCAAAAABNSQU5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TU4BQAAAAZoZWlnaHQFAAAABndpbkFtdAIAAAAABAAAAAZTRVJWRVIJAQAAABRhZGRyZXNzRnJvbVB1YmxpY0tleQAAAAEIBQAAAAFpAAAAD2NhbGxlclB1YmxpY0tleQQAAAAOc2VydmVyVHJhbnNmZXIJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwUAAAAGU0VSVkVSBQAAAApDT01NSVNTSU9OBQAAAAR1bml0BQAAAANuaWwEAAAAB2JldERhdGEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAADlJFU0VSVkFUSU9OS0VZCQEAAAAeVmFsaWRhdGVBbmRJbmNyZWFzZVJlc2VydmVkQW10AAAAAQUAAAAGd2luQW10CQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACBQAAAA9HQU1FU0NPVU5URVJLRVkFAAAACm5ld0dhbWVOdW0JAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAABmdhbWVJZAUAAAALZ2FtZURhdGFTdHIFAAAAA25pbAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEFAAAAB2JldERhdGEJAQAAAAtUcmFuc2ZlclNldAAAAAEFAAAADnNlcnZlclRyYW5zZmVyAAAAAOoVkbk=", "chainId": 84, "height": 640528, "spentComplexity": 0 } View: original | compacted Prev: BNcRqiYRNYBGqzkZaopEacSxP3vhDjJzmoviHtJgFk8G Next: FZaVVwuudjyPinYPnh2twVyVoL6EezfDWF72xkYXN69a Diff:
Old | New | Differences | |
---|---|---|---|
19 | 19 | ||
20 | 20 | let BET14 = (14 * WAVELET) | |
21 | 21 | ||
22 | + | let RATEMULT = 10000 | |
23 | + | ||
24 | + | let RATE1 = 39655 | |
25 | + | ||
26 | + | let RATE2 = 24600 | |
27 | + | ||
28 | + | let RATE3 = 19000 | |
29 | + | ||
30 | + | let RATE4 = 14200 | |
31 | + | ||
32 | + | let RATE5 = 11400 | |
33 | + | ||
34 | + | let GAMESCOUNTERKEY = "$GAME_NUM" | |
35 | + | ||
22 | 36 | let RESERVATIONKEY = "$RESERVED_AMOUNT" | |
37 | + | ||
38 | + | let STATESUBMITTED = "SUBMITTED" | |
39 | + | ||
40 | + | let STATEWON = "WON" | |
41 | + | ||
42 | + | let STATELOST = "LOST" | |
23 | 43 | ||
24 | 44 | func getAnswer (playerChoice) = BET14 | |
25 | 45 | ||
85 | 105 | } | |
86 | 106 | ||
87 | 107 | ||
88 | - | @Callable(i) | |
89 | - | func bet (playerChoice) = { | |
90 | - | let playerAddress = toBase58String(i.caller.bytes) | |
91 | - | let answer = getAnswer(playerChoice) | |
92 | - | let amount = i.payment | |
108 | + | func ValidateAndIncreaseReservedAmt (winAmt) = { | |
109 | + | let newReservedAmount = (ExtractReservedAmt() + winAmt) | |
93 | 110 | let balance = wavesBalance(this) | |
94 | - | let game = [DataEntry((playerAddress + " это Ставка Игрока"), playerChoice), DataEntry("Ответ Сервера", answer), DataEntry("Текущий баланс игры", balance), DataEntry("Номер текущего блока", height), DataEntry("Bytes блокчейн игры", this.bytes)] | |
95 | - | let playerAddressTx = Address(i.caller.bytes) | |
96 | - | let tSetCommonData = [ScriptTransfer(playerAddressTx, 10, unit)] | |
97 | - | ScriptResult(WriteSet(game), TransferSet(tSetCommonData)) | |
111 | + | if ((newReservedAmount > balance)) | |
112 | + | then throw("Insufficient funds on Russian Roulette account. Transaction was rejected for your safety.") | |
113 | + | else newReservedAmount | |
98 | 114 | } | |
99 | 115 | ||
100 | 116 | ||
101 | - | ||
102 | - | @Callable(i) | |
103 | - | func withdraw (amount) = { | |
104 | - | let currentKey = toBase58String(i.caller.bytes) | |
105 | - | let currentAmount = match getInteger(this, currentKey) { | |
106 | - | case a: Int => | |
107 | - | a | |
117 | + | func IncrementGameNum () = { | |
118 | + | let gameNum = match getInteger(this, GAMESCOUNTERKEY) { | |
119 | + | case num: Int => | |
120 | + | num | |
108 | 121 | case _ => | |
109 | 122 | 0 | |
110 | 123 | } | |
111 | - | let newAmount = (currentAmount - amount) | |
112 | - | if ((0 > amount)) | |
113 | - | then throw("Can't withdraw negative amount") | |
114 | - | else if ((0 > newAmount)) | |
115 | - | then throw("Not enough balance") | |
116 | - | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) | |
124 | + | (gameNum + 1) | |
117 | 125 | } | |
118 | 126 | ||
119 | 127 | ||
120 | - | ||
121 | - | ||
122 | - | | |
123 | - | | |
124 | - | | |
125 | - | | |
126 | - | | |
127 | - | | |
128 | - | | |
128 | + | func FormatGameDataParam (p) = { | |
129 | + | let s = size(p) | |
130 | + | if ((s == 0)) | |
131 | + | then throw("Parameter size must be greater then 0") | |
132 | + | else if ((s > 99)) | |
133 | + | then throw("Parameter size must be less then 100") | |
134 | + | else if ((10 > s)) | |
135 | + | then (("0" + toString(s)) + p) | |
136 | + | else (toString(s) + p) | |
129 | 137 | } | |
130 | - | else false | |
138 | + | ||
139 | + | ||
140 | + | func FormatGameDataStr (gameState,playerChoice,playerPubKey58,startedHeight,winAmt,randOrEmpty) = { | |
141 | + | let fullStateStr = ((((((((FormatGameDataParam(gameState) + "_") + FormatGameDataParam(playerChoice)) + "_") + FormatGameDataParam(playerPubKey58)) + "_") + FormatGameDataParam(toString(startedHeight))) + "_") + FormatGameDataParam(toString(winAmt))) | |
142 | + | if ((randOrEmpty == "")) | |
143 | + | then fullStateStr | |
144 | + | else ((fullStateStr + "_") + FormatGameDataParam(randOrEmpty)) | |
145 | + | } | |
146 | + | ||
147 | + | ||
148 | + | func ValidateBetAndDefineWinAmt (betAmt,playerChoice) = { | |
149 | + | let betAmtValid = if (if (if (if (if ((betAmt == (BET1 + COMMISSION))) | |
150 | + | then true | |
151 | + | else (betAmt == (BET2 + COMMISSION))) | |
152 | + | then true | |
153 | + | else (betAmt == (BET4 + COMMISSION))) | |
154 | + | then true | |
155 | + | else (betAmt == (BET8 + COMMISSION))) | |
156 | + | then true | |
157 | + | else (betAmt == (BET14 + COMMISSION))) | |
158 | + | then true | |
159 | + | else false | |
160 | + | if (betAmtValid) | |
161 | + | then { | |
162 | + | let bulletsCount = size(playerChoice) | |
163 | + | let bet = (betAmt - COMMISSION) | |
164 | + | if ((bulletsCount == 5)) | |
165 | + | then ((bet * RATE1) / RATEMULT) | |
166 | + | else if ((bulletsCount == 4)) | |
167 | + | then ((bet * RATE2) / RATEMULT) | |
168 | + | else if ((bulletsCount == 3)) | |
169 | + | then ((bet * RATE3) / RATEMULT) | |
170 | + | else if ((bulletsCount == 2)) | |
171 | + | then ((bet * RATE4) / RATEMULT) | |
172 | + | else if ((bulletsCount == 1)) | |
173 | + | then ((bet * RATE5) / RATEMULT) | |
174 | + | else throw("Invalid bullets in player's choice") | |
175 | + | } | |
176 | + | else throw("Bet amount is not in range") | |
177 | + | } | |
178 | + | ||
179 | + | ||
180 | + | @Callable(i) | |
181 | + | func bet (playerChoice) = { | |
182 | + | let newGameNum = IncrementGameNum() | |
183 | + | let gameId = toBase58String(i.transactionId) | |
184 | + | let pmt = extract(i.payment) | |
185 | + | let betNotInWaves = isDefined(pmt.assetId) | |
186 | + | let feeNotInWaves = isDefined(pmt.assetId) | |
187 | + | let winAmt = ValidateBetAndDefineWinAmt(pmt.amount, playerChoice) | |
188 | + | let txIdUsed = isDefined(getString(this, gameId)) | |
189 | + | if (betNotInWaves) | |
190 | + | then throw("Bet amount must be in Waves") | |
191 | + | else if (feeNotInWaves) | |
192 | + | then throw("Transaction's fee must be in Waves") | |
193 | + | else if (txIdUsed) | |
194 | + | then throw("Passed txId had been used before. Game aborted.") | |
195 | + | else { | |
196 | + | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
197 | + | let gameDataStr = FormatGameDataStr(STATESUBMITTED, playerChoice, playerPubKey58, height, winAmt, "") | |
198 | + | let SERVER = addressFromPublicKey(i.callerPublicKey) | |
199 | + | let serverTransfer = [ScriptTransfer(SERVER, COMMISSION, unit)] | |
200 | + | let betData = [DataEntry(RESERVATIONKEY, ValidateAndIncreaseReservedAmt(winAmt)), DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)] | |
201 | + | ScriptResult(WriteSet(betData), TransferSet(serverTransfer)) | |
202 | + | } | |
203 | + | } | |
204 | + | ||
131 | 205 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlemr95J1jZUs7cJmrmmlN4zo7YVsBJzIeJdk8LDFGhUKSI6yfs20ZyJe21+6GJwNnKUU1Uyoc17wSWMKkrZ0MMvYE+Z5AiijvBK4sSJ3IgGjdU8/NhI8CBDu0F+xRM9q3TB3LLbDy5sBdudYfHfsUOc+MTvAD69n27db2Rh8+yZQMtubkuTQNp89sphHQaLGyQFaNlK/Na3lFx6omqzaa1gjoplUr6rvYKgfAICUB3zVmJShiEi7w7R0hWlNRD3qcZjCUONSpFo4WbzknGOazw84B+IMIFnIpXWzQL8RX0vNcfsBvLDfM6k2ZacqwyMKaLLqigdBiGdJ7W+0lOStOQIDAQAB") | |
5 | 5 | ||
6 | 6 | let RANDORACLETIMEFRAME = 4320 | |
7 | 7 | ||
8 | 8 | let WAVELET = ((100 * 1000) * 1000) | |
9 | 9 | ||
10 | 10 | let COMMISSION = ((5 * WAVELET) / 1000) | |
11 | 11 | ||
12 | 12 | let BET1 = (1 * WAVELET) | |
13 | 13 | ||
14 | 14 | let BET2 = (2 * WAVELET) | |
15 | 15 | ||
16 | 16 | let BET4 = (4 * WAVELET) | |
17 | 17 | ||
18 | 18 | let BET8 = (8 * WAVELET) | |
19 | 19 | ||
20 | 20 | let BET14 = (14 * WAVELET) | |
21 | 21 | ||
22 | + | let RATEMULT = 10000 | |
23 | + | ||
24 | + | let RATE1 = 39655 | |
25 | + | ||
26 | + | let RATE2 = 24600 | |
27 | + | ||
28 | + | let RATE3 = 19000 | |
29 | + | ||
30 | + | let RATE4 = 14200 | |
31 | + | ||
32 | + | let RATE5 = 11400 | |
33 | + | ||
34 | + | let GAMESCOUNTERKEY = "$GAME_NUM" | |
35 | + | ||
22 | 36 | let RESERVATIONKEY = "$RESERVED_AMOUNT" | |
37 | + | ||
38 | + | let STATESUBMITTED = "SUBMITTED" | |
39 | + | ||
40 | + | let STATEWON = "WON" | |
41 | + | ||
42 | + | let STATELOST = "LOST" | |
23 | 43 | ||
24 | 44 | func getAnswer (playerChoice) = BET14 | |
25 | 45 | ||
26 | 46 | ||
27 | 47 | func GenerateRandInt (gameId,rsaSign) = { | |
28 | 48 | let rsaSigValid = rsaVerify(SHA256, toBytes(gameId), rsaSign, RSAPUBLIC) | |
29 | 49 | if (rsaSigValid) | |
30 | 50 | then { | |
31 | 51 | let rand = (toInt(sha256(rsaSign)) % 6) | |
32 | 52 | if ((0 > rand)) | |
33 | 53 | then (-1 * rand) | |
34 | 54 | else rand | |
35 | 55 | } | |
36 | 56 | else throw("Invalid RSA signature") | |
37 | 57 | } | |
38 | 58 | ||
39 | 59 | ||
40 | 60 | func RemoveUnderscoreIfPresent (remaining) = if ((size(remaining) > 0)) | |
41 | 61 | then drop(remaining, 1) | |
42 | 62 | else remaining | |
43 | 63 | ||
44 | 64 | ||
45 | 65 | func ParseNextAttribute (remaining) = { | |
46 | 66 | let s = size(remaining) | |
47 | 67 | if ((s > 0)) | |
48 | 68 | then { | |
49 | 69 | let nn = parseIntValue(take(remaining, 2)) | |
50 | 70 | let v = take(drop(remaining, 2), nn) | |
51 | 71 | let tmpRemaining = drop(remaining, (nn + 2)) | |
52 | 72 | let remainingState = RemoveUnderscoreIfPresent(tmpRemaining) | |
53 | 73 | [v, remainingState] | |
54 | 74 | } | |
55 | 75 | else throw("Empty string was passed into parseNextAttribute func") | |
56 | 76 | } | |
57 | 77 | ||
58 | 78 | ||
59 | 79 | func ParseGameRawDataStr (rawStateStr) = { | |
60 | 80 | let gameState = ParseNextAttribute(rawStateStr) | |
61 | 81 | let playerChoice = ParseNextAttribute(gameState[1]) | |
62 | 82 | let playerPubKey58 = ParseNextAttribute(playerChoice[1]) | |
63 | 83 | let startedHeight = ParseNextAttribute(playerPubKey58[1]) | |
64 | 84 | let winAmt = ParseNextAttribute(startedHeight[1]) | |
65 | 85 | [gameState[0], playerChoice[0], playerPubKey58[0], startedHeight[0], winAmt[0]] | |
66 | 86 | } | |
67 | 87 | ||
68 | 88 | ||
69 | 89 | func ExtractGameDataList (gameId) = { | |
70 | 90 | let rawDataStr = match getString(this, gameId) { | |
71 | 91 | case str: String => | |
72 | 92 | str | |
73 | 93 | case _ => | |
74 | 94 | throw(("Couldn't find game by " + gameId)) | |
75 | 95 | } | |
76 | 96 | ParseGameRawDataStr(rawDataStr) | |
77 | 97 | } | |
78 | 98 | ||
79 | 99 | ||
80 | 100 | func ExtractReservedAmt () = match getInteger(this, RESERVATIONKEY) { | |
81 | 101 | case a: Int => | |
82 | 102 | a | |
83 | 103 | case _ => | |
84 | 104 | 0 | |
85 | 105 | } | |
86 | 106 | ||
87 | 107 | ||
88 | - | @Callable(i) | |
89 | - | func bet (playerChoice) = { | |
90 | - | let playerAddress = toBase58String(i.caller.bytes) | |
91 | - | let answer = getAnswer(playerChoice) | |
92 | - | let amount = i.payment | |
108 | + | func ValidateAndIncreaseReservedAmt (winAmt) = { | |
109 | + | let newReservedAmount = (ExtractReservedAmt() + winAmt) | |
93 | 110 | let balance = wavesBalance(this) | |
94 | - | let game = [DataEntry((playerAddress + " это Ставка Игрока"), playerChoice), DataEntry("Ответ Сервера", answer), DataEntry("Текущий баланс игры", balance), DataEntry("Номер текущего блока", height), DataEntry("Bytes блокчейн игры", this.bytes)] | |
95 | - | let playerAddressTx = Address(i.caller.bytes) | |
96 | - | let tSetCommonData = [ScriptTransfer(playerAddressTx, 10, unit)] | |
97 | - | ScriptResult(WriteSet(game), TransferSet(tSetCommonData)) | |
111 | + | if ((newReservedAmount > balance)) | |
112 | + | then throw("Insufficient funds on Russian Roulette account. Transaction was rejected for your safety.") | |
113 | + | else newReservedAmount | |
98 | 114 | } | |
99 | 115 | ||
100 | 116 | ||
101 | - | ||
102 | - | @Callable(i) | |
103 | - | func withdraw (amount) = { | |
104 | - | let currentKey = toBase58String(i.caller.bytes) | |
105 | - | let currentAmount = match getInteger(this, currentKey) { | |
106 | - | case a: Int => | |
107 | - | a | |
117 | + | func IncrementGameNum () = { | |
118 | + | let gameNum = match getInteger(this, GAMESCOUNTERKEY) { | |
119 | + | case num: Int => | |
120 | + | num | |
108 | 121 | case _ => | |
109 | 122 | 0 | |
110 | 123 | } | |
111 | - | let newAmount = (currentAmount - amount) | |
112 | - | if ((0 > amount)) | |
113 | - | then throw("Can't withdraw negative amount") | |
114 | - | else if ((0 > newAmount)) | |
115 | - | then throw("Not enough balance") | |
116 | - | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) | |
124 | + | (gameNum + 1) | |
117 | 125 | } | |
118 | 126 | ||
119 | 127 | ||
120 | - | ||
121 | - | ||
122 | - | | |
123 | - | | |
124 | - | | |
125 | - | | |
126 | - | | |
127 | - | | |
128 | - | | |
128 | + | func FormatGameDataParam (p) = { | |
129 | + | let s = size(p) | |
130 | + | if ((s == 0)) | |
131 | + | then throw("Parameter size must be greater then 0") | |
132 | + | else if ((s > 99)) | |
133 | + | then throw("Parameter size must be less then 100") | |
134 | + | else if ((10 > s)) | |
135 | + | then (("0" + toString(s)) + p) | |
136 | + | else (toString(s) + p) | |
129 | 137 | } | |
130 | - | else false | |
138 | + | ||
139 | + | ||
140 | + | func FormatGameDataStr (gameState,playerChoice,playerPubKey58,startedHeight,winAmt,randOrEmpty) = { | |
141 | + | let fullStateStr = ((((((((FormatGameDataParam(gameState) + "_") + FormatGameDataParam(playerChoice)) + "_") + FormatGameDataParam(playerPubKey58)) + "_") + FormatGameDataParam(toString(startedHeight))) + "_") + FormatGameDataParam(toString(winAmt))) | |
142 | + | if ((randOrEmpty == "")) | |
143 | + | then fullStateStr | |
144 | + | else ((fullStateStr + "_") + FormatGameDataParam(randOrEmpty)) | |
145 | + | } | |
146 | + | ||
147 | + | ||
148 | + | func ValidateBetAndDefineWinAmt (betAmt,playerChoice) = { | |
149 | + | let betAmtValid = if (if (if (if (if ((betAmt == (BET1 + COMMISSION))) | |
150 | + | then true | |
151 | + | else (betAmt == (BET2 + COMMISSION))) | |
152 | + | then true | |
153 | + | else (betAmt == (BET4 + COMMISSION))) | |
154 | + | then true | |
155 | + | else (betAmt == (BET8 + COMMISSION))) | |
156 | + | then true | |
157 | + | else (betAmt == (BET14 + COMMISSION))) | |
158 | + | then true | |
159 | + | else false | |
160 | + | if (betAmtValid) | |
161 | + | then { | |
162 | + | let bulletsCount = size(playerChoice) | |
163 | + | let bet = (betAmt - COMMISSION) | |
164 | + | if ((bulletsCount == 5)) | |
165 | + | then ((bet * RATE1) / RATEMULT) | |
166 | + | else if ((bulletsCount == 4)) | |
167 | + | then ((bet * RATE2) / RATEMULT) | |
168 | + | else if ((bulletsCount == 3)) | |
169 | + | then ((bet * RATE3) / RATEMULT) | |
170 | + | else if ((bulletsCount == 2)) | |
171 | + | then ((bet * RATE4) / RATEMULT) | |
172 | + | else if ((bulletsCount == 1)) | |
173 | + | then ((bet * RATE5) / RATEMULT) | |
174 | + | else throw("Invalid bullets in player's choice") | |
175 | + | } | |
176 | + | else throw("Bet amount is not in range") | |
177 | + | } | |
178 | + | ||
179 | + | ||
180 | + | @Callable(i) | |
181 | + | func bet (playerChoice) = { | |
182 | + | let newGameNum = IncrementGameNum() | |
183 | + | let gameId = toBase58String(i.transactionId) | |
184 | + | let pmt = extract(i.payment) | |
185 | + | let betNotInWaves = isDefined(pmt.assetId) | |
186 | + | let feeNotInWaves = isDefined(pmt.assetId) | |
187 | + | let winAmt = ValidateBetAndDefineWinAmt(pmt.amount, playerChoice) | |
188 | + | let txIdUsed = isDefined(getString(this, gameId)) | |
189 | + | if (betNotInWaves) | |
190 | + | then throw("Bet amount must be in Waves") | |
191 | + | else if (feeNotInWaves) | |
192 | + | then throw("Transaction's fee must be in Waves") | |
193 | + | else if (txIdUsed) | |
194 | + | then throw("Passed txId had been used before. Game aborted.") | |
195 | + | else { | |
196 | + | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
197 | + | let gameDataStr = FormatGameDataStr(STATESUBMITTED, playerChoice, playerPubKey58, height, winAmt, "") | |
198 | + | let SERVER = addressFromPublicKey(i.callerPublicKey) | |
199 | + | let serverTransfer = [ScriptTransfer(SERVER, COMMISSION, unit)] | |
200 | + | let betData = [DataEntry(RESERVATIONKEY, ValidateAndIncreaseReservedAmt(winAmt)), DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)] | |
201 | + | ScriptResult(WriteSet(betData), TransferSet(serverTransfer)) | |
202 | + | } | |
203 | + | } | |
204 | + | ||
131 | 205 |
github/deemru/w8io/026f985 38.40 ms ◑