tx · CyA88LXvvL7V7Z6igTx4qK4bBM1sq3vi2nAgmDmJ1DY9

3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun:  -0.01400000 Waves

2019.09.08 11:42 [666870] smart account 3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun > SELF 0.00000000 Waves

{ "type": 13, "id": "CyA88LXvvL7V7Z6igTx4qK4bBM1sq3vi2nAgmDmJ1DY9", "fee": 1400000, "feeAssetId": null, "timestamp": 1567932166845, "version": 1, "sender": "3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun", "senderPublicKey": "7uRSDXQUkUS7719CDA4wXghhzsWrF22gb18FGDPZyA6P", "proofs": [ "2gSQbXaqntGKg2Kn9Jekd5jSuppZqKMJK1cMFvX56QpP8jp69HCDxszjy4k1ivhv8wC4pSmDbUg4wiAQnRNtFozb" ], "script": "base64:AAIDAAAAAAAAAAAAAAASAAAAAAlXaW5TZXJ2ZXIJAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQIAAAAjM045WG55UHBXeFlvaEtIN3o1ZEV1cThycG5vYnB5elByekUAAAAAB1dBVkVMRVQJAABoAAAAAgkAAGgAAAACAAAAAAAAAABkAAAAAAAAAAPoAAAAAAAAAAPoAAAAAApDT01NSVNTSU9OCQAAaQAAAAIJAABoAAAAAgAAAAAAAAAABQUAAAAHV0FWRUxFVAAAAAAAAAAD6AAAAAAOVGlja2V0c1BlcldhdmUAAAAAAAAAAGQAAAAAC0NVUlJFTlRHQU1FAgAAAA0kQ1VSUkVOVF9HQU1FAAAAAA9HQU1FU0NPVU5URVJLRVkCAAAACSRHQU1FX05VTQAAAAAKTEFTVFRJQ0tFVAIAAAAMJExBU1RfVElDS0VUAAAAAARCQU5LAgAAAAokR0FNRV9CQU5LAQAAAA5nZXRQbGF5ZXJzTGlzdAAAAAIAAAAGZ2FtZUlkAAAADWN1cnJlbnRQbGF5ZXIEAAAAEHBsYXllcnNQcmVzZW50ZWQJ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dGVTZXQAAAABBQAAAAdiZXREYXRhCQEAAAALVHJhbnNmZXJTZXQAAAABBQAAAAt0b1dpblNlcnZlcgAAAACi7dRE", "chainId": 84, "height": 666870, "spentComplexity": 0 } View: original | compacted Prev: 32qsTgxx1aTMzvupms8e8DT2nUht88BvHGKzJrqh3Vd5 Next: EnpE8ac45xwM9iADdDzuBhnJ43evyfjgEGNhXn36d7bH Diff:
OldNewDifferences
1414 let GAMESCOUNTERKEY = "$GAME_NUM"
1515
1616 let LASTTICKET = "$LAST_TICKET"
17+
18+let BANK = "$GAME_BANK"
1719
1820 func getPlayersList (gameId,currentPlayer) = {
1921 let playersPresented = isDefined(getString(this, (gameId + "_players")))
100102 }
101103
102104
105+func getBankBalance (gameId,paymentAmt) = {
106+ let bankBalance = match getInteger(this, ((gameId + "_") + BANK)) {
107+ case num: Int =>
108+ num
109+ case _ =>
110+ 0
111+ }
112+ (bankBalance + paymentAmt)
113+ }
114+
115+
116+func getTotalPlayerBetsAmt (gameId,playerAddressStr,paymentAmt) = {
117+ let totalPlayerBets = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_totalBetsAmt")) {
118+ case num: Int =>
119+ num
120+ case _ =>
121+ 0
122+ }
123+ (totalPlayerBets + paymentAmt)
124+ }
125+
126+
103127 @Callable(i)
104128 func resetGameData (gameId) = {
105129 let playerPubKey58 = toBase58String(i.callerPublicKey)
128152 then throw("Transaction's fee must be in Waves")
129153 else {
130154 let playerAddressStr = toString(playerAddress)
131- let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt))]
155+ let newBankBalance = getBankBalance(gameId, paymentAmt)
156+ let newTotalPlayerBetsAmt = getTotalPlayerBetsAmt(gameId, playerAddressStr, paymentAmt)
157+ let playerWinAmt = ((newTotalPlayerBetsAmt * 90) / 100)
158+ let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((((gameId + "_") + playerAddressStr) + "_IfWinsGet"), playerWinAmt), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), newTotalPlayerBetsAmt), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt)), DataEntry(((gameId + "_") + BANK), newBankBalance)]
132159 let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)]
133160 ScriptResult(WriteSet(betData), TransferSet(toWinServer))
134161 }
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let WinServer = addressFromStringValue("3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE")
55
66 let WAVELET = ((100 * 1000) * 1000)
77
88 let COMMISSION = ((5 * WAVELET) / 1000)
99
1010 let TicketsPerWave = 100
1111
1212 let CURRENTGAME = "$CURRENT_GAME"
1313
1414 let GAMESCOUNTERKEY = "$GAME_NUM"
1515
1616 let LASTTICKET = "$LAST_TICKET"
17+
18+let BANK = "$GAME_BANK"
1719
1820 func getPlayersList (gameId,currentPlayer) = {
1921 let playersPresented = isDefined(getString(this, (gameId + "_players")))
2022 if (!(playersPresented))
2123 then currentPlayer
2224 else if (isDefined(getString(this, (((gameId + "_") + currentPlayer) + "_tickets"))))
2325 then getStringValue(this, (gameId + "_players"))
2426 else ((getStringValue(this, (gameId + "_players")) + "_") + currentPlayer)
2527 }
2628
2729
2830 func FormatGameDataParam (p) = {
2931 let s = size(p)
3032 if ((s == 0))
3133 then throw("Parameter size must be greater then 0")
3234 else if ((s > 99))
3335 then throw("Parameter size must be less then 100")
3436 else if ((10 > s))
3537 then (("0" + toString(s)) + p)
3638 else (toString(s) + p)
3739 }
3840
3941
4042 func getOrCreateLastTicket () = {
4143 let isLastTicketPresented = isDefined(getInteger(this, LASTTICKET))
4244 if (!(isLastTicketPresented))
4345 then 0
4446 else getIntegerValue(this, LASTTICKET)
4547 }
4648
4749
4850 func getTickets (gameId,playerAddressStr,paymentAmt) = {
4951 let lastTicket = getOrCreateLastTicket()
5052 let wavesPayment = (paymentAmt / WAVELET)
5153 let firstNewTicket = (lastTicket + 1)
5254 let lastNewTicket = ((firstNewTicket + (wavesPayment * TicketsPerWave)) - 1)
5355 let newTickets = ((FormatGameDataParam(toString(firstNewTicket)) + "_") + FormatGameDataParam(toString(lastNewTicket)))
5456 let ticketsStr = isDefined(getString(this, (((gameId + "_") + playerAddressStr) + "_tickets")))
5557 if (ticketsStr)
5658 then {
5759 let currentTickets = getStringValue(this, (((gameId + "_") + playerAddressStr) + "_tickets"))
5860 ((currentTickets + " ") + newTickets)
5961 }
6062 else newTickets
6163 }
6264
6365
6466 func getLastTicket (paymentAmt) = {
6567 let lastTicket = getOrCreateLastTicket()
6668 let wavesPayment = (paymentAmt / WAVELET)
6769 (lastTicket + (wavesPayment * TicketsPerWave))
6870 }
6971
7072
7173 func IncrementGameNum (gameId,txId) = {
7274 let gameNum = match getInteger(this, GAMESCOUNTERKEY) {
7375 case num: Int =>
7476 num
7577 case _ =>
7678 0
7779 }
7880 if ((gameId == txId))
7981 then (gameNum + 1)
8082 else gameNum
8183 }
8284
8385
8486 func getOrCreateCurrentGame (txId) = {
8587 let isCurrentGamePresented = isDefined(getString(this, CURRENTGAME))
8688 if (!(isCurrentGamePresented))
8789 then txId
8890 else if ((getStringValue(this, CURRENTGAME) == ""))
8991 then txId
9092 else getStringValue(this, CURRENTGAME)
9193 }
9294
9395
9496 func getCurrentGame (txId) = {
9597 let gameId = getOrCreateCurrentGame(txId)
9698 let gameAlreadyPlayed = isDefined(getString(this, (gameId + "_result")))
9799 if (gameAlreadyPlayed)
98100 then txId
99101 else gameId
100102 }
101103
102104
105+func getBankBalance (gameId,paymentAmt) = {
106+ let bankBalance = match getInteger(this, ((gameId + "_") + BANK)) {
107+ case num: Int =>
108+ num
109+ case _ =>
110+ 0
111+ }
112+ (bankBalance + paymentAmt)
113+ }
114+
115+
116+func getTotalPlayerBetsAmt (gameId,playerAddressStr,paymentAmt) = {
117+ let totalPlayerBets = match getInteger(this, (((gameId + "_") + playerAddressStr) + "_totalBetsAmt")) {
118+ case num: Int =>
119+ num
120+ case _ =>
121+ 0
122+ }
123+ (totalPlayerBets + paymentAmt)
124+ }
125+
126+
103127 @Callable(i)
104128 func resetGameData (gameId) = {
105129 let playerPubKey58 = toBase58String(i.callerPublicKey)
106130 let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
107131 let playerAddressStr = toString(playerAddress)
108132 let zeroData = [DataEntry(CURRENTGAME, ""), DataEntry(GAMESCOUNTERKEY, 0), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), ""), DataEntry((gameId + "_players"), ""), DataEntry(LASTTICKET, 0)]
109133 WriteSet(zeroData)
110134 }
111135
112136
113137
114138 @Callable(i)
115139 func bet () = {
116140 let txId = toBase58String(i.transactionId)
117141 let gameId = getCurrentGame(txId)
118142 let gameNum = IncrementGameNum(gameId, txId)
119143 let pmt = extract(i.payment)
120144 let paymentAmt = pmt.amount
121145 let betNotInWaves = isDefined(pmt.assetId)
122146 let feeNotInWaves = isDefined(pmt.assetId)
123147 let playerPubKey58 = toBase58String(i.callerPublicKey)
124148 let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58))
125149 if (betNotInWaves)
126150 then throw("Bet amount must be in Waves")
127151 else if (feeNotInWaves)
128152 then throw("Transaction's fee must be in Waves")
129153 else {
130154 let playerAddressStr = toString(playerAddress)
131- let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt))]
155+ let newBankBalance = getBankBalance(gameId, paymentAmt)
156+ let newTotalPlayerBetsAmt = getTotalPlayerBetsAmt(gameId, playerAddressStr, paymentAmt)
157+ let playerWinAmt = ((newTotalPlayerBetsAmt * 90) / 100)
158+ let betData = [DataEntry(CURRENTGAME, gameId), DataEntry(GAMESCOUNTERKEY, gameNum), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), getTickets(gameId, playerAddressStr, paymentAmt)), DataEntry((((gameId + "_") + playerAddressStr) + "_IfWinsGet"), playerWinAmt), DataEntry((((gameId + "_") + playerAddressStr) + "_totalBetsAmt"), newTotalPlayerBetsAmt), DataEntry((gameId + "_players"), getPlayersList(gameId, playerAddressStr)), DataEntry(LASTTICKET, getLastTicket(paymentAmt)), DataEntry(((gameId + "_") + BANK), newBankBalance)]
132159 let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)]
133160 ScriptResult(WriteSet(betData), TransferSet(toWinServer))
134161 }
135162 }
136163
137164

github/deemru/w8io/026f985 
30.01 ms