tx · 3ANQJjUbtCZw5Udsv6HymoZK4ZDwCXQZzDGcfws9VgN5

3N9rM4oycrh554kcWZeLCge8ex5Hjc8htNh:  -0.01500000 Waves

2019.10.09 10:53 [712040] smart account 3N9rM4oycrh554kcWZeLCge8ex5Hjc8htNh > SELF 0.00000000 Waves

{ "type": 13, "id": "3ANQJjUbtCZw5Udsv6HymoZK4ZDwCXQZzDGcfws9VgN5", "fee": 1500000, "feeAssetId": null, "timestamp": 1570607721072, "version": 1, "sender": "3N9rM4oycrh554kcWZeLCge8ex5Hjc8htNh", "senderPublicKey": "9EY8Kfx32TT2GMrY1Jh8nmbMxYkmDMELbnnqdDqvVxXk", "proofs": [ "51tvHnaN33BJRZzKMECDH9fYPNprsN7ioAmKugABGuZKdP1UZX1oYWfsabYZG5jghsm9jcY4u3ckTALW7pi9tyL4" ], "script": null, "chainId": 84, "height": 712040, "spentComplexity": 0 } View: original | compacted Prev: ALHKyEP4UTXEAu3jCaz9GnJeZrZn577hynFgiDGM8rdF Next: none Full:
OldNewDifferences
1-{-# STDLIB_VERSION 3 #-}
2-{-# SCRIPT_TYPE ACCOUNT #-}
3-{-# CONTENT_TYPE DAPP #-}
4-let rsaPublicKey1 = fromBase64String("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOkiuz/BV4EjoxGhTmNCbt2TgkbSPH/w69b3F1rKmD61JiPXvvF8L2pI9xOYcW4FmoEZVHlRQtAlaJykl3+rsrECAwEAAQ==")
5-
6-let rsaPublicKey2 = fromBase64String("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJnXzbM/V2sDV1ULbPSOlHkldOTWRrHi5fxIkBmuevrClMPVH7rqccwirDNcMdIdwXHI9Adhj9FWjwGIwfU/K6MCAwEAAQ==")
7-
8-let rsaPublicKey3 = fromBase64String("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAORDevy0r4kzLqOySloB63Huv2e4zeHKHjCsy5vtFKmWZbXJa8gZYt4+EklFIo1K9oqu5BAPVfJ3FOzs2U1A+g0CAwEAAQ==")
9-
10-let drum1 = ["2", "1", "2", "5", "1", "3", "1", "3", "4", "3", "4", "2", "1", "5", "2", "7", "4", "6", "1", "3"]
11-
12-let drum2 = ["7", "6", "3", "1", "4", "2", "1", "2", "5", "3", "1", "4", "3", "6", "5", "2", "1", "1", "2", "4"]
13-
14-let drum3 = ["4", "3", "1", "6", "5", "7", "4", "3", "6", "1", "2", "4", "3", "1", "2", "5", "2", "1", "5", "1"]
15-
16-let gameTimeFrame = (1440 * 2)
17-
18-let commission = 500000
19-
20-let stateAcc = "Accepted"
21-
22-let stateWin = "Win"
23-
24-let stateTimeout = "WinByTimeout"
25-
26-let stateLose = "Lose"
27-
28-let wavesId = unit
29-
30-let btcId = base58'Gt4HLkHunts7bWbtYP5UCsAPW7TUA4gmQEnjgjbZ2NqB'
31-
32-let ethId = base58'6A79GDQj8bdHqUaoJQ3qE1TCPnBc3wFirNCSsAY5RKry'
33-
34-let ltcId = base58'7oRhs4zoufHM4KiBDuJwRXUWb9JQaFt98N8ubpmytMmw'
35-
36-let vstId = base58'5UyDjBMx1Q8UWhJj1r7JuA6h4aCkKrHE1J19HvMXRpRd'
37-
38-let wctId = base58'Ae5W927iuKSLLT6Sdt3bqWze6ZUbYHDWzPY6dLKQusZv'
39-
40-let divider = 1000
41-
42-let WavesMinAmt = (100000000 / divider)
43-
44-let WavesMaxAmt = (WavesMinAmt * 10)
45-
46-let BtcMinAmt = (10000 / divider)
47-
48-let BtcMaxAmt = (BtcMinAmt * 10)
49-
50-let EthMinAmt = (1000000 / divider)
51-
52-let EthMaxAmt = (EthMinAmt * 10)
53-
54-let LtcMinAmt = (2000000 / divider)
55-
56-let LtcMaxAmt = (LtcMinAmt * 10)
57-
58-let WctMinAmt = (500000000 / divider)
59-
60-let WctMaxAmt = (WctMinAmt * 10)
61-
62-let VstMinAmt = (500000000 / divider)
63-
64-let VstMaxAmt = (VstMinAmt * 10)
65-
66-func pmtAmtCheck (pmtAssetId,betAmount) = if ((pmtAssetId == "WAVES"))
67- then if (if ((betAmount >= WavesMinAmt))
68- then (WavesMaxAmt >= betAmount)
69- else false)
70- then true
71- else throw("Bet amount is not in range")
72- else if ((pmtAssetId == "BTC"))
73- then if (if ((betAmount >= BtcMinAmt))
74- then (BtcMaxAmt >= betAmount)
75- else false)
76- then true
77- else throw("Bet amount is not in range")
78- else if ((pmtAssetId == "ETH"))
79- then if (if ((betAmount >= EthMinAmt))
80- then (EthMaxAmt >= betAmount)
81- else false)
82- then true
83- else throw("Bet amount is not in range")
84- else if ((pmtAssetId == "LTC"))
85- then if (if ((betAmount >= LtcMinAmt))
86- then (LtcMaxAmt >= betAmount)
87- else false)
88- then true
89- else throw("Bet amount is not in range")
90- else if ((pmtAssetId == "WCT"))
91- then if (if ((betAmount >= WctMinAmt))
92- then (WctMaxAmt >= betAmount)
93- else false)
94- then true
95- else throw("Bet amount is not in range")
96- else if (if ((betAmount >= VstMinAmt))
97- then (VstMaxAmt >= betAmount)
98- else false)
99- then true
100- else throw("Bet amount is not in range")
101-
102-
103-func getDataList (gameId) = {
104- let getDataString = getString(this, (gameId + "_GameId"))
105- let a = match getDataString {
106- case a: String =>
107- a
108- case _ =>
109- throw("GameId was not found")
110- }
111- split(a, "_")
112- }
113-
114-
115-func rsaToInt (gameId,rsaSign,rsaPublicKey) = {
116- let rsaCheck = rsaVerify(SHA256, toBytes(gameId), fromBase64String(rsaSign), rsaPublicKey)
117- if (rsaCheck)
118- then {
119- let rsaInt = (toInt(sha256(fromBase64String(rsaSign))) % 19)
120- if (if ((rsaInt >= 0))
121- then (19 >= rsaInt)
122- else false)
123- then rsaInt
124- else throw("Integer is not in range")
125- }
126- else throw("Rsa Signature is invalid")
127- }
128-
129-
130-func increaseReservedBalance (pmtAmt,pmtAssetName,assetId58) = {
131- let currentReservedBalance = {
132- let valueReservedBalance = getInteger(this, (pmtAssetName + "_Reserved"))
133- match valueReservedBalance {
134- case a: Int =>
135- a
136- case _ =>
137- 0
138- }
139- }
140- let newReservedBalance = (currentReservedBalance + pmtAmt)
141- if ((assetBalance(this, assetId58) >= newReservedBalance))
142- then {
143- let increaseReservedBalance = newReservedBalance
144- increaseReservedBalance
145- }
146- else throw("Bet was rejected. Insufficient funds on game account.")
147- }
148-
149-
150-func decreaseReservedBalance (betAmt,assetId) = {
151- let valueReservedBalance = getInteger(this, (assetId + "_Reserved"))
152- let extractReservedBalance = match valueReservedBalance {
153- case a: Int =>
154- a
155- case _ =>
156- 0
157- }
158- let decreaseReservedBalance = (extractReservedBalance - betAmt)
159- if ((decreaseReservedBalance >= 0))
160- then decreaseReservedBalance
161- else throw("Reserved balance couldn't be less than 0")
162- }
163-
164-
165-func drumIntToString (drumInt) = if ((10 > drumInt))
166- then ("0" + toString(drumInt))
167- else toString(drumInt)
168-
169-
170-func defineMultiplier (threeInARow,twoInARow) = if ((threeInARow == "777"))
171- then 5370
172- else if ((threeInARow == "666"))
173- then 1300
174- else if ((threeInARow == "555"))
175- then 450
176- else if ((threeInARow == "444"))
177- then 200
178- else if ((threeInARow == "333"))
179- then 150
180- else if ((threeInARow == "222"))
181- then 110
182- else if ((threeInARow == "111"))
183- then 40
184- else if ((twoInARow == "77"))
185- then 270
186- else if ((twoInARow == "66"))
187- then 130
188- else if ((twoInARow == "55"))
189- then 65
190- else if ((twoInARow == "44"))
191- then 30
192- else if ((twoInARow == "33"))
193- then 20
194- else if ((twoInARow == "22"))
195- then 15
196- else if ((twoInARow == "11"))
197- then 10
198- else 0
199-
200-
201-func AssetNameToBase58 (assetName) = if ((assetName == "WAVES"))
202- then wavesId
203- else if ((assetName == "BTC"))
204- then btcId
205- else if ((assetName == "ETH"))
206- then ethId
207- else if ((assetName == "LTC"))
208- then ltcId
209- else if ((assetName == "VST"))
210- then vstId
211- else if ((assetName == "WCT"))
212- then wctId
213- else throw("Asset name is incorrect")
214-
215-
216-func assetBase58ToName (assetId) = if (!(isDefined(assetId)))
217- then "WAVES"
218- else if ((assetId == btcId))
219- then "BTC"
220- else if ((assetId == ethId))
221- then "ETH"
222- else if ((assetId == ltcId))
223- then "LTC"
224- else if ((assetId == wctId))
225- then "WCT"
226- else if ((assetId == vstId))
227- then "VST"
228- else throw("AssetId is incorrect")
229-
230-
231-@Callable(i)
232-func makeBet () = {
233- let pmt = extract(i.payment)
234- let betAmount = (pmt.amount - commission)
235- let assetId = pmt.assetId
236- let gameId = toBase58String(i.transactionId)
237- let gameStart = height
238- let playerPublicKey = toBase58String(i.callerPublicKey)
239- let pmtAssetName = assetBase58ToName(assetId)
240- let setReservedBalance = increaseReservedBalance(betAmount, pmtAssetName, pmt.assetId)
241- let pmtAmtCorrect = pmtAmtCheck(pmtAssetName, betAmount)
242- if (pmtAmtCorrect)
243- then {
244- let dataString = ((((((((stateAcc + "_") + playerPublicKey) + "_") + toString(betAmount)) + "_") + pmtAssetName) + "_") + toString(gameStart))
245- WriteSet([DataEntry((gameId + "_GameId"), dataString), DataEntry((pmtAssetName + "_Reserved"), setReservedBalance)])
246- }
247- else throw("assetId is incorrect")
248- }
249-
250-
251-
252-@Callable(i)
253-func playGame (gameId,rsaSign1,rsaSign2,rsaSign3) = {
254- let dataList = getDataList(gameId)
255- let gameState = dataList[0]
256- let playerAddress = addressFromPublicKey(fromBase58String(dataList[1]))
257- let betAmt = parseIntValue(dataList[2])
258- let assetName = dataList[3]
259- let gameStart = parseIntValue(dataList[4])
260- let assetId58 = AssetNameToBase58(assetName)
261- let setReservedBalance = decreaseReservedBalance(betAmt, assetName)
262- let drum1Int = rsaToInt(gameId, rsaSign1, rsaPublicKey1)
263- let drum2Int = rsaToInt(gameId, rsaSign2, rsaPublicKey2)
264- let drum3Int = rsaToInt(gameId, rsaSign3, rsaPublicKey3)
265- let threeInARow = ((drum1[drum1Int] + drum2[drum2Int]) + drum3[drum3Int])
266- let twoInARow = (drum1[drum1Int] + drum2[drum2Int])
267- let droppedElementsString = {
268- let drum1ToString = drumIntToString(drum1Int)
269- let drum2ToString = drumIntToString(drum2Int)
270- let drum3ToString = drumIntToString(drum3Int)
271- ((drum1ToString + drum2ToString) + drum3ToString)
272- }
273- let winAmt = {
274- let multiplier = defineMultiplier(threeInARow, twoInARow)
275- ((betAmt * multiplier) / 10)
276- }
277- let winPmtAmt = {
278- let balance = assetBalance(this, assetId58)
279- if ((winAmt > balance))
280- then (betAmt * 2)
281- else winAmt
282- }
283- let gameTimeCheck = (gameTimeFrame > (height - gameStart))
284- let stateCorrect = (gameState == stateAcc)
285- if (stateCorrect)
286- then if (gameTimeCheck)
287- then if ((winAmt == 0))
288- then WriteSet([DataEntry((gameId + "_GameId"), ((((((((((((((stateLose + "_") + dataList[1]) + "_") + dataList[2]) + "_") + dataList[3]) + "_") + toString(height)) + "_") + toString(winAmt)) + "_") + threeInARow) + "_") + droppedElementsString)), DataEntry((assetName + "_Reserved"), setReservedBalance)])
289- else ScriptResult(WriteSet([DataEntry((gameId + "_GameId"), ((((((((((((((stateWin + "_") + dataList[1]) + "_") + dataList[2]) + "_") + dataList[3]) + "_") + toString(height)) + "_") + toString(winAmt)) + "_") + threeInARow) + "_") + droppedElementsString)), DataEntry((assetName + "_Reserved"), setReservedBalance)]), TransferSet([ScriptTransfer(playerAddress, winPmtAmt, assetId58)]))
290- else ScriptResult(WriteSet([DataEntry((gameId + "_GameId"), ((((((((((((((stateTimeout + "_") + dataList[1]) + "_") + dataList[2]) + "_") + dataList[3]) + "_") + toString(height)) + "_") + toString((betAmt * 2))) + "_") + "000") + "_") + "000000")), DataEntry((assetName + "_Reserved"), setReservedBalance)]), TransferSet([ScriptTransfer(playerAddress, betAmt, assetId58)]))
291- else throw("Game state is incorrect")
292- }
293-
294-
295-@Verifier(tx)
296-func verify () = match tx {
297- case ttx: TransferTransaction =>
298- let assetName = assetBase58ToName(ttx.assetId)
299- let valueReservedBalance = getInteger(this, (assetName + "_Reserved"))
300- let reservedBalance = match valueReservedBalance {
301- case a: Int =>
302- a
303- case _ =>
304- 0
305- }
306- let availableBalance = (assetBalance(this, ttx.assetId) - reservedBalance)
307- let availibleAmount = (availableBalance >= ttx.amount)
308- let signature = sigVerify(ttx.bodyBytes, ttx.proofs[0], ttx.senderPublicKey)
309- if (availibleAmount)
310- then signature
311- else false
312- case sstx: SetScriptTransaction =>
313- sigVerify(sstx.bodyBytes, sstx.proofs[0], sstx.senderPublicKey)
314- case istx: InvokeScriptTransaction =>
315- sigVerify(istx.bodyBytes, istx.proofs[0], istx.senderPublicKey)
316- case dtx: DataTransaction =>
317- true
318- case _ =>
319- false
320-}
321-
1+# no script

github/deemru/w8io/169f3d6 
46.17 ms