tx · BdcbaA9oBiVYJpP7HCLpMmnisL3mptRw2ZkBsYowHGSV 3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE: -0.01400000 Waves 2019.09.08 08:33 [666688] smart account 3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE > SELF 0.00000000 Waves
{ "type": 13, "id": "BdcbaA9oBiVYJpP7HCLpMmnisL3mptRw2ZkBsYowHGSV", "fee": 1400000, "feeAssetId": null, "timestamp": 1567920792753, "version": 1, "sender": "3N9XnyPpWxYohKH7z5dEuq8rpnobpyzPrzE", "senderPublicKey": "ESNVczQiY4oxY2hoRSZcruKNBwsPdXVu1nSCbpprDGJB", "proofs": [ "3UGkijM49ZYe1ehZNP3ykLBnmBJ7cq4M4tHSqehYBDKGS77EowCVgrCvt795hAFBnmvb63zWxt8dyLfmQtJPiviX" ], "script": "base64:AAIDAAAAAAAAAAAAAAAOAAAAAA9TZXJ2ZXJQdWJsaWNLZXkJAAJZAAAAAQIAAAAsN2ltOWNhaUNtRTRTTDZqVG00S1RpY0hINGJHUGY1djU5cm5mVUEzY0NSRGoAAAAACUJldFNlcnZlcgkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABAgAAACMzTjZ5Rko1WjhOVVVRdmZHR01McDVlZm1ldlJSdFRnUXV1bgAAAAAHV0FWRUxFVAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAA+gAAAAAAAAAA+gAAAAACkNPTU1JU1NJT04JAABpAAAAAgkAAGgAAAACAAAAAAAAAAAFBQAAAAdXQVZFTEVUAAAAAAAAAAPoAAAAAA5UaWNrZXRzUGVyV2F2ZQAAAAAAAAAAZAAAAAALQ1VSUkVOVEdBTUUCAAAADSRDVVJSRU5UX0dBTUUAAAAACkxBU1RUSUNLRVQCAAAADCRMQVNUX1RJQ0tFVAEAAAAPR2VuZXJhdGVSYW5kSW50AAAAAgAAAAZnYW1lSWQAAAAHcnNhU2lnbgQAAAAKbGFzdFRp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cgUAAAAQd2lubmVyQWRkcmVzc1N0cgkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkAASwAAAACBQAAAAZnYW1lSWQCAAAAB193aW5BbXQFAAAABndpbkFtdAUAAAADbmlsCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQUAAAAKZ2FtZVJlc3VsdAkBAAAAC1RyYW5zZmVyU2V0AAAAAQUAAAAFd2luVFgJAAACAAAAAQkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAQQ3VycmVudCBHYW1lIGlzIAUAAAALY3VycmVudEdhbWUCAAAACiwgYnV0IG5vdCAFAAAABmdhbWVJZAAAAABdVjkV", "chainId": 84, "height": 666688, "spentComplexity": 0 } View: original | compacted Prev: none Next: Gb1METas8sCSMMZjfEWKYCAEMhmCLotbQmPmcWTT9jZB Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 3 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let ServerPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
5 | + | ||
6 | + | let BetServer = addressFromStringValue("3N6yFJ5Z8NUUQvfGGMLp5efmevRRtTgQuun") | |
7 | + | ||
8 | + | let WAVELET = ((100 * 1000) * 1000) | |
9 | + | ||
10 | + | let COMMISSION = ((5 * WAVELET) / 1000) | |
11 | + | ||
12 | + | let TicketsPerWave = 100 | |
13 | + | ||
14 | + | let CURRENTGAME = "$CURRENT_GAME" | |
15 | + | ||
16 | + | let LASTTICKET = "$LAST_TICKET" | |
17 | + | ||
18 | + | func GenerateRandInt (gameId,rsaSign) = { | |
19 | + | let lastTicket = getIntegerValue(BetServer, LASTTICKET) | |
20 | + | let rsaSigValid = sigVerify(toBytes(gameId), rsaSign, ServerPublicKey) | |
21 | + | if (rsaSigValid) | |
22 | + | then { | |
23 | + | let rand = (toInt(sha256(rsaSign)) % lastTicket) | |
24 | + | if ((0 > rand)) | |
25 | + | then ((-1 * rand) + 1) | |
26 | + | else (rand + 1) | |
27 | + | } | |
28 | + | else throw("Invalid RSA signature") | |
29 | + | } | |
30 | + | ||
31 | + | ||
32 | + | func getPlayersTickets (gameId,player) = { | |
33 | + | let ticketsStr = (((gameId + "_") + player) + "_tickets") | |
34 | + | getStringValue(BetServer, ticketsStr) | |
35 | + | } | |
36 | + | ||
37 | + | ||
38 | + | func ParseNextAttribute (remaining) = { | |
39 | + | let s = size(remaining) | |
40 | + | if ((s > 0)) | |
41 | + | then { | |
42 | + | let nn = parseIntValue(take(remaining, 2)) | |
43 | + | let v = take(drop(remaining, 2), nn) | |
44 | + | let tmpRemaining = drop(remaining, (nn + 2)) | |
45 | + | let remainingState = tmpRemaining | |
46 | + | [v, remainingState] | |
47 | + | } | |
48 | + | else throw("Empty string was passed into parseNextAttribute func") | |
49 | + | } | |
50 | + | ||
51 | + | ||
52 | + | func parseTicketsStr (ticketsStr) = ["1", "100", "101", "300", "0", "0", "0", "0"] | |
53 | + | ||
54 | + | ||
55 | + | func isWinner (gameId,player,winTicket) = { | |
56 | + | let tickets = parseTicketsStr(getPlayersTickets(gameId, player)) | |
57 | + | if (if ((winTicket >= parseIntValue(tickets[0]))) | |
58 | + | then (parseIntValue(tickets[1]) >= winTicket) | |
59 | + | else false) | |
60 | + | then true | |
61 | + | else if (if ((winTicket >= parseIntValue(tickets[2]))) | |
62 | + | then (parseIntValue(tickets[3]) >= winTicket) | |
63 | + | else false) | |
64 | + | then true | |
65 | + | else if (if ((winTicket >= parseIntValue(tickets[4]))) | |
66 | + | then (parseIntValue(tickets[5]) >= winTicket) | |
67 | + | else false) | |
68 | + | then true | |
69 | + | else if (if ((winTicket >= parseIntValue(tickets[6]))) | |
70 | + | then (parseIntValue(tickets[7]) >= winTicket) | |
71 | + | else false) | |
72 | + | then true | |
73 | + | else false | |
74 | + | } | |
75 | + | ||
76 | + | ||
77 | + | func defineWinner (gameId,winTicket) = { | |
78 | + | let players = getStringValue(BetServer, (gameId + "_players")) | |
79 | + | let playersList = split(players, "_") | |
80 | + | if (isWinner(gameId, playersList[0], winTicket)) | |
81 | + | then playersList[0] | |
82 | + | else if (isWinner(gameId, playersList[1], winTicket)) | |
83 | + | then playersList[1] | |
84 | + | else if (isWinner(gameId, playersList[2], winTicket)) | |
85 | + | then playersList[2] | |
86 | + | else if (isWinner(gameId, playersList[3], winTicket)) | |
87 | + | then playersList[3] | |
88 | + | else throw("Error with defining winner") | |
89 | + | } | |
90 | + | ||
91 | + | ||
92 | + | func defineWinAmt (winnerAddressStr) = (1 * WAVELET) | |
93 | + | ||
94 | + | ||
95 | + | @Callable(i) | |
96 | + | func generateResult (gameId,rsaSignCrypted) = { | |
97 | + | let currentGame = getStringValue(BetServer, CURRENTGAME) | |
98 | + | if ((currentGame == gameId)) | |
99 | + | then { | |
100 | + | let rsaSign = fromBase58String(rsaSignCrypted) | |
101 | + | let winTicket = GenerateRandInt(gameId, rsaSign) | |
102 | + | let winnerAddressStr = "3N6xavpiLALkk4H4qWfeZ4N1cmvoykyToBa" | |
103 | + | let winAmt = defineWinAmt(winnerAddressStr) | |
104 | + | let winTX = [ScriptTransfer(addressFromStringValue(winnerAddressStr), winAmt, unit)] | |
105 | + | let gameResult = [DataEntry((gameId + "_result"), toString(winTicket)), DataEntry((gameId + "_winner"), winnerAddressStr), DataEntry((gameId + "_winAmt"), winAmt)] | |
106 | + | ScriptResult(WriteSet(gameResult), TransferSet(winTX)) | |
107 | + | } | |
108 | + | else throw(((("Current Game is " + currentGame) + ", but not ") + gameId)) | |
109 | + | } | |
110 | + | ||
111 | + |
github/deemru/w8io/169f3d6 20.98 ms ◑