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/RS9p36FY3qCJjLclClmAz4vj6GlBAAAAAA1TZXJ2ZXJBZGRyZXNzCQEAAAAcQGV4dHJVc2VyKGFkZHJlc3NGcm9tU3RyaW5nKQAAAAECAAAAIzNNdThvS1NjV0N3UjMzWW9tVDV1a1U3M1A3akxyeVpUazRzAAAAABBSb3VsZXR0ZVNlY3Rpb25zAAAAAAAAAAAVAAAAABFEYXRhR2FtZU51bWJlcktleQIAAAALQVBQX0dBTUVfSUQAAAAADURhdGFBbW91bnRLZXkCAAAABkFNT1VOVAAAAAAORGF0YVNlY3Rpb25LZXkCAAAAB1NFQ1RJT04AAAAADURhdGFTdGF0dXNLZXkCAAAABlNUQVRVUwAAAAANRGF0YVJlc3VsdEtleQIAAAAGUkVTVUxUAAAAAA1EYXRhU3RhdHVzTmV3AgAAAANORVcAAAAADURhdGFTdGF0dXNXaW4CAAAAA1dJTgAAAAAPRGF0YVN0YXR1c0xvb3NlAgAAAAVMT09TRQAAAAAHV0FWRUxFVAkAAGg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XN1bHRLZXkFAAAABHJhbmQFAAAAA25pbAMFAAAABWlzV2luCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgUAAAAId3JpdGVTZXQJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwUAAAANU2VydmVyQWRkcmVzcwUAAAAKQ09NTUlTU0lPTgUAAAAEdW5pdAUAAAADbmlsBQAAAAh3cml0ZVNldAkAAAIAAAABCQABLAAAAAIFAAAADUVycm9yR2FtZU92ZXIFAAAABnN0YXR1cwAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAADCQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleQQAAAAHJG1hdGNoMAUAAAACdHgDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAFFNldFNjcmlwdFRyYW5zYWN0aW9uBAAAAANzdHgFAAAAByRtYXRjaDAGBwdKzIOd", "chainId": 84, "height": 566278, "spentComplexity": 0 } View: original | compacted Prev: 4B8RqB1MKxCxzkzbi3iy4zr4WFq2PFsahEiXreSF8M82 Next: DMyUSMcfdFyiN2L3Kt2jfbpWHJY2dv41CcPNir6gtWM5 Diff:
OldNewDifferences
2727
2828 let COMMISSION = ((5 * WAVELET) / 1000)
2929
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+
3042 let ErrorOnlyWavesAccepted = "Only waves accepted"
3143
3244 let ErrorMustGreaterThan0 = "Parameter size must be greater than 0"
4254 let ErrorKeyNotFound = "Key not found: "
4355
4456 let ErrorGameOver = "Game already is over"
57+
58+let ErrorIncorrectSectionResult = "Incorrect sectionn result"
59+
60+let ErrorBetAmountNotInRange = "Bet amount is not in range"
4561
4662 func StoreData (transactionId,key,value) = DataEntry(((transactionId + "_") + key), value)
4763
95111 }
96112
97113
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+
98135 @Callable(i)
99136 func bet (expectedResult) = {
137+ let isIncorrectResult = if ((0 >= expectedResult))
138+ then true
139+ else (expectedResult > 20)
100140 let gameNumber = NewGameId()
101141 let gameTransactionId = toBase58String(i.transactionId)
102142 let address = toBase58String(i.caller.bytes)
105145 let betNotInWaves = isDefined(pmt.assetId)
106146 let feeNotInWaves = isDefined(pmt.assetId)
107147 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)]))
115158 }
116159
117160
124167 if ((status == DataStatusNew))
125168 then {
126169 let isWin = (rand == selectedSection)
127- let writeSet = WriteSet([StoreData(gameTransactionId, DataStatusKey, toString(isWin)), StoreDataInt(gameTransactionId, DataResultKey, rand)])
170+ let writeSet = WriteSet([StoreData(gameTransactionId, DataStatusKey, GetStatus(isWin)), StoreDataInt(gameTransactionId, DataResultKey, rand)])
128171 if (isWin)
129172 then ScriptResult(writeSet, TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)]))
130173 else writeSet
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let ServerPublicKey = base58'DrYgfD7j6AKD1iXtn9uhMka95ATZB42B1kGKCUATP2UG'
55
66 let ServerAddress = addressFromStringValue("3Mu8oKScWCwR33YomT5ukU73P7jLryZTk4s")
77
88 let RouletteSections = 21
99
1010 let DataGameNumberKey = "APP_GAME_ID"
1111
1212 let DataAmountKey = "AMOUNT"
1313
1414 let DataSectionKey = "SECTION"
1515
1616 let DataStatusKey = "STATUS"
1717
1818 let DataResultKey = "RESULT"
1919
2020 let DataStatusNew = "NEW"
2121
2222 let DataStatusWin = "WIN"
2323
2424 let DataStatusLoose = "LOOSE"
2525
2626 let WAVELET = ((100 * 1000) * 1000)
2727
2828 let COMMISSION = ((5 * WAVELET) / 1000)
2929
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+
3042 let ErrorOnlyWavesAccepted = "Only waves accepted"
3143
3244 let ErrorMustGreaterThan0 = "Parameter size must be greater than 0"
3345
3446 let ErrorMustLessThan100 = "Parameter size must be less than 100"
3547
3648 let ErrorBetMustBeInWaves = "Bet amount must be in Waves"
3749
3850 let ErrorTransactionMustBeInWaves = "Transaction's fee must be in Waves"
3951
4052 let ErrorTransactionUsed = "Passed txId had been used before. Game aborted."
4153
4254 let ErrorKeyNotFound = "Key not found: "
4355
4456 let ErrorGameOver = "Game already is over"
57+
58+let ErrorIncorrectSectionResult = "Incorrect sectionn result"
59+
60+let ErrorBetAmountNotInRange = "Bet amount is not in range"
4561
4662 func StoreData (transactionId,key,value) = DataEntry(((transactionId + "_") + key), value)
4763
4864
4965 func StoreDataInt (transactionId,key,value) = DataEntry(((transactionId + "_") + key), value)
5066
5167
5268 func GetDataString (transactionId,key) = {
5369 let fullKey = ((transactionId + "_") + key)
5470 match getString(this, fullKey) {
5571 case str: String =>
5672 str
5773 case _ =>
5874 throw((ErrorKeyNotFound + fullKey))
5975 }
6076 }
6177
6278
6379 func GetDataInt (transactionId,key) = {
6480 let fullKey = ((transactionId + "_") + key)
6581 match getInteger(this, fullKey) {
6682 case str: Int =>
6783 str
6884 case _ =>
6985 throw((ErrorKeyNotFound + fullKey))
7086 }
7187 }
7288
7389
7490 func NewGameId () = {
7591 let gameNum = match getInteger(this, DataGameNumberKey) {
7692 case num: Int =>
7793 num
7894 case _ =>
7995 0
8096 }
8197 (gameNum + 1)
8298 }
8399
84100
85101 func GenerateRandInt (gameId,rsaSign) = {
86102 let rsaSigValid = sigVerify(fromBase58String(gameId), fromBase58String(rsaSign), ServerPublicKey)
87103 if (rsaSigValid)
88104 then {
89105 let rand = (toInt(sha256(toBytes(rsaSign))) % RouletteSections)
90106 if ((0 > rand))
91107 then (-1 * rand)
92108 else rand
93109 }
94110 else throw("Invalid RSA signature")
95111 }
96112
97113
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+
98135 @Callable(i)
99136 func bet (expectedResult) = {
137+ let isIncorrectResult = if ((0 >= expectedResult))
138+ then true
139+ else (expectedResult > 20)
100140 let gameNumber = NewGameId()
101141 let gameTransactionId = toBase58String(i.transactionId)
102142 let address = toBase58String(i.caller.bytes)
103143 let pmt = extract(i.payment)
104144 let txIdUsed = isDefined(getString(this, gameTransactionId))
105145 let betNotInWaves = isDefined(pmt.assetId)
106146 let feeNotInWaves = isDefined(pmt.assetId)
107147 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)]))
115158 }
116159
117160
118161
119162 @Callable(i)
120163 func result (gameTransactionId,rsa) = {
121164 let rand = GenerateRandInt(gameTransactionId, rsa)
122165 let selectedSection = GetDataInt(gameTransactionId, DataSectionKey)
123166 let status = GetDataString(gameTransactionId, DataStatusKey)
124167 if ((status == DataStatusNew))
125168 then {
126169 let isWin = (rand == selectedSection)
127- let writeSet = WriteSet([StoreData(gameTransactionId, DataStatusKey, toString(isWin)), StoreDataInt(gameTransactionId, DataResultKey, rand)])
170+ let writeSet = WriteSet([StoreData(gameTransactionId, DataStatusKey, GetStatus(isWin)), StoreDataInt(gameTransactionId, DataResultKey, rand)])
128171 if (isWin)
129172 then ScriptResult(writeSet, TransferSet([ScriptTransfer(ServerAddress, COMMISSION, unit)]))
130173 else writeSet
131174 }
132175 else throw((ErrorGameOver + status))
133176 }
134177
135178
136179 @Verifier(tx)
137180 func verify () = if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey))
138181 then match tx {
139182 case stx: SetScriptTransaction =>
140183 true
141184 case _ =>
142185 false
143186 }
144187 else false
145188

github/deemru/w8io/169f3d6 
44.47 ms