tx · 9iTGABtKnXks19UXagceDxnQxT7dLfgVfALKKj4TKoqm 3N8M61KCm8G72mK8PjacFbnnxdbFsyqQDeT: -0.01400000 Waves 2019.07.01 18:27 [566498] smart account 3N8M61KCm8G72mK8PjacFbnnxdbFsyqQDeT > SELF 0.00000000 Waves
{ "type": 13, "id": "9iTGABtKnXks19UXagceDxnQxT7dLfgVfALKKj4TKoqm", "fee": 1400000, "feeAssetId": null, "timestamp": 1561994899900, "version": 1, "sender": "3N8M61KCm8G72mK8PjacFbnnxdbFsyqQDeT", "senderPublicKey": "Bhyvkx4xdbEi4KPJNZSzx9gZgzgyLEsavuj2kYSt7SST", "proofs": [ "58nnGnRQ7rHRFsTuYfNFwLDoCEhScYECgni71eC4cztCjFUzuhgHLYiguFshZYcuaqHVeXr3EZYrZLDeY5XUUJc9" ], "script": "base64:AAIDAAAAAAAAAAAAAAAmAAAAAA9TZXJ2ZXJQdWJsaWNLZXkBAAAAIL79hxhmqWX34iA/RS9p36FY3qCJjLclClmAz4vj6GlBAAAAAA1TZXJ2ZXJBZGRyZXNzCQEAAAAcQGV4dHJVc2VyKGFkZHJlc3NGcm9tU3RyaW5nKQAAAAECAAAAIzNNdThvS1NjV0N3UjMzWW9tVDV1a1U3M1A3akxyeVpUazRzAAAAABBSb3VsZXR0ZVNlY3Rpb25zAAAAAAAAAAAVAAAAABFEYXRhR2FtZU51bWJlcktleQIAAAALQVBQX0dBTUVfSUQAAAAADURhdGFBbW91bnRLZXkCAAAABkFNT1VOVAAAAAAORGF0YVNlY3Rpb25LZXkCAAAAB1NFQ1RJT04AAAAADURhdGFTdGF0dXNLZXkCAAAABlNUQVRVUwAAAAANRGF0YVJlc3VsdEtleQIAAAAGUkVTVUxUAAAAABBEYXRhV2luQW1vdW50S2V5AgAAAApXSU5fQU1PVU5UAAAAAA1EYXRhU3RhdHVzTmV3AgAAAANORVcAAAAADURhdGFTdGF0dXNXaW4CAAAAA1dJTgAAAAAPRGF0YVN0YXR1c0xvb3NlAgA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AAD3NlbGVjdGVkU2VjdGlvbgQAAAAId3JpdGVTZXQJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACVN0b3JlRGF0YQAAAAMFAAAAEWdhbWVUcmFuc2FjdGlvbklkBQAAAA1EYXRhU3RhdHVzS2V5CQEAAAAJR2V0U3RhdHVzAAAAAQUAAAAFaXNXaW4JAARMAAAAAgkBAAAADFN0b3JlRGF0YUludAAAAAMFAAAAEWdhbWVUcmFuc2FjdGlvbklkBQAAAA1EYXRhUmVzdWx0S2V5BQAAAARyYW5kBQAAAANuaWwDBQAAAAVpc1dpbgkBAAAADFNjcmlwdFJlc3VsdAAAAAIFAAAACHdyaXRlU2V0CQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMFAAAADVNlcnZlckFkZHJlc3MFAAAACkNPTU1JU1NJT04FAAAABHVuaXQFAAAAA25pbAUAAAAId3JpdGVTZXQJAAACAAAAAQkAASwAAAACBQAAAA1FcnJvckdhbWVPdmVyBQAAAAZzdGF0dXMAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAAAwkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXkEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABRTZXRTY3JpcHRUcmFuc2FjdGlvbgQAAAADc3R4BQAAAAckbWF0Y2gwBgcHsAK6Ag==", "chainId": 84, "height": 566498, "spentComplexity": 0 } View: original | compacted Prev: EkGxio875NzkxeFBpE2Hjz3y7DvEnL89JHdr7rF67hAc Next: DdidCosjvqoP3AM1mWJ4rp2JXEBF2xaasnvRk2Z8TjjJ Diff:
Old | New | Differences | |
---|---|---|---|
118 | 118 | else DataStatusLoose | |
119 | 119 | ||
120 | 120 | ||
121 | - | func GetWinAmount (betAmt) = { | |
121 | + | func GetWinAmount (betAmt,section) = { | |
122 | + | let isIncorrectResult = if ((0 >= section)) | |
123 | + | then true | |
124 | + | else (section > 20) | |
122 | 125 | let betAmtValid = if (if (if (if ((betAmt == (BET1 + COMMISSION))) | |
123 | 126 | then true | |
124 | 127 | else (betAmt == (BET2 + COMMISSION))) | |
128 | 131 | else (betAmt == (BET8 + COMMISSION))) | |
129 | 132 | then true | |
130 | 133 | else (betAmt == (BET14 + COMMISSION)) | |
131 | - | if (betAmtValid) | |
132 | - | then 666 | |
133 | - | else throw(ErrorBetAmountNotInRange) | |
134 | + | if (isIncorrectResult) | |
135 | + | then throw(ErrorIncorrectSectionResult) | |
136 | + | else if (betAmtValid) | |
137 | + | then ((betAmt - COMMISSION) * Sections[section]) | |
138 | + | else throw(ErrorBetAmountNotInRange) | |
134 | 139 | } | |
135 | 140 | ||
136 | 141 | ||
137 | 142 | @Callable(i) | |
138 | 143 | func bet (expectedResult) = { | |
139 | - | let isIncorrectResult = if ((0 >= expectedResult)) | |
140 | - | then true | |
141 | - | else (expectedResult > 20) | |
142 | 144 | let gameNumber = NewGameId() | |
143 | 145 | let gameTransactionId = toBase58String(i.transactionId) | |
144 | 146 | let address = toBase58String(i.caller.bytes) | |
147 | 149 | let betNotInWaves = isDefined(pmt.assetId) | |
148 | 150 | let feeNotInWaves = isDefined(pmt.assetId) | |
149 | 151 | let amount = pmt.amount | |
150 | - | let winAmt = GetWinAmount(pmt.amount) | |
151 | - | if (isIncorrectResult) | |
152 | - | then throw(ErrorIncorrectSectionResult) | |
153 | - | else if (betNotInWaves) | |
154 | - | then throw(ErrorBetMustBeInWaves) | |
155 | - | else if (feeNotInWaves) | |
156 | - | then throw(ErrorTransactionMustBeInWaves) | |
157 | - | else if (txIdUsed) | |
158 | - | then throw(ErrorTransactionUsed) | |
159 | - | else ScriptResult(WriteSet([DataEntry(gameTransactionId, address), DataEntry(DataGameNumberKey, gameNumber), StoreDataInt(gameTransactionId, DataAmountKey, amount), StoreDataInt(gameTransactionId, DataSectionKey, expectedResult), StoreData(gameTransactionId, DataStatusKey, DataStatusNew), StoreDataInt(gameTransactionId, DataWinAmountKey, winAmt)]), TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)])) | |
152 | + | let winAmt = GetWinAmount(pmt.amount, expectedResult) | |
153 | + | if (betNotInWaves) | |
154 | + | then throw(ErrorBetMustBeInWaves) | |
155 | + | else if (feeNotInWaves) | |
156 | + | then throw(ErrorTransactionMustBeInWaves) | |
157 | + | else if (txIdUsed) | |
158 | + | then throw(ErrorTransactionUsed) | |
159 | + | else ScriptResult(WriteSet([DataEntry(gameTransactionId, address), DataEntry(DataGameNumberKey, gameNumber), StoreDataInt(gameTransactionId, DataAmountKey, amount), StoreDataInt(gameTransactionId, DataSectionKey, expectedResult), StoreData(gameTransactionId, DataStatusKey, DataStatusNew), StoreDataInt(gameTransactionId, DataWinAmountKey, winAmt)]), TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)])) | |
160 | 160 | } | |
161 | 161 | ||
162 | 162 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ServerPublicKey = base58'DrYgfD7j6AKD1iXtn9uhMka95ATZB42B1kGKCUATP2UG' | |
5 | 5 | ||
6 | 6 | let ServerAddress = addressFromStringValue("3Mu8oKScWCwR33YomT5ukU73P7jLryZTk4s") | |
7 | 7 | ||
8 | 8 | let RouletteSections = 21 | |
9 | 9 | ||
10 | 10 | let DataGameNumberKey = "APP_GAME_ID" | |
11 | 11 | ||
12 | 12 | let DataAmountKey = "AMOUNT" | |
13 | 13 | ||
14 | 14 | let DataSectionKey = "SECTION" | |
15 | 15 | ||
16 | 16 | let DataStatusKey = "STATUS" | |
17 | 17 | ||
18 | 18 | let DataResultKey = "RESULT" | |
19 | 19 | ||
20 | 20 | let DataWinAmountKey = "WIN_AMOUNT" | |
21 | 21 | ||
22 | 22 | let DataStatusNew = "NEW" | |
23 | 23 | ||
24 | 24 | let DataStatusWin = "WIN" | |
25 | 25 | ||
26 | 26 | let DataStatusLoose = "LOOSE" | |
27 | 27 | ||
28 | 28 | let WAVELET = ((100 * 1000) * 1000) | |
29 | 29 | ||
30 | 30 | let COMMISSION = ((5 * WAVELET) / 1000) | |
31 | 31 | ||
32 | 32 | let BET1 = (1 * WAVELET) | |
33 | 33 | ||
34 | 34 | let BET2 = (2 * WAVELET) | |
35 | 35 | ||
36 | 36 | let BET4 = (4 * WAVELET) | |
37 | 37 | ||
38 | 38 | let BET8 = (8 * WAVELET) | |
39 | 39 | ||
40 | 40 | let BET14 = (14 * WAVELET) | |
41 | 41 | ||
42 | 42 | let Sections = [0, 2, 20, 2, 5, 2, 10, 2, 6, 2, 5, 2, 6, 2, 5, 2, 10, 2, 5, 2, 6] | |
43 | 43 | ||
44 | 44 | let ErrorOnlyWavesAccepted = "Only waves accepted" | |
45 | 45 | ||
46 | 46 | let ErrorMustGreaterThan0 = "Parameter size must be greater than 0" | |
47 | 47 | ||
48 | 48 | let ErrorMustLessThan100 = "Parameter size must be less than 100" | |
49 | 49 | ||
50 | 50 | let ErrorBetMustBeInWaves = "Bet amount must be in Waves" | |
51 | 51 | ||
52 | 52 | let ErrorTransactionMustBeInWaves = "Transaction's fee must be in Waves" | |
53 | 53 | ||
54 | 54 | let ErrorTransactionUsed = "Passed txId had been used before. Game aborted." | |
55 | 55 | ||
56 | 56 | let ErrorKeyNotFound = "Key not found: " | |
57 | 57 | ||
58 | 58 | let ErrorGameOver = "Game already is over" | |
59 | 59 | ||
60 | 60 | let ErrorIncorrectSectionResult = "Incorrect section result" | |
61 | 61 | ||
62 | 62 | let ErrorBetAmountNotInRange = "Bet amount is not in range" | |
63 | 63 | ||
64 | 64 | func StoreData (transactionId,key,value) = DataEntry(((transactionId + "_") + key), value) | |
65 | 65 | ||
66 | 66 | ||
67 | 67 | func StoreDataInt (transactionId,key,value) = DataEntry(((transactionId + "_") + key), value) | |
68 | 68 | ||
69 | 69 | ||
70 | 70 | func GetDataString (transactionId,key) = { | |
71 | 71 | let fullKey = ((transactionId + "_") + key) | |
72 | 72 | match getString(this, fullKey) { | |
73 | 73 | case str: String => | |
74 | 74 | str | |
75 | 75 | case _ => | |
76 | 76 | throw((ErrorKeyNotFound + fullKey)) | |
77 | 77 | } | |
78 | 78 | } | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func GetDataInt (transactionId,key) = { | |
82 | 82 | let fullKey = ((transactionId + "_") + key) | |
83 | 83 | match getInteger(this, fullKey) { | |
84 | 84 | case str: Int => | |
85 | 85 | str | |
86 | 86 | case _ => | |
87 | 87 | throw((ErrorKeyNotFound + fullKey)) | |
88 | 88 | } | |
89 | 89 | } | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | func NewGameId () = { | |
93 | 93 | let gameNum = match getInteger(this, DataGameNumberKey) { | |
94 | 94 | case num: Int => | |
95 | 95 | num | |
96 | 96 | case _ => | |
97 | 97 | 0 | |
98 | 98 | } | |
99 | 99 | (gameNum + 1) | |
100 | 100 | } | |
101 | 101 | ||
102 | 102 | ||
103 | 103 | func GenerateRandInt (gameId,rsaSign) = { | |
104 | 104 | let rsaSigValid = sigVerify(fromBase58String(gameId), fromBase58String(rsaSign), ServerPublicKey) | |
105 | 105 | if (rsaSigValid) | |
106 | 106 | then { | |
107 | 107 | let rand = (toInt(sha256(toBytes(rsaSign))) % RouletteSections) | |
108 | 108 | if ((0 > rand)) | |
109 | 109 | then (-1 * rand) | |
110 | 110 | else rand | |
111 | 111 | } | |
112 | 112 | else throw("Invalid RSA signature") | |
113 | 113 | } | |
114 | 114 | ||
115 | 115 | ||
116 | 116 | func GetStatus (result) = if (result) | |
117 | 117 | then DataStatusWin | |
118 | 118 | else DataStatusLoose | |
119 | 119 | ||
120 | 120 | ||
121 | - | func GetWinAmount (betAmt) = { | |
121 | + | func GetWinAmount (betAmt,section) = { | |
122 | + | let isIncorrectResult = if ((0 >= section)) | |
123 | + | then true | |
124 | + | else (section > 20) | |
122 | 125 | let betAmtValid = if (if (if (if ((betAmt == (BET1 + COMMISSION))) | |
123 | 126 | then true | |
124 | 127 | else (betAmt == (BET2 + COMMISSION))) | |
125 | 128 | then true | |
126 | 129 | else (betAmt == (BET4 + COMMISSION))) | |
127 | 130 | then true | |
128 | 131 | else (betAmt == (BET8 + COMMISSION))) | |
129 | 132 | then true | |
130 | 133 | else (betAmt == (BET14 + COMMISSION)) | |
131 | - | if (betAmtValid) | |
132 | - | then 666 | |
133 | - | else throw(ErrorBetAmountNotInRange) | |
134 | + | if (isIncorrectResult) | |
135 | + | then throw(ErrorIncorrectSectionResult) | |
136 | + | else if (betAmtValid) | |
137 | + | then ((betAmt - COMMISSION) * Sections[section]) | |
138 | + | else throw(ErrorBetAmountNotInRange) | |
134 | 139 | } | |
135 | 140 | ||
136 | 141 | ||
137 | 142 | @Callable(i) | |
138 | 143 | func bet (expectedResult) = { | |
139 | - | let isIncorrectResult = if ((0 >= expectedResult)) | |
140 | - | then true | |
141 | - | else (expectedResult > 20) | |
142 | 144 | let gameNumber = NewGameId() | |
143 | 145 | let gameTransactionId = toBase58String(i.transactionId) | |
144 | 146 | let address = toBase58String(i.caller.bytes) | |
145 | 147 | let pmt = extract(i.payment) | |
146 | 148 | let txIdUsed = isDefined(getString(this, gameTransactionId)) | |
147 | 149 | let betNotInWaves = isDefined(pmt.assetId) | |
148 | 150 | let feeNotInWaves = isDefined(pmt.assetId) | |
149 | 151 | let amount = pmt.amount | |
150 | - | let winAmt = GetWinAmount(pmt.amount) | |
151 | - | if (isIncorrectResult) | |
152 | - | then throw(ErrorIncorrectSectionResult) | |
153 | - | else if (betNotInWaves) | |
154 | - | then throw(ErrorBetMustBeInWaves) | |
155 | - | else if (feeNotInWaves) | |
156 | - | then throw(ErrorTransactionMustBeInWaves) | |
157 | - | else if (txIdUsed) | |
158 | - | then throw(ErrorTransactionUsed) | |
159 | - | else ScriptResult(WriteSet([DataEntry(gameTransactionId, address), DataEntry(DataGameNumberKey, gameNumber), StoreDataInt(gameTransactionId, DataAmountKey, amount), StoreDataInt(gameTransactionId, DataSectionKey, expectedResult), StoreData(gameTransactionId, DataStatusKey, DataStatusNew), StoreDataInt(gameTransactionId, DataWinAmountKey, winAmt)]), TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)])) | |
152 | + | let winAmt = GetWinAmount(pmt.amount, expectedResult) | |
153 | + | if (betNotInWaves) | |
154 | + | then throw(ErrorBetMustBeInWaves) | |
155 | + | else if (feeNotInWaves) | |
156 | + | then throw(ErrorTransactionMustBeInWaves) | |
157 | + | else if (txIdUsed) | |
158 | + | then throw(ErrorTransactionUsed) | |
159 | + | else ScriptResult(WriteSet([DataEntry(gameTransactionId, address), DataEntry(DataGameNumberKey, gameNumber), StoreDataInt(gameTransactionId, DataAmountKey, amount), StoreDataInt(gameTransactionId, DataSectionKey, expectedResult), StoreData(gameTransactionId, DataStatusKey, DataStatusNew), StoreDataInt(gameTransactionId, DataWinAmountKey, winAmt)]), TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)])) | |
160 | 160 | } | |
161 | 161 | ||
162 | 162 | ||
163 | 163 | ||
164 | 164 | @Callable(i) | |
165 | 165 | func result (gameTransactionId,rsa) = { | |
166 | 166 | let rand = GenerateRandInt(gameTransactionId, rsa) | |
167 | 167 | let selectedSection = GetDataInt(gameTransactionId, DataSectionKey) | |
168 | 168 | let status = GetDataString(gameTransactionId, DataStatusKey) | |
169 | 169 | if ((status == DataStatusNew)) | |
170 | 170 | then { | |
171 | 171 | let isWin = (rand == selectedSection) | |
172 | 172 | let writeSet = WriteSet([StoreData(gameTransactionId, DataStatusKey, GetStatus(isWin)), StoreDataInt(gameTransactionId, DataResultKey, rand)]) | |
173 | 173 | if (isWin) | |
174 | 174 | then ScriptResult(writeSet, TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)])) | |
175 | 175 | else writeSet | |
176 | 176 | } | |
177 | 177 | else throw((ErrorGameOver + status)) | |
178 | 178 | } | |
179 | 179 | ||
180 | 180 | ||
181 | 181 | @Verifier(tx) | |
182 | 182 | func verify () = if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) | |
183 | 183 | then match tx { | |
184 | 184 | case stx: SetScriptTransaction => | |
185 | 185 | true | |
186 | 186 | case _ => | |
187 | 187 | false | |
188 | 188 | } | |
189 | 189 | else false | |
190 | 190 |
github/deemru/w8io/026f985 49.22 ms ◑