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