tx · 5tEKP6aVwiDYZSB1sW2Zrrn2cjuUeEa1W1bxU51MuT2W 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs: -0.01400000 Waves 2019.09.07 01:59 [664842] smart account 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs > SELF 0.00000000 Waves
{ "type": 13, "id": "5tEKP6aVwiDYZSB1sW2Zrrn2cjuUeEa1W1bxU51MuT2W", "fee": 1400000, "feeAssetId": null, "timestamp": 1567809845065, "version": 1, "sender": "3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs", "senderPublicKey": "HSTmdhPrJF81ozDBaqVn8QVtV76oD7gzDfcHPQRdxdwW", "proofs": [ "37uhkk8cvuMDaQk6umVPnZRRiM8JZMEU73PgdEiY54gmDa16tJS7QFPJ4cEZwfRsoU9rcJuPgiZNE3htdRb4Grdn" ], "script": "base64:AAIDAAAAAAAAAAAAAAAKAAAAAA9TZXJ2ZXJQdWJsaWNLZXkJAAJZAAAAAQIAAAAsN2ltOWNhaUNtRTRTTDZqVG00S1RpY0hINGJHUGY1djU5cm5mVUEzY0NSRGoAAAAAElNlcnZlckJldFB1YmxpY0tleQkAAlkAAAABAgAAACw3aW05Y2FpQ21FNFNMNmpUbTRLVGljSEg0YkdQZjV2NTlybmZVQTNjQ1JEagAAAAAHV0FWRUxFVAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAA+gAAAAAAAAAA+gAAAAACkNPTU1JU1NJT04JAABpAAAAAgkAAGgAAAACAAAAAAAAAAAFBQAAAAdXQVZFTEVUAAAAAAAAAAPoAQAAAA9HZW5lcmF0ZVJhbmRJbnQAAAADAAAABmdhbWVJZAAAAAdyc2FTaWduAAAACmxhc3RUaWNrZXQEAAAAC3JzYVNpZ1ZhbGlkCQAB9AAAAAMJAAGbAAAAAQUAAAAGZ2FtZUlkBQAAAAdyc2FTaWduBQAAAA9TZXJ2ZXJQdWJsaWNLZXkDBQAAAAtyc2FTaWd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50c0xpc3QFAAAACXdpbm5lck51bQUAAAAEdW5pdAUAAAADbmlsBAAAAApnYW1lUmVzdWx0CQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQABLAAAAAIFAAAABmdhbWVJZAIAAAAHX3Jlc3VsdAkAAaQAAAABBQAAAAl3aW5UaWNrZXQJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAAGZ2FtZUlkAgAAAAdfd2lubmVyCQABkQAAAAIFAAAAC3BsYXllcnNMaXN0BQAAAAl3aW5uZXJOdW0JAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAAGZ2FtZUlkAgAAAAdfd2luQW10CQABkQAAAAIFAAAADndpbkFtb3VudHNMaXN0BQAAAAl3aW5uZXJOdW0FAAAAA25pbAkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEFAAAACmdhbWVSZXN1bHQJAQAAAAtUcmFuc2ZlclNldAAAAAEFAAAABXdpblRYAAAAAIOrGsA=", "chainId": 84, "height": 664842, "spentComplexity": 0 } View: original | compacted Prev: 6MjK6a8hGxdYsfthntDygKdDQHemsf7ZmNC7B3zz26xs Next: DuKUZisMxrbKqG5HgJ8c8Up3NNwkATXhM6zwGMtQb5UZ Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ServerPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
5 | 5 | ||
6 | 6 | let ServerBetPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
7 | 7 | ||
8 | 8 | let WAVELET = ((100 * 1000) * 1000) | |
9 | 9 | ||
10 | 10 | let COMMISSION = ((5 * WAVELET) / 1000) | |
11 | 11 | ||
12 | 12 | func GenerateRandInt (gameId,rsaSign,lastTicket) = { | |
13 | 13 | let rsaSigValid = sigVerify(toBytes(gameId), rsaSign, ServerPublicKey) | |
14 | 14 | if (rsaSigValid) | |
15 | 15 | then { | |
16 | 16 | let rand = (toInt(sha256(rsaSign)) % lastTicket) | |
17 | 17 | if ((0 > rand)) | |
18 | 18 | then ((-1 * rand) + 1) | |
19 | 19 | else (rand + 1) | |
20 | 20 | } | |
21 | 21 | else throw("Invalid RSA signature") | |
22 | 22 | } | |
23 | 23 | ||
24 | 24 | ||
25 | 25 | func getPlayersTickets (gameId,player) = { | |
26 | 26 | let ticketsStr = (((gameId + "_") + player) + "_tickets") | |
27 | 27 | let playerTicketsStr = getStringValue(this, ticketsStr) | |
28 | 28 | playerTicketsStr | |
29 | 29 | } | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func ParseNextAttribute (remaining) = { | |
33 | 33 | let s = size(remaining) | |
34 | 34 | if ((s > 0)) | |
35 | 35 | then { | |
36 | 36 | let nn = parseIntValue(take(remaining, 2)) | |
37 | 37 | let v = take(drop(remaining, 2), nn) | |
38 | 38 | let tmpRemaining = drop(remaining, (nn + 2)) | |
39 | 39 | let remainingState = tmpRemaining | |
40 | 40 | [v, remainingState] | |
41 | 41 | } | |
42 | 42 | else throw("Empty string was passed into parseNextAttribute func") | |
43 | 43 | } | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func parseBetStr (ticketsStr) = ["1", "100", "101", "300", "0", "0", "0", "0"] | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func isWinner (gameId,player,winTicket) = { | |
50 | 50 | let playersTicket = getPlayersTickets(gameId, player) | |
51 | 51 | let bets = parseBetStr(playersTicket) | |
52 | 52 | if (if ((winTicket >= parseIntValue(bets[0]))) | |
53 | 53 | then (parseIntValue(bets[1]) >= winTicket) | |
54 | 54 | else false) | |
55 | 55 | then true | |
56 | 56 | else if (if ((winTicket >= parseIntValue(bets[2]))) | |
57 | 57 | then (parseIntValue(bets[3]) >= winTicket) | |
58 | 58 | else false) | |
59 | 59 | then true | |
60 | 60 | else if (if ((winTicket >= parseIntValue(bets[4]))) | |
61 | 61 | then (parseIntValue(bets[5]) >= winTicket) | |
62 | 62 | else false) | |
63 | 63 | then true | |
64 | 64 | else if (if ((winTicket >= parseIntValue(bets[6]))) | |
65 | 65 | then (parseIntValue(bets[7]) >= winTicket) | |
66 | 66 | else false) | |
67 | 67 | then true | |
68 | 68 | else false | |
69 | 69 | } | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func defineWinner (gameId,players,winAmounts,winTicket) = { | |
73 | 73 | let playersList = split(players, "_") | |
74 | 74 | let winAmountsList = split(winAmounts, "_") | |
75 | 75 | if (isWinner(gameId, playersList[0], winTicket)) | |
76 | 76 | then 0 | |
77 | 77 | else if (isWinner(gameId, playersList[1], winTicket)) | |
78 | 78 | then 1 | |
79 | 79 | else if (isWinner(gameId, playersList[2], winTicket)) | |
80 | 80 | then 2 | |
81 | 81 | else if (isWinner(gameId, playersList[3], winTicket)) | |
82 | 82 | then 3 | |
83 | 83 | else if (isWinner(gameId, playersList[4], winTicket)) | |
84 | 84 | then 4 | |
85 | 85 | else if (isWinner(gameId, playersList[5], winTicket)) | |
86 | 86 | then 5 | |
87 | 87 | else throw("Error with defining winner") | |
88 | 88 | } | |
89 | 89 | ||
90 | 90 | ||
91 | 91 | @Callable(i) | |
92 | 92 | func bet (gameId,gameIdCryptedStr,tickets) = { | |
93 | 93 | let gameIdCrypted = fromBase58String(gameIdCryptedStr) | |
94 | 94 | let pmt = extract(i.payment) | |
95 | 95 | let betNotInWaves = isDefined(pmt.assetId) | |
96 | 96 | let feeNotInWaves = isDefined(pmt.assetId) | |
97 | 97 | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
98 | 98 | let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58)) | |
99 | 99 | let gameStillOpen = isDefined(getString(this, (gameId + "_result"))) | |
100 | 100 | if (!(gameStillOpen)) | |
101 | 101 | then if (betNotInWaves) | |
102 | 102 | then throw("Bet amount must be in Waves") | |
103 | 103 | else if (feeNotInWaves) | |
104 | 104 | then throw("Transaction's fee must be in Waves") | |
105 | 105 | else { | |
106 | 106 | let rsaSigValid = sigVerify(toBytes(gameId), gameIdCrypted, ServerBetPublicKey) | |
107 | 107 | if (rsaSigValid) | |
108 | 108 | then { | |
109 | 109 | let playerAddressStr = toString(playerAddress) | |
110 | 110 | let betData = [DataEntry((((gameId + "_") + playerAddressStr) + "_tickets"), tickets)] | |
111 | 111 | WriteSet(betData) | |
112 | 112 | } | |
113 | 113 | else throw("Invalid RSA signature") | |
114 | 114 | } | |
115 | 115 | else throw("This game already end, try make bet again") | |
116 | 116 | } | |
117 | 117 | ||
118 | 118 | ||
119 | 119 | ||
120 | 120 | @Callable(i) | |
121 | 121 | func generateResult (gameId,rsaSignCrypted,lastTicket,players,winAmounts) = { | |
122 | 122 | let rsaSign = fromBase58String(rsaSignCrypted) | |
123 | 123 | let winTicket = GenerateRandInt(gameId, rsaSign, lastTicket) | |
124 | 124 | let playersList = split(players, "_") | |
125 | 125 | let winAmountsList = split(winAmounts, "_") | |
126 | 126 | let winnerNum = defineWinner(gameId, players, winAmounts, winTicket) | |
127 | 127 | let winTX = [ScriptTransfer(addressFromStringValue(playersList[winnerNum]), parseIntValue(winAmountsList[winnerNum]), unit)] | |
128 | 128 | let gameResult = [DataEntry((gameId + "_result"), toString(winTicket)), DataEntry((gameId + "_winner"), playersList[winnerNum]), DataEntry((gameId + "_winAmt"), winAmountsList[winnerNum])] | |
129 | 129 | ScriptResult(WriteSet(gameResult), TransferSet(winTX)) | |
130 | 130 | } | |
131 | 131 | ||
132 | 132 |
github/deemru/w8io/026f985 40.09 ms ◑