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:AAIDAAAAAAAAAAAAAAASAAAAAAlXaW5TZXJ2ZXIJAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQIAAAAjM045WG55UHBXeFlvaEtIN3o1ZEV1cThycG5vYnB5elByekUAAAAAB1dBVkVMRVQJAABoAAAAAgkAAGgAAAACAAAAAAAAAABkAAAAAAAAAAPoAAAAAAAAAAPoAAAAAApDT01NSVNTSU9OCQAAaQAAAAIJAABoAAAAAgAAAAAAAAAABQUAAAAHV0FWRUxFVAAAAAAAAAAD6AAAAAAOVGlja2V0c1BlcldhdmUAAAAAAAAAAGQAAAAAC0NVUlJFTlRHQU1FAgAAAA0kQ1VSUkVOVF9HQU1FAAAAAA9HQU1FU0NPVU5URVJLRVkCAAAACSRHQU1FX05VTQAAAAAKTEFTVFRJQ0tFVAIAAAAMJExBU1RfVElDS0VUAAAAAARCQU5LAgAAAAokR0FNRV9CQU5LAQAAAA5nZXRQbGF5ZXJzTGlzdAAAAAIAAAAGZ2FtZUlkAAAADWN1cnJlbnRQbGF5ZXIEAAAAEHBsYXllcnNQcmVzZW50ZWQJA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GVTZXQAAAABBQAAAAdiZXREYXRhCQEAAAALVHJhbnNmZXJTZXQAAAABBQAAAAt0b1dpblNlcnZlcgAAAACi7dRE", "chainId": 84, "height": 666870, "spentComplexity": 0 } View: original | compacted Prev: 32qsTgxx1aTMzvupms8e8DT2nUht88BvHGKzJrqh3Vd5 Next: EnpE8ac45xwM9iADdDzuBhnJ43evyfjgEGNhXn36d7bH Diff:
Old | New | Differences | |
---|---|---|---|
14 | 14 | let GAMESCOUNTERKEY = "$GAME_NUM" | |
15 | 15 | ||
16 | 16 | let LASTTICKET = "$LAST_TICKET" | |
17 | + | ||
18 | + | let BANK = "$GAME_BANK" | |
17 | 19 | ||
18 | 20 | func getPlayersList (gameId,currentPlayer) = { | |
19 | 21 | let playersPresented = isDefined(getString(this, (gameId + "_players"))) | |
100 | 102 | } | |
101 | 103 | ||
102 | 104 | ||
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 | + | ||
103 | 127 | @Callable(i) | |
104 | 128 | func resetGameData (gameId) = { | |
105 | 129 | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
128 | 152 | then throw("Transaction's fee must be in Waves") | |
129 | 153 | else { | |
130 | 154 | 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)] | |
132 | 159 | let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)] | |
133 | 160 | ScriptResult(WriteSet(betData), TransferSet(toWinServer)) | |
134 | 161 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let WinServer = addressFromStringValue("3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE") | |
5 | 5 | ||
6 | 6 | let WAVELET = ((100 * 1000) * 1000) | |
7 | 7 | ||
8 | 8 | let COMMISSION = ((5 * WAVELET) / 1000) | |
9 | 9 | ||
10 | 10 | let TicketsPerWave = 100 | |
11 | 11 | ||
12 | 12 | let CURRENTGAME = "$CURRENT_GAME" | |
13 | 13 | ||
14 | 14 | let GAMESCOUNTERKEY = "$GAME_NUM" | |
15 | 15 | ||
16 | 16 | let LASTTICKET = "$LAST_TICKET" | |
17 | + | ||
18 | + | let BANK = "$GAME_BANK" | |
17 | 19 | ||
18 | 20 | func getPlayersList (gameId,currentPlayer) = { | |
19 | 21 | let playersPresented = isDefined(getString(this, (gameId + "_players"))) | |
20 | 22 | if (!(playersPresented)) | |
21 | 23 | then currentPlayer | |
22 | 24 | else if (isDefined(getString(this, (((gameId + "_") + currentPlayer) + "_tickets")))) | |
23 | 25 | then getStringValue(this, (gameId + "_players")) | |
24 | 26 | else ((getStringValue(this, (gameId + "_players")) + "_") + currentPlayer) | |
25 | 27 | } | |
26 | 28 | ||
27 | 29 | ||
28 | 30 | func FormatGameDataParam (p) = { | |
29 | 31 | let s = size(p) | |
30 | 32 | if ((s == 0)) | |
31 | 33 | then throw("Parameter size must be greater then 0") | |
32 | 34 | else if ((s > 99)) | |
33 | 35 | then throw("Parameter size must be less then 100") | |
34 | 36 | else if ((10 > s)) | |
35 | 37 | then (("0" + toString(s)) + p) | |
36 | 38 | else (toString(s) + p) | |
37 | 39 | } | |
38 | 40 | ||
39 | 41 | ||
40 | 42 | func getOrCreateLastTicket () = { | |
41 | 43 | let isLastTicketPresented = isDefined(getInteger(this, LASTTICKET)) | |
42 | 44 | if (!(isLastTicketPresented)) | |
43 | 45 | then 0 | |
44 | 46 | else getIntegerValue(this, LASTTICKET) | |
45 | 47 | } | |
46 | 48 | ||
47 | 49 | ||
48 | 50 | func getTickets (gameId,playerAddressStr,paymentAmt) = { | |
49 | 51 | let lastTicket = getOrCreateLastTicket() | |
50 | 52 | let wavesPayment = (paymentAmt / WAVELET) | |
51 | 53 | let firstNewTicket = (lastTicket + 1) | |
52 | 54 | let lastNewTicket = ((firstNewTicket + (wavesPayment * TicketsPerWave)) - 1) | |
53 | 55 | let newTickets = ((FormatGameDataParam(toString(firstNewTicket)) + "_") + FormatGameDataParam(toString(lastNewTicket))) | |
54 | 56 | let ticketsStr = isDefined(getString(this, (((gameId + "_") + playerAddressStr) + "_tickets"))) | |
55 | 57 | if (ticketsStr) | |
56 | 58 | then { | |
57 | 59 | let currentTickets = getStringValue(this, (((gameId + "_") + playerAddressStr) + "_tickets")) | |
58 | 60 | ((currentTickets + " ") + newTickets) | |
59 | 61 | } | |
60 | 62 | else newTickets | |
61 | 63 | } | |
62 | 64 | ||
63 | 65 | ||
64 | 66 | func getLastTicket (paymentAmt) = { | |
65 | 67 | let lastTicket = getOrCreateLastTicket() | |
66 | 68 | let wavesPayment = (paymentAmt / WAVELET) | |
67 | 69 | (lastTicket + (wavesPayment * TicketsPerWave)) | |
68 | 70 | } | |
69 | 71 | ||
70 | 72 | ||
71 | 73 | func IncrementGameNum (gameId,txId) = { | |
72 | 74 | let gameNum = match getInteger(this, GAMESCOUNTERKEY) { | |
73 | 75 | case num: Int => | |
74 | 76 | num | |
75 | 77 | case _ => | |
76 | 78 | 0 | |
77 | 79 | } | |
78 | 80 | if ((gameId == txId)) | |
79 | 81 | then (gameNum + 1) | |
80 | 82 | else gameNum | |
81 | 83 | } | |
82 | 84 | ||
83 | 85 | ||
84 | 86 | func getOrCreateCurrentGame (txId) = { | |
85 | 87 | let isCurrentGamePresented = isDefined(getString(this, CURRENTGAME)) | |
86 | 88 | if (!(isCurrentGamePresented)) | |
87 | 89 | then txId | |
88 | 90 | else if ((getStringValue(this, CURRENTGAME) == "")) | |
89 | 91 | then txId | |
90 | 92 | else getStringValue(this, CURRENTGAME) | |
91 | 93 | } | |
92 | 94 | ||
93 | 95 | ||
94 | 96 | func getCurrentGame (txId) = { | |
95 | 97 | let gameId = getOrCreateCurrentGame(txId) | |
96 | 98 | let gameAlreadyPlayed = isDefined(getString(this, (gameId + "_result"))) | |
97 | 99 | if (gameAlreadyPlayed) | |
98 | 100 | then txId | |
99 | 101 | else gameId | |
100 | 102 | } | |
101 | 103 | ||
102 | 104 | ||
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 | + | ||
103 | 127 | @Callable(i) | |
104 | 128 | func resetGameData (gameId) = { | |
105 | 129 | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
106 | 130 | let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58)) | |
107 | 131 | let playerAddressStr = toString(playerAddress) | |
108 | 132 | let zeroData = [DataEntry(CURRENTGAME, ""), DataEntry(GAMESCOUNTERKEY, 0), DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), ""), DataEntry((gameId + "_players"), ""), DataEntry(LASTTICKET, 0)] | |
109 | 133 | WriteSet(zeroData) | |
110 | 134 | } | |
111 | 135 | ||
112 | 136 | ||
113 | 137 | ||
114 | 138 | @Callable(i) | |
115 | 139 | func bet () = { | |
116 | 140 | let txId = toBase58String(i.transactionId) | |
117 | 141 | let gameId = getCurrentGame(txId) | |
118 | 142 | let gameNum = IncrementGameNum(gameId, txId) | |
119 | 143 | let pmt = extract(i.payment) | |
120 | 144 | let paymentAmt = pmt.amount | |
121 | 145 | let betNotInWaves = isDefined(pmt.assetId) | |
122 | 146 | let feeNotInWaves = isDefined(pmt.assetId) | |
123 | 147 | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
124 | 148 | let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58)) | |
125 | 149 | if (betNotInWaves) | |
126 | 150 | then throw("Bet amount must be in Waves") | |
127 | 151 | else if (feeNotInWaves) | |
128 | 152 | then throw("Transaction's fee must be in Waves") | |
129 | 153 | else { | |
130 | 154 | 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)] | |
132 | 159 | let toWinServer = [ScriptTransfer(WinServer, paymentAmt, unit)] | |
133 | 160 | ScriptResult(WriteSet(betData), TransferSet(toWinServer)) | |
134 | 161 | } | |
135 | 162 | } | |
136 | 163 | ||
137 | 164 |
github/deemru/w8io/026f985 30.01 ms ◑