tx · DhFEayuE5j9FP4AxLqBrmaaC7dnDSpU8hPUecYz59b6m 3Mwuu6do9zBghKKVshUFferCwepiQYcAeVE: -0.01500000 Waves 2019.07.12 11:09 [582243] smart account 3Mwuu6do9zBghKKVshUFferCwepiQYcAeVE > SELF 0.00000000 Waves
{ "type": 13, "id": "DhFEayuE5j9FP4AxLqBrmaaC7dnDSpU8hPUecYz59b6m", "fee": 1500000, "feeAssetId": null, "timestamp": 1562918981178, "version": 1, "sender": "3Mwuu6do9zBghKKVshUFferCwepiQYcAeVE", "senderPublicKey": "8fdATo5z3B5EweA3kKoRgbJZhGa4JicyHHMkhBZTvNSf", "proofs": [ "4E29nC2tVwqPSc5gimi3MVbh6zzvMKCxbdCWdNwyQLd25VBvsmKrafR2PWnuGAprEr9hcZebMty6BtghLdWAtF2j" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAVXYXZlcwAAAAAABfXhAAAAAAAEYmV0MQkAAGgAAAACAAAAAAAAAAABBQAAAAVXYXZlcwAAAAAEYmV0NQkAAGgAAAACAAAAAAAAAAAFBQAAAAVXYXZlcwAAAAAFYmV0MTAJAABoAAAAAgAAAAAAAAAACgUAAAAFV2F2ZXMAAAAABWJldDI1CQAAaAAAAAIAAAAAAAAAABkFAAAABVdhdmVzAAAAAAZiZXQxMDAJAABoAAAAAgAAAAAAAAAAZAUAAAAFV2F2ZXMAAAAACWNvbWlzc2lvbgAAAAAAAExLQAAAAAAPb3JhY2xlUHVibGljS2V5CQACWQAAAAECAAAALEE3N3FwVmt0enQxb0FQeVBmbUtkUHNEWkdSUEp6QnJFM1dUdHVMMUt4TVlMAAAAAA1nYW1lVGltZUZyYW1lAAAAAAAAAAWgAAAAAAhzdGF0ZUFjYwIAAAAIQWNjZXB0ZWQAAAAACHN0YXRlV2luAgAAAANXaW4AAAAADHN0YXRlVGltZW91dAIAAAAMV2luQnlUaW1lb3V0AAAAAAlzdGF0ZUxvc2UCAAAABExvc2UAAAACAAAAAWkBAAAAA2JldA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YQAAAAAAAAAAAAQAAAAQYXZhaWxhYmxlQmFsYW5jZQkAAGUAAAACCQEAAAAMd2F2ZXNCYWxhbmNlAAAAAQUAAAAEdGhpcwUAAAAPcmVzZXJ2ZWRCYWxhbmNlBAAAAA9hdmFpbGlibGVBbW91bnQJAABnAAAAAgUAAAAQYXZhaWxhYmxlQmFsYW5jZQgFAAAAA3R0eAAAAAZhbW91bnQEAAAACXNpZ25hdHVyZQkAAfQAAAADCAUAAAADdHR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAADdHR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAA3R0eAAAAA9zZW5kZXJQdWJsaWNLZXkDBQAAAA9hdmFpbGlibGVBbW91bnQFAAAACXNpZ25hdHVyZQcDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAFFNldFNjcmlwdFRyYW5zYWN0aW9uBAAAAARzc3R4BQAAAAckbWF0Y2gwCQAB9AAAAAMIBQAAAARzc3R4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAAEc3N0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAARzc3R4AAAAD3NlbmRlclB1YmxpY0tleQcTrGHv", "chainId": 84, "height": 582243, "spentComplexity": 0 } View: original | compacted Prev: 9KTapyJLaNDEyyvVz9Mv52MYtkDyMK41GLgnwmHAwytw Next: GaYZTuzs3UhNTx4HES5bG8wEVkZ9Qg8ikQQxLUXQta8a Diff:
Old | New | Differences | |
---|---|---|---|
169 | 169 | ||
170 | 170 | ||
171 | 171 | @Verifier(tx) | |
172 | - | func verify () = true | |
172 | + | func verify () = match tx { | |
173 | + | case ttx: TransferTransaction => | |
174 | + | let valueReservedBalance = getInteger(this, "Reserved") | |
175 | + | let reservedBalance = match valueReservedBalance { | |
176 | + | case a: Int => | |
177 | + | a | |
178 | + | case _ => | |
179 | + | 0 | |
180 | + | } | |
181 | + | let availableBalance = (wavesBalance(this) - reservedBalance) | |
182 | + | let availibleAmount = (availableBalance >= ttx.amount) | |
183 | + | let signature = sigVerify(ttx.bodyBytes, ttx.proofs[0], ttx.senderPublicKey) | |
184 | + | if (availibleAmount) | |
185 | + | then signature | |
186 | + | else false | |
187 | + | case sstx: SetScriptTransaction => | |
188 | + | sigVerify(sstx.bodyBytes, sstx.proofs[0], sstx.senderPublicKey) | |
189 | + | case _ => | |
190 | + | false | |
191 | + | } | |
173 | 192 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let Waves = 100000000 | |
5 | 5 | ||
6 | 6 | let bet1 = (1 * Waves) | |
7 | 7 | ||
8 | 8 | let bet5 = (5 * Waves) | |
9 | 9 | ||
10 | 10 | let bet10 = (10 * Waves) | |
11 | 11 | ||
12 | 12 | let bet25 = (25 * Waves) | |
13 | 13 | ||
14 | 14 | let bet100 = (100 * Waves) | |
15 | 15 | ||
16 | 16 | let comission = 5000000 | |
17 | 17 | ||
18 | 18 | let oraclePublicKey = fromBase58String("A77qpVktzt1oAPyPfmKdPsDZGRPJzBrE3WTtuL1KxMYL") | |
19 | 19 | ||
20 | 20 | let gameTimeFrame = 1440 | |
21 | 21 | ||
22 | 22 | let stateAcc = "Accepted" | |
23 | 23 | ||
24 | 24 | let stateWin = "Win" | |
25 | 25 | ||
26 | 26 | let stateTimeout = "WinByTimeout" | |
27 | 27 | ||
28 | 28 | let stateLose = "Lose" | |
29 | 29 | ||
30 | 30 | @Callable(i) | |
31 | 31 | func bet (choice) = { | |
32 | 32 | let pmnt = extract(i.payment) | |
33 | 33 | let gameId = toBase58String(i.transactionId) | |
34 | 34 | let gameStart = height | |
35 | 35 | let gameCounter = { | |
36 | 36 | let gameNumber = { | |
37 | 37 | let counterValue = getInteger(this, "GamesCounter") | |
38 | 38 | match counterValue { | |
39 | 39 | case p: Int => | |
40 | 40 | p | |
41 | 41 | case _ => | |
42 | 42 | 0 | |
43 | 43 | } | |
44 | 44 | } | |
45 | 45 | (gameNumber + 1) | |
46 | 46 | } | |
47 | 47 | let betAssetIdCheck = isDefined(pmnt.assetId) | |
48 | 48 | let playerPublicKey = toBase58String(i.callerPublicKey) | |
49 | 49 | let playerChoice = if (if ((choice == "1")) | |
50 | 50 | then true | |
51 | 51 | else (choice == "2")) | |
52 | 52 | then choice | |
53 | 53 | else throw("Player's choice is incorrect") | |
54 | 54 | let playerPrize = { | |
55 | 55 | let bet = (pmnt.amount - comission) | |
56 | 56 | if (if (if (if (if ((bet == bet1)) | |
57 | 57 | then true | |
58 | 58 | else (bet == bet5)) | |
59 | 59 | then true | |
60 | 60 | else (bet == bet10)) | |
61 | 61 | then true | |
62 | 62 | else (bet == bet25)) | |
63 | 63 | then true | |
64 | 64 | else (bet == bet100)) | |
65 | 65 | then (bet * 2) | |
66 | 66 | else throw("Payment amount is incorrect") | |
67 | 67 | } | |
68 | 68 | let reservedBalance = { | |
69 | 69 | let currentReservedBalance = { | |
70 | 70 | let valueReservedBalance = getInteger(this, "Reserved") | |
71 | 71 | match valueReservedBalance { | |
72 | 72 | case a: Int => | |
73 | 73 | a | |
74 | 74 | case _ => | |
75 | 75 | 0 | |
76 | 76 | } | |
77 | 77 | } | |
78 | 78 | let newReservedBalance = (currentReservedBalance + playerPrize) | |
79 | 79 | if ((wavesBalance(this) >= newReservedBalance)) | |
80 | 80 | then { | |
81 | 81 | let increaseReservedBalance = newReservedBalance | |
82 | 82 | increaseReservedBalance | |
83 | 83 | } | |
84 | 84 | else throw("Bet was rejected. Insufficient funds on game account.") | |
85 | 85 | } | |
86 | 86 | if (betAssetIdCheck) | |
87 | 87 | then throw("You can make bet in Waves only") | |
88 | 88 | else { | |
89 | 89 | let dataString = ((((((((stateAcc + "_") + playerPublicKey) + "_") + playerChoice) + "_") + toString(playerPrize)) + "_") + toString(gameStart)) | |
90 | 90 | WriteSet([DataEntry("Reserved", reservedBalance), DataEntry(gameId, dataString)]) | |
91 | 91 | } | |
92 | 92 | } | |
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | @Callable(i) | |
97 | 97 | func withdraw (gameId,rsaSign) = { | |
98 | 98 | let dataList = { | |
99 | 99 | let getDataString = getString(this, gameId) | |
100 | 100 | let a = match getDataString { | |
101 | 101 | case a: String => | |
102 | 102 | a | |
103 | 103 | case _ => | |
104 | 104 | throw("GameId was not found") | |
105 | 105 | } | |
106 | 106 | split(a, "_") | |
107 | 107 | } | |
108 | 108 | let gameState = dataList[0] | |
109 | 109 | let playerAddress = { | |
110 | 110 | let a = dataList[1] | |
111 | 111 | addressFromPublicKey(fromBase58String(a)) | |
112 | 112 | } | |
113 | 113 | let playerChoice = dataList[2] | |
114 | 114 | let rsaToInt = { | |
115 | 115 | let rsaCheck = rsaVerify(SHA256, toBytes(gameId), rsaSign, oraclePublicKey) | |
116 | 116 | if (rsaCheck) | |
117 | 117 | then { | |
118 | 118 | let rsaInt = ((toInt(sha256(rsaSign)) % 99) + 1) | |
119 | 119 | if (if ((rsaInt > 0)) | |
120 | 120 | then (100 >= rsaInt) | |
121 | 121 | else false) | |
122 | 122 | then rsaInt | |
123 | 123 | else throw("Rsa integer is not in range") | |
124 | 124 | } | |
125 | 125 | else throw("Rsa Signature is invalid") | |
126 | 126 | } | |
127 | 127 | let gameStart = { | |
128 | 128 | let a = dataList[4] | |
129 | 129 | parseIntValue(a) | |
130 | 130 | } | |
131 | 131 | let playerPrize = { | |
132 | 132 | let a = dataList[3] | |
133 | 133 | parseIntValue(a) | |
134 | 134 | } | |
135 | 135 | let newReservedBalance = { | |
136 | 136 | let valueReservedBalance = getInteger(this, "Reserved") | |
137 | 137 | let extractReservedBalance = match valueReservedBalance { | |
138 | 138 | case a: Int => | |
139 | 139 | a | |
140 | 140 | case _ => | |
141 | 141 | 0 | |
142 | 142 | } | |
143 | 143 | let decreaseReservedBalance = (extractReservedBalance - playerPrize) | |
144 | 144 | if ((decreaseReservedBalance > 0)) | |
145 | 145 | then decreaseReservedBalance | |
146 | 146 | else throw("Reserved balance couldn't be less than 0") | |
147 | 147 | } | |
148 | 148 | let stringForNewData = ((((((dataList[1] + "_") + dataList[2]) + "_") + dataList[3]) + "_") + dataList[4]) | |
149 | 149 | let gameTime = (gameTimeFrame > (height - gameStart)) | |
150 | 150 | let stateCheck = (gameState == stateAcc) | |
151 | 151 | if (stateCheck) | |
152 | 152 | then if (gameTime) | |
153 | 153 | then { | |
154 | 154 | let playerWin = { | |
155 | 155 | let rsaToState = if ((48 > rsaToInt)) | |
156 | 156 | then "1" | |
157 | 157 | else if ((rsaToInt > 52)) | |
158 | 158 | then "2" | |
159 | 159 | else "3" | |
160 | 160 | (rsaToState == playerChoice) | |
161 | 161 | } | |
162 | 162 | if (playerWin) | |
163 | 163 | then ScriptResult(WriteSet([DataEntry(gameId, ((((stateWin + "_") + stringForNewData) + "_") + toString(rsaToInt))), DataEntry("Reserved", newReservedBalance)]), TransferSet([ScriptTransfer(playerAddress, playerPrize, unit)])) | |
164 | 164 | else WriteSet([DataEntry(gameId, ((((stateLose + "_") + stringForNewData) + "_") + toString(rsaToInt))), DataEntry("Reserved", newReservedBalance)]) | |
165 | 165 | } | |
166 | 166 | else throw("Game state is invalid") | |
167 | 167 | else ScriptResult(WriteSet([DataEntry(gameId, ((((stateTimeout + "_") + stringForNewData) + "_") + "00")), DataEntry("Reserved", newReservedBalance)]), TransferSet([ScriptTransfer(playerAddress, playerPrize, unit)])) | |
168 | 168 | } | |
169 | 169 | ||
170 | 170 | ||
171 | 171 | @Verifier(tx) | |
172 | - | func verify () = true | |
172 | + | func verify () = match tx { | |
173 | + | case ttx: TransferTransaction => | |
174 | + | let valueReservedBalance = getInteger(this, "Reserved") | |
175 | + | let reservedBalance = match valueReservedBalance { | |
176 | + | case a: Int => | |
177 | + | a | |
178 | + | case _ => | |
179 | + | 0 | |
180 | + | } | |
181 | + | let availableBalance = (wavesBalance(this) - reservedBalance) | |
182 | + | let availibleAmount = (availableBalance >= ttx.amount) | |
183 | + | let signature = sigVerify(ttx.bodyBytes, ttx.proofs[0], ttx.senderPublicKey) | |
184 | + | if (availibleAmount) | |
185 | + | then signature | |
186 | + | else false | |
187 | + | case sstx: SetScriptTransaction => | |
188 | + | sigVerify(sstx.bodyBytes, sstx.proofs[0], sstx.senderPublicKey) | |
189 | + | case _ => | |
190 | + | false | |
191 | + | } | |
173 | 192 |
github/deemru/w8io/169f3d6 44.65 ms ◑