tx · 4m21MpLuugmVJucmk6mwDGaahTC8cXFgsBiTeFoGu7qD 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs: -0.01400000 Waves 2019.09.06 15:59 [664229] smart account 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs > SELF 0.00000000 Waves
{ "type": 13, "id": "4m21MpLuugmVJucmk6mwDGaahTC8cXFgsBiTeFoGu7qD", "fee": 1400000, "feeAssetId": null, "timestamp": 1567774731756, "version": 1, "sender": "3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs", "senderPublicKey": "HSTmdhPrJF81ozDBaqVn8QVtV76oD7gzDfcHPQRdxdwW", "proofs": [ "GPyS3YAabau6i7rrAJCxSF8MimS9T7xcQFghQqZm9Gs6dvYxJBSyJTiLMoxQikeD5qVpJPqy7LMH4C6orStX4yi" ], "script": "base64:AAIDAAAAAAAAAAAAAAAIAAAAAA9TZXJ2ZXJQdWJsaWNLZXkJAAJZAAAAAQIAAAAsN2ltOWNhaUNtRTRTTDZqVG00S1RpY0hINGJHUGY1djU5cm5mVUEzY0NSRGoAAAAAElNlcnZlckJldFB1YmxpY0tleQkAAlkAAAABAgAAACw3aW05Y2FpQ21FNFNMNmpUbTRLVGljSEg0YkdQZjV2NTlybmZVQTNjQ1JEagAAAAAHV0FWRUxFVAkAAGgAAAACCQAAaAAAAAIAAAAAAAAAAGQAAAAAAAAAA+gAAAAAAAAAA+gAAAAACkNPTU1JU1NJT04JAABpAAAAAgkAAGgAAAACAAAAAAAAAAAFBQAAAAdXQVZFTEVUAAAAAAAAAAPoAAAAAAtUaWNrZXRzUmF0ZQAAAAAAAAAAZAEAAAAPR2VuZXJhdGVSYW5kSW50AAAAAwAAAAZnYW1lSWQAAAAHcnNhU2lnbgAAAApsYXN0VGlja2V0BAAAAAtyc2FTaWdWYWxpZAkAAfQAAAADCQABmwAAAAEFAAAABmdhbWVJZAUAAAAHcnNhU2lnbgUAAAAPU2VydmVyUHVibGljS2V5Aw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AAACAAAAAQIAAAAWUGxheWVyMSBub3QgdGhlIFdpbm5lcgAAAABEVK4e", "chainId": 84, "height": 664229, "spentComplexity": 0 } View: original | compacted Prev: 4TPt9aJMVsVfVQXjAiM1Wfw5ob8Q6n8emtr6jbTooUkD Next: 6MjK6a8hGxdYsfthntDygKdDQHemsf7ZmNC7B3zz26xs Diff:
Old | New | Differences | |
---|---|---|---|
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ServerPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
5 | + | ||
6 | + | let ServerBetPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
5 | 7 | ||
6 | 8 | let WAVELET = ((100 * 1000) * 1000) | |
7 | 9 | ||
45 | 47 | ||
46 | 48 | ||
47 | 49 | @Callable(i) | |
48 | - | func bet () = { | |
49 | - | let gameId = toBase58String(i.transactionId) | |
50 | + | func bet (gameId,gameIdCrypted,tickets) = { | |
50 | 51 | let pmt = extract(i.payment) | |
51 | 52 | let betNotInWaves = isDefined(pmt.assetId) | |
52 | 53 | let feeNotInWaves = isDefined(pmt.assetId) | |
57 | 58 | else if (feeNotInWaves) | |
58 | 59 | then throw("Transaction's fee must be in Waves") | |
59 | 60 | else { | |
60 | - | let gameDataStr = toString(playerAddress) | |
61 | - | let betData = [DataEntry(gameId, gameDataStr)] | |
62 | - | WriteSet(betData) | |
61 | + | let rsaSigValid = sigVerify(toBytes(gameId), gameIdCrypted, ServerBetPublicKey) | |
62 | + | if (rsaSigValid) | |
63 | + | then { | |
64 | + | let playerAddressStr = toString(playerAddress) | |
65 | + | let betData = [DataEntry((playerAddressStr + "_tickets"), tickets)] | |
66 | + | WriteSet(betData) | |
67 | + | } | |
68 | + | else throw("Invalid RSA signature") | |
63 | 69 | } | |
64 | 70 | } | |
65 | 71 |
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 | + | ||
6 | + | let ServerBetPublicKey = fromBase58String("7im9caiCmE4SL6jTm4KTicHH4bGPf5v59rnfUA3cCRDj") | |
5 | 7 | ||
6 | 8 | let WAVELET = ((100 * 1000) * 1000) | |
7 | 9 | ||
8 | 10 | let COMMISSION = ((5 * WAVELET) / 1000) | |
9 | 11 | ||
10 | 12 | let TicketsRate = 100 | |
11 | 13 | ||
12 | 14 | func GenerateRandInt (gameId,rsaSign,lastTicket) = { | |
13 | 15 | let rsaSigValid = sigVerify(toBytes(gameId), rsaSign, ServerPublicKey) | |
14 | 16 | if (rsaSigValid) | |
15 | 17 | then { | |
16 | 18 | let rand = (toInt(sha256(rsaSign)) % lastTicket) | |
17 | 19 | if ((0 > rand)) | |
18 | 20 | then ((-1 * rand) + 1) | |
19 | 21 | else (rand + 1) | |
20 | 22 | } | |
21 | 23 | else throw("Invalid RSA signature") | |
22 | 24 | } | |
23 | 25 | ||
24 | 26 | ||
25 | 27 | func getPlayers (gameId) = { | |
26 | 28 | let rawDataStr = match getString(this, gameId) { | |
27 | 29 | case str: String => | |
28 | 30 | str | |
29 | 31 | case _ => | |
30 | 32 | throw(("Couldn't find game by " + gameId)) | |
31 | 33 | } | |
32 | 34 | split(rawDataStr, "_") | |
33 | 35 | } | |
34 | 36 | ||
35 | 37 | ||
36 | 38 | func getPlayersTickets (gameId,Player) = { | |
37 | 39 | let playerTicketsStr = match getString(this, ((gameId + "_") + Player)) { | |
38 | 40 | case str: String => | |
39 | 41 | str | |
40 | 42 | case _ => | |
41 | 43 | throw(("Couldn't find game by " + gameId)) | |
42 | 44 | } | |
43 | 45 | split(playerTicketsStr, " ") | |
44 | 46 | } | |
45 | 47 | ||
46 | 48 | ||
47 | 49 | @Callable(i) | |
48 | - | func bet () = { | |
49 | - | let gameId = toBase58String(i.transactionId) | |
50 | + | func bet (gameId,gameIdCrypted,tickets) = { | |
50 | 51 | let pmt = extract(i.payment) | |
51 | 52 | let betNotInWaves = isDefined(pmt.assetId) | |
52 | 53 | let feeNotInWaves = isDefined(pmt.assetId) | |
53 | 54 | let playerPubKey58 = toBase58String(i.callerPublicKey) | |
54 | 55 | let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58)) | |
55 | 56 | if (betNotInWaves) | |
56 | 57 | then throw("Bet amount must be in Waves") | |
57 | 58 | else if (feeNotInWaves) | |
58 | 59 | then throw("Transaction's fee must be in Waves") | |
59 | 60 | else { | |
60 | - | let gameDataStr = toString(playerAddress) | |
61 | - | let betData = [DataEntry(gameId, gameDataStr)] | |
62 | - | WriteSet(betData) | |
61 | + | let rsaSigValid = sigVerify(toBytes(gameId), gameIdCrypted, ServerBetPublicKey) | |
62 | + | if (rsaSigValid) | |
63 | + | then { | |
64 | + | let playerAddressStr = toString(playerAddress) | |
65 | + | let betData = [DataEntry((playerAddressStr + "_tickets"), tickets)] | |
66 | + | WriteSet(betData) | |
67 | + | } | |
68 | + | else throw("Invalid RSA signature") | |
63 | 69 | } | |
64 | 70 | } | |
65 | 71 | ||
66 | 72 | ||
67 | 73 | ||
68 | 74 | @Callable(i) | |
69 | 75 | func generateResult (gameId,rsaSignCrypted,lastTicket) = { | |
70 | 76 | let rsaSign = fromBase58String(rsaSignCrypted) | |
71 | 77 | let randTicket = GenerateRandInt(gameId, rsaSign, lastTicket) | |
72 | 78 | let gameResult = [DataEntry((gameId + "_result"), toString(randTicket))] | |
73 | 79 | let playersList = getPlayers(gameId) | |
74 | 80 | let player1Tickets = getPlayersTickets(gameId, playersList[0]) | |
75 | 81 | let player1TicketFirst = parseIntValue(player1Tickets[0]) | |
76 | 82 | let player1TicketLast = parseIntValue(player1Tickets[1]) | |
77 | 83 | if (if ((randTicket >= player1TicketFirst)) | |
78 | 84 | then (player1TicketLast >= randTicket) | |
79 | 85 | else false) | |
80 | 86 | then { | |
81 | 87 | let winAmt = 100000000 | |
82 | 88 | ScriptResult(WriteSet(gameResult), TransferSet([ScriptTransfer(addressFromStringValue(playersList[0]), winAmt, unit)])) | |
83 | 89 | } | |
84 | 90 | else throw("Player1 not the Winner") | |
85 | 91 | } | |
86 | 92 | ||
87 | 93 |
github/deemru/w8io/026f985 28.60 ms ◑