tx · BnCWwfp8RGwVhDjYBjKgkznwpjFezeuYnCbqB4hb4vqg

3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun:  -0.01400000 Waves

2019.09.08 14:34 [667049] smart account 3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun > SELF 0.00000000 Waves

{ "type": 13, "id": "BnCWwfp8RGwVhDjYBjKgkznwpjFezeuYnCbqB4hb4vqg", "fee": 1400000, "feeAssetId": null, "timestamp": 1567942435455, "version": 1, "sender": "3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun", "senderPublicKey": "7uRSDXQUkUS7719CDA4wXghhzsWrF22gb18FGDPZyA6P", "proofs": [ "QzV2q2BWTx3HLnAmEJzu9EHkv6c8SUEPJMw5QBaEz5pmokeQBaVKTsTwJiZpFCp4aLD9veXP17ibxhu4KbcduPk" ], "script": "base64:AAIDAAAAAAAAAAAAAAALAAAAAA9TZXJ2ZXJQdWJsaWNLZXkJAAJZAAAAAQIAAAAsN2ltOWNhaUNtRTRTTDZqVG00S1RpY0hINGJHUGY1djU5cm5mVUEzY0NSRGoAAAAACUJldFNlcnZlcgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABAgAAACMzTjZ5Rko1WjhOVVVRdmZHR01McDVlZm1ldlJSdFRnUXV1bgAAAAAHV0FWRUxFVAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAA+gAAAAAAAAAA+gAAAAACkNPTU1JU1NJT04JAABpAAAAAgkAAGgAAAACAAAAAAAAAAAFBQAAAAdXQVZFTEVUAAAAAAAAAAPoAAAAAA5UaWNrZXRzUGVyV2F2ZQAAAAAAAAAAZAAAAAALQ1VSUkVOVEdBTUUCAAAADSRDVVJSRU5UX0dBTUUAAAAACkxBU1RUSUNLRVQCAAAADCRMQVNUX1RJQ0tFVAAAAAAEQkFOSwIAAAAKJEdBTUVfQkFOSwEAAAAPR2VuZXJhdGVSYW5kSW50AAAAAgAAAAZnY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XwkAAZEAAAACBQAAAAtwbGF5ZXJzTGlzdAAAAAAAAAAABAIAAAANX3RvdGFsQmV0c0FtdAkAAAIAAAABAgAAAAVFcnJvcgkAAAIAAAABCQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAABBDdXJyZW50IEdhbWUgaXMgBQAAAAtjdXJyZW50R2FtZQIAAAAKLCBidXQgbm90IAUAAAAGZ2FtZUlkAAAAAA/aLK4=", "chainId": 84, "height": 667049, "spentComplexity": 0 } View: original | compacted Prev: Ey5a6bFhmv79hBDcz1BFTL4uXqHGNuGc3FP8fG4Enm25 Next: 8SQjJKyJzYLw16Caj1HzR9DjTgmvy8sjJQ17Hwrtv4YV Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let WinServer = addressFromStringValue("3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE")
4+let ServerPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj")
5+
6+let BetServer = addressFromStringValue("3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun")
57
68 let WAVELET = ((100 * 1000) * 1000)
79
1113
1214 let CURRENTGAME = "$CURRENT_GAME"
1315
14-let GAMESCOUNTERKEY = "$GAME_NUM"
15-
1616 let LASTTICKET = "$LAST_TICKET"
1717
1818 let BANK = "$GAME_BANK"
1919
20-func getPlayersList (gameId,currentPlayer) = {
21- let playersPresented = isDefined(getString(this, (gameId + "_players")))
22- if (!(playersPresented))
23- then currentPlayer
24- else if (isDefined(getString(this, (((gameId + "_") + currentPlayer) + "_tickets"))))
25- then getStringValue(this, (gameId + "_players"))
26- else ((getStringValue(this, (gameId + "_players")) + "_") + currentPlayer)
20+func GenerateRandInt (gameId,rsaSign) = {
21+ let lastTicket = getIntegerValue(BetServer, LASTTICKET)
22+ let rsaSigValid = sigVerify(toBytes(gameId), rsaSign, ServerPublicKey)
23+ if (rsaSigValid)
24+ then {
25+ let rand = (toInt(sha256(rsaSign)) % lastTicket)
26+ if ((0 > rand))
27+ then ((-1 * rand) + 1)
28+ else (rand + 1)
29+ }
30+ else throw("Invalid RSA signature")
2731 }
2832
2933
30-func getOrCreateLastTicket () = {
31- let isLastTicketPresented = isDefined(getInteger(this, LASTTICKET))
32- if (!(isLastTicketPresented))
33- then 0
34- else getIntegerValue(this, LASTTICKET)
34+func isWinner (ticketsStr,winTicket) = {
35+ let tickets = split(ticketsStr, "_")
36+ if (if ((winTicket >= parseIntValue(tickets[0])))
37+ then (parseIntValue(tickets[1]) >= winTicket)
38+ else false)
39+ then true
40+ else if (if ((winTicket >= parseIntValue(tickets[2])))
41+ then (parseIntValue(tickets[3]) >= winTicket)
42+ else false)
43+ then true
44+ else if (if ((winTicket >= parseIntValue(tickets[4])))
45+ then (parseIntValue(tickets[5]) >= winTicket)
46+ else false)
47+ then true
48+ else if (if ((winTicket >= parseIntValue(tickets[6])))
49+ then (parseIntValue(tickets[7]) >= winTicket)
50+ else false)
51+ then true
52+ else false
3553 }
3654
3755
38-func getPlayerBetsCount (gameId,playerAddressStr) = {
39- let betsCount = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_betsCount")) {
40- case num: Int =>
41- num
42- case _ =>
43- 0
44- }
45- betsCount
46- }
47-
48-
49-func getTickets (gameId,playerAddressStr,paymentAmt) = {
50- let lastTicket = getOrCreateLastTicket()
51- let wavesPayment = (paymentAmt / WAVELET)
52- let firstNewTicket = (lastTicket + 1)
53- let lastNewTicket = ((firstNewTicket + (wavesPayment * TicketsPerWave)) - 1)
54- let firstNewTicketStr = toString(firstNewTicket)
55- let lastNewTicketStr = toString(lastNewTicket)
56- let ticketsStr = isDefined(getString(this, (((gameId + "_") + playerAddressStr) + "_tickets")))
57- if (ticketsStr)
58- then {
59- let currentTickets = getStringValue(this, (((gameId + "_") + playerAddressStr) + "_tickets"))
60- let currentPlayerBetNum = getPlayerBetsCount(gameId, playerAddressStr)
61- let CTL = split(currentTickets, "_")
62- if ((currentPlayerBetNum == 1))
63- then (((((((CTL[0] + "_") + CTL[1]) + "_") + firstNewTicketStr) + "_") + lastNewTicketStr) + "_0_0_0_0")
64- else if ((currentPlayerBetNum == 2))
65- then ((((((((((CTL[0] + "_") + CTL[1]) + "_") + CTL[2]) + "_") + CTL[3]) + firstNewTicketStr) + "_") + lastNewTicketStr) + "_0_0")
66- else if ((currentPlayerBetNum == 3))
67- then ((((((((((((CTL[0] + "_") + CTL[1]) + "_") + CTL[2]) + "_") + CTL[3]) + CTL[4]) + "_") + CTL[5]) + firstNewTicketStr) + "_") + lastNewTicketStr)
68- else throw("Error, bid limit exceeded")
69- }
70- else (((firstNewTicketStr + "_") + lastNewTicketStr) + "_0_0_0_0_0_0")
71- }
72-
73-
74-func getLastTicket (paymentAmt) = {
75- let lastTicket = getOrCreateLastTicket()
76- let wavesPayment = (paymentAmt / WAVELET)
77- (lastTicket + (wavesPayment * TicketsPerWave))
78- }
79-
80-
81-func IncrementGameNum (gameId,txId) = {
82- let gameNum = match getInteger(this, GAMESCOUNTERKEY) {
83- case num: Int =>
84- num
85- case _ =>
86- 0
87- }
88- if ((gameId == txId))
89- then (gameNum + 1)
90- else gameNum
91- }
92-
93-
94-func getOrCreateCurrentGame (txId) = {
95- let isCurrentGamePresented = isDefined(getString(this, CURRENTGAME))
96- if (!(isCurrentGamePresented))
97- then txId
98- else if ((getStringValue(this, CURRENTGAME) == ""))
99- then txId
100- else getStringValue(this, CURRENTGAME)
101- }
102-
103-
104-func getCurrentGame (txId) = {
105- let gameId = getOrCreateCurrentGame(txId)
106- let gameAlreadyPlayed = isDefined(getString(this, (gameId + "_result")))
107- if (gameAlreadyPlayed)
108- then txId
109- else gameId
110- }
111-
112-
113-func getBankBalance (gameId,paymentAmt) = {
114- let bankBalance = match getInteger(this, ((gameId + "_") + BANK)) {
115- case num: Int =>
116- num
117- case _ =>
118- 0
119- }
120- (bankBalance + paymentAmt)
121- }
122-
123-
124-func getTotalPlayerBetsAmt (gameId,playerAddressStr,paymentAmt) = {
125- let totalPlayerBets = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_totalBetsAmt")) {
126- case num: Int =>
127- num
128- case _ =>
129- 0
130- }
131- (totalPlayerBets + paymentAmt)
56+func win (gameId,winTicket,winnerAddressStr,bankBalance,totalWinnerBetsAmt) = {
57+ let winAmt = (((bankBalance - totalWinnerBetsAmt) * 90) / 100)
58+ let winTX = [ScriptTransfer(addressFromStringValue(winnerAddressStr), winAmt, unit)]
59+ let gameResult = [DataEntry((gameId + "_result"), toString(winTicket)), DataEntry((gameId + "_winner"), winnerAddressStr), DataEntry((gameId + "_winAmt"), winAmt)]
60+ ScriptResult(WriteSet(gameResult), TransferSet(winTX))
13261 }
13362
13463
13564 @Callable(i)
136-func resetGameData (gameId) = {
137- let playerPubKey58 = toBase58String(i.callerPublicKey)
138- let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
139- let playerAddressStr = toString(playerAddress)
140- let zeroData = [DataEntry(CURRENTGAME, ""), DataEntry(GAMESCOUNTERKEY, 0), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), ""), DataEntry((((gameId + "_") + playerAddressStr) + "_betsCount"), 0), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), 0), DataEntry(((gameId + "_") + BANK), 0), DataEntry((gameId + "_players"), ""), DataEntry(LASTTICKET, 0)]
141- WriteSet(zeroData)
142- }
143-
144-
145-
146-@Callable(i)
147-func bet () = {
148- let txId = toBase58String(i.transactionId)
149- let gameId = getCurrentGame(txId)
150- let gameNum = IncrementGameNum(gameId, txId)
151- let pmt = extract(i.payment)
152- let paymentAmt = pmt.amount
153- let betNotInWaves = isDefined(pmt.assetId)
154- let feeNotInWaves = isDefined(pmt.assetId)
155- let playerPubKey58 = toBase58String(i.callerPublicKey)
156- let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
157- if (betNotInWaves)
158- then throw("Bet amount must be in Waves")
159- else if (feeNotInWaves)
160- then throw("Transaction's fee must be in Waves")
161- else {
162- let playerAddressStr = toString(playerAddress)
163- let newBankBalance = getBankBalance(gameId, paymentAmt)
164- let newTotalPlayerBetsAmt = getTotalPlayerBetsAmt(gameId, playerAddressStr, paymentAmt)
165- let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((((gameId + "_") + playerAddressStr) + "_betsCount"), (getPlayerBetsCount(gameId, playerAddressStr) + 1)), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), newTotalPlayerBetsAmt), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt)), DataEntry(((gameId + "_") + BANK), newBankBalance)]
166- let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)]
167- ScriptResult(WriteSet(betData), TransferSet(toWinServer))
168- }
65+func generateResult (gameId,rsaSignCrypted) = {
66+ let currentGame = getStringValue(BetServer, CURRENTGAME)
67+ if ((currentGame == gameId))
68+ then {
69+ let rsaSign = fromBase58String(rsaSignCrypted)
70+ let winTicket = GenerateRandInt(gameId, rsaSign)
71+ let players = getStringValue(BetServer, (gameId + "_players"))
72+ let playersList = split(players, "_")
73+ let bankBalance = getIntegerValue(BetServer, BANK)
74+ if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[0]) + "_tickets")), winTicket))
75+ then win(gameId, winTicket, playersList[0], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[0]) + "_totalBetsAmt")))
76+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[1]) + "_tickets")), winTicket))
77+ then win(gameId, winTicket, playersList[1], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[1]) + "_totalBetsAmt")))
78+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[2]) + "_tickets")), winTicket))
79+ then win(gameId, winTicket, playersList[2], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[2]) + "_totalBetsAmt")))
80+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[3]) + "_tickets")), winTicket))
81+ then win(gameId, winTicket, playersList[3], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[3]) + "_totalBetsAmt")))
82+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[4]) + "_tickets")), winTicket))
83+ then win(gameId, winTicket, playersList[4], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[4]) + "_totalBetsAmt")))
84+ else throw("Error")
85+ }
86+ else throw(((("Current Game is " + currentGame) + ", but not ") + gameId))
16987 }
17088
17189
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let WinServer = addressFromStringValue("3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE")
4+let ServerPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj")
5+
6+let BetServer = addressFromStringValue("3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun")
57
68 let WAVELET = ((100 * 1000) * 1000)
79
810 let COMMISSION = ((5 * WAVELET) / 1000)
911
1012 let TicketsPerWave = 100
1113
1214 let CURRENTGAME = "$CURRENT_GAME"
1315
14-let GAMESCOUNTERKEY = "$GAME_NUM"
15-
1616 let LASTTICKET = "$LAST_TICKET"
1717
1818 let BANK = "$GAME_BANK"
1919
20-func getPlayersList (gameId,currentPlayer) = {
21- let playersPresented = isDefined(getString(this, (gameId + "_players")))
22- if (!(playersPresented))
23- then currentPlayer
24- else if (isDefined(getString(this, (((gameId + "_") + currentPlayer) + "_tickets"))))
25- then getStringValue(this, (gameId + "_players"))
26- else ((getStringValue(this, (gameId + "_players")) + "_") + currentPlayer)
20+func GenerateRandInt (gameId,rsaSign) = {
21+ let lastTicket = getIntegerValue(BetServer, LASTTICKET)
22+ let rsaSigValid = sigVerify(toBytes(gameId), rsaSign, ServerPublicKey)
23+ if (rsaSigValid)
24+ then {
25+ let rand = (toInt(sha256(rsaSign)) % lastTicket)
26+ if ((0 > rand))
27+ then ((-1 * rand) + 1)
28+ else (rand + 1)
29+ }
30+ else throw("Invalid RSA signature")
2731 }
2832
2933
30-func getOrCreateLastTicket () = {
31- let isLastTicketPresented = isDefined(getInteger(this, LASTTICKET))
32- if (!(isLastTicketPresented))
33- then 0
34- else getIntegerValue(this, LASTTICKET)
34+func isWinner (ticketsStr,winTicket) = {
35+ let tickets = split(ticketsStr, "_")
36+ if (if ((winTicket >= parseIntValue(tickets[0])))
37+ then (parseIntValue(tickets[1]) >= winTicket)
38+ else false)
39+ then true
40+ else if (if ((winTicket >= parseIntValue(tickets[2])))
41+ then (parseIntValue(tickets[3]) >= winTicket)
42+ else false)
43+ then true
44+ else if (if ((winTicket >= parseIntValue(tickets[4])))
45+ then (parseIntValue(tickets[5]) >= winTicket)
46+ else false)
47+ then true
48+ else if (if ((winTicket >= parseIntValue(tickets[6])))
49+ then (parseIntValue(tickets[7]) >= winTicket)
50+ else false)
51+ then true
52+ else false
3553 }
3654
3755
38-func getPlayerBetsCount (gameId,playerAddressStr) = {
39- let betsCount = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_betsCount")) {
40- case num: Int =>
41- num
42- case _ =>
43- 0
44- }
45- betsCount
46- }
47-
48-
49-func getTickets (gameId,playerAddressStr,paymentAmt) = {
50- let lastTicket = getOrCreateLastTicket()
51- let wavesPayment = (paymentAmt / WAVELET)
52- let firstNewTicket = (lastTicket + 1)
53- let lastNewTicket = ((firstNewTicket + (wavesPayment * TicketsPerWave)) - 1)
54- let firstNewTicketStr = toString(firstNewTicket)
55- let lastNewTicketStr = toString(lastNewTicket)
56- let ticketsStr = isDefined(getString(this, (((gameId + "_") + playerAddressStr) + "_tickets")))
57- if (ticketsStr)
58- then {
59- let currentTickets = getStringValue(this, (((gameId + "_") + playerAddressStr) + "_tickets"))
60- let currentPlayerBetNum = getPlayerBetsCount(gameId, playerAddressStr)
61- let CTL = split(currentTickets, "_")
62- if ((currentPlayerBetNum == 1))
63- then (((((((CTL[0] + "_") + CTL[1]) + "_") + firstNewTicketStr) + "_") + lastNewTicketStr) + "_0_0_0_0")
64- else if ((currentPlayerBetNum == 2))
65- then ((((((((((CTL[0] + "_") + CTL[1]) + "_") + CTL[2]) + "_") + CTL[3]) + firstNewTicketStr) + "_") + lastNewTicketStr) + "_0_0")
66- else if ((currentPlayerBetNum == 3))
67- then ((((((((((((CTL[0] + "_") + CTL[1]) + "_") + CTL[2]) + "_") + CTL[3]) + CTL[4]) + "_") + CTL[5]) + firstNewTicketStr) + "_") + lastNewTicketStr)
68- else throw("Error, bid limit exceeded")
69- }
70- else (((firstNewTicketStr + "_") + lastNewTicketStr) + "_0_0_0_0_0_0")
71- }
72-
73-
74-func getLastTicket (paymentAmt) = {
75- let lastTicket = getOrCreateLastTicket()
76- let wavesPayment = (paymentAmt / WAVELET)
77- (lastTicket + (wavesPayment * TicketsPerWave))
78- }
79-
80-
81-func IncrementGameNum (gameId,txId) = {
82- let gameNum = match getInteger(this, GAMESCOUNTERKEY) {
83- case num: Int =>
84- num
85- case _ =>
86- 0
87- }
88- if ((gameId == txId))
89- then (gameNum + 1)
90- else gameNum
91- }
92-
93-
94-func getOrCreateCurrentGame (txId) = {
95- let isCurrentGamePresented = isDefined(getString(this, CURRENTGAME))
96- if (!(isCurrentGamePresented))
97- then txId
98- else if ((getStringValue(this, CURRENTGAME) == ""))
99- then txId
100- else getStringValue(this, CURRENTGAME)
101- }
102-
103-
104-func getCurrentGame (txId) = {
105- let gameId = getOrCreateCurrentGame(txId)
106- let gameAlreadyPlayed = isDefined(getString(this, (gameId + "_result")))
107- if (gameAlreadyPlayed)
108- then txId
109- else gameId
110- }
111-
112-
113-func getBankBalance (gameId,paymentAmt) = {
114- let bankBalance = match getInteger(this, ((gameId + "_") + BANK)) {
115- case num: Int =>
116- num
117- case _ =>
118- 0
119- }
120- (bankBalance + paymentAmt)
121- }
122-
123-
124-func getTotalPlayerBetsAmt (gameId,playerAddressStr,paymentAmt) = {
125- let totalPlayerBets = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_totalBetsAmt")) {
126- case num: Int =>
127- num
128- case _ =>
129- 0
130- }
131- (totalPlayerBets + paymentAmt)
56+func win (gameId,winTicket,winnerAddressStr,bankBalance,totalWinnerBetsAmt) = {
57+ let winAmt = (((bankBalance - totalWinnerBetsAmt) * 90) / 100)
58+ let winTX = [ScriptTransfer(addressFromStringValue(winnerAddressStr), winAmt, unit)]
59+ let gameResult = [DataEntry((gameId + "_result"), toString(winTicket)), DataEntry((gameId + "_winner"), winnerAddressStr), DataEntry((gameId + "_winAmt"), winAmt)]
60+ ScriptResult(WriteSet(gameResult), TransferSet(winTX))
13261 }
13362
13463
13564 @Callable(i)
136-func resetGameData (gameId) = {
137- let playerPubKey58 = toBase58String(i.callerPublicKey)
138- let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
139- let playerAddressStr = toString(playerAddress)
140- let zeroData = [DataEntry(CURRENTGAME, ""), DataEntry(GAMESCOUNTERKEY, 0), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), ""), DataEntry((((gameId + "_") + playerAddressStr) + "_betsCount"), 0), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), 0), DataEntry(((gameId + "_") + BANK), 0), DataEntry((gameId + "_players"), ""), DataEntry(LASTTICKET, 0)]
141- WriteSet(zeroData)
142- }
143-
144-
145-
146-@Callable(i)
147-func bet () = {
148- let txId = toBase58String(i.transactionId)
149- let gameId = getCurrentGame(txId)
150- let gameNum = IncrementGameNum(gameId, txId)
151- let pmt = extract(i.payment)
152- let paymentAmt = pmt.amount
153- let betNotInWaves = isDefined(pmt.assetId)
154- let feeNotInWaves = isDefined(pmt.assetId)
155- let playerPubKey58 = toBase58String(i.callerPublicKey)
156- let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
157- if (betNotInWaves)
158- then throw("Bet amount must be in Waves")
159- else if (feeNotInWaves)
160- then throw("Transaction's fee must be in Waves")
161- else {
162- let playerAddressStr = toString(playerAddress)
163- let newBankBalance = getBankBalance(gameId, paymentAmt)
164- let newTotalPlayerBetsAmt = getTotalPlayerBetsAmt(gameId, playerAddressStr, paymentAmt)
165- let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((((gameId + "_") + playerAddressStr) + "_betsCount"), (getPlayerBetsCount(gameId, playerAddressStr) + 1)), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), newTotalPlayerBetsAmt), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt)), DataEntry(((gameId + "_") + BANK), newBankBalance)]
166- let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)]
167- ScriptResult(WriteSet(betData), TransferSet(toWinServer))
168- }
65+func generateResult (gameId,rsaSignCrypted) = {
66+ let currentGame = getStringValue(BetServer, CURRENTGAME)
67+ if ((currentGame == gameId))
68+ then {
69+ let rsaSign = fromBase58String(rsaSignCrypted)
70+ let winTicket = GenerateRandInt(gameId, rsaSign)
71+ let players = getStringValue(BetServer, (gameId + "_players"))
72+ let playersList = split(players, "_")
73+ let bankBalance = getIntegerValue(BetServer, BANK)
74+ if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[0]) + "_tickets")), winTicket))
75+ then win(gameId, winTicket, playersList[0], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[0]) + "_totalBetsAmt")))
76+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[1]) + "_tickets")), winTicket))
77+ then win(gameId, winTicket, playersList[1], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[1]) + "_totalBetsAmt")))
78+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[2]) + "_tickets")), winTicket))
79+ then win(gameId, winTicket, playersList[2], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[2]) + "_totalBetsAmt")))
80+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[3]) + "_tickets")), winTicket))
81+ then win(gameId, winTicket, playersList[3], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[3]) + "_totalBetsAmt")))
82+ else if (isWinner(getStringValue(BetServer, (((gameId + "_") + playersList[4]) + "_tickets")), winTicket))
83+ then win(gameId, winTicket, playersList[4], bankBalance, getIntegerValue(BetServer, (((gameId + "_") + playersList[4]) + "_totalBetsAmt")))
84+ else throw("Error")
85+ }
86+ else throw(((("Current Game is " + currentGame) + ", but not ") + gameId))
16987 }
17088
17189

github/deemru/w8io/169f3d6 
45.58 ms