tx · 81e8LDeP4zHvSMfPz2y4Ara8wbSrBcCDyxJXjKmyZf5h 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs: -0.01400000 Waves 2019.08.28 00:33 [650150] smart account 3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs > SELF 0.00000000 Waves
{ "type": 13, "id": "81e8LDeP4zHvSMfPz2y4Ara8wbSrBcCDyxJXjKmyZf5h", "fee": 1400000, "feeAssetId": null, "timestamp": 1566941616994, "version": 1, "sender": "3N2Z6EjzrzaCpD8ypDYLWDKe2PPVU8y9dJs", "senderPublicKey": "HSTmdhPrJF81ozDBaqVn8QVtV76oD7gzDfcHPQRdxdwW", "proofs": [ "3zmgDeaPW1NeVpiJkQwpMc3R9z7WTACn9e9jy5UdCriV4MhNQ21MX9G7BEeB2RnCainopq54BCga6H9qETDW1djV" ], "script": "base64:AAIDAAAAAAAAAAAAAAARAAAAAAdXQVZFTEVUCQAAaAAAAAIJAABoAAAAAgAAAAAAAAAAZAAAAAAAAAAD6AAAAAAAAAAD6AAAAAAKQ09NTUlTU0lPTgkAAGkAAAACCQAAaAAAAAIAAAAAAAAAAAUFAAAAB1dBVkVMRVQAAAAAAAAAA+gAAAAAClRva2VuUHJpY2UAAAAAAAAAAAoAAAAAEERPTkFURUNPVU5URVJLRVkCAAAACyRET05BVEVfTlVNAAAAAAdCVVlJVEVNAgAAAAkkQlVZX0lURU0AAAAABEJhZzEJAABoAAAAAgAAAAAAAAAAAQUAAAAHV0FWRUxFVAAAAAAEQmFnNQkAAGgAAAACAAAAAAAAAAAFBQAAAAdXQVZFTEVUAAAAAAVCYWcxMAkAAGgAAAACAAAAAAAAAAAKBQAAAAdXQVZFTEVUAAAAAAVCYWcyMAkAAGgAAAACAAAAAAAAAAAUBQAAAAdXQVZFTEVUAAAAAAVCYWc1MAkAAGgAAAACAAAAAAAAAAAyBQAAAAdXQVZFTEVUAAAAAAZCYWcxMDAJAABoAAAAAgAAAAAAAAAAZAUAAAA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FuY2UAAAABBQAAAAtrZXkyQmFsYW5jZQkAAGgAAAACBQAAAAlkb25hdGVOdW0FAAAAClRva2VuUHJpY2UEAAAACmRvbmF0ZURhdGEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAAEERPTkFURUNPVU5URVJLRVkFAAAACm5ld0dhbWVOdW0JAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIFAAAAC2tleTJCYWxhbmNlBQAAAApuZXdCYWxhbmNlCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACBQAAAAhkb25hdGVJZAUAAAAJZG9uYXRlTnVtBQAAAANuaWwJAQAAAAhXcml0ZVNldAAAAAEFAAAACmRvbmF0ZURhdGEJAAACAAAAAQIAAAAZWW91IHBhaWQgdGhlIHdyb25nIGFtb3VudAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAADCQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAgFAAAAAnR4AAAAD3NlbmRlclB1YmxpY0tleQQAAAAHJG1hdGNoMAUAAAACdHgDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAE1RyYW5zZmVyVHJhbnNhY3Rpb24EAAAAA3R0eAUAAAAHJG1hdGNoMAYDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAFFNldFNjcmlwdFRyYW5zYWN0aW9uBAAAAANzdHgFAAAAByRtYXRjaDAGBwcxd4yr", "chainId": 84, "height": 650150, "spentComplexity": 0 } View: original | compacted Prev: DW9N6GzVT9dS6xnAENzXWCwFyU4p7TFkjpnRNNAvzQeQ Next: CFW7wT9GkPHJ6X8nhsJgpveGuRPdRZSz6Cv9B2Ss7qFe Diff:
Old | New | Differences | |
---|---|---|---|
60 | 60 | } | |
61 | 61 | ||
62 | 62 | ||
63 | + | func getUserItemByKey (key) = { | |
64 | + | let rawDataStr = match getInteger(this, key) { | |
65 | + | case int: Int => | |
66 | + | int | |
67 | + | case _ => | |
68 | + | 0 | |
69 | + | } | |
70 | + | rawDataStr | |
71 | + | } | |
72 | + | ||
73 | + | ||
63 | 74 | @Callable(i) | |
64 | 75 | func buyItem (itemId) = { | |
65 | 76 | let buyTXId = toBase58String(i.transactionId) | |
72 | 83 | let NewBalance = (getBalance((playerAddress + "_balance")) - balanceMinus) | |
73 | 84 | let newBalanceData = DataEntry((playerAddress + "_balance"), NewBalance) | |
74 | 85 | let keyToItem = ((playerAddress + "_itemID_") + toString(itemId)) | |
75 | - | WriteSet([DataEntry(keyToItem, 1), DataEntry(((BUYITEM + "_") + buyTXId), itemId), newBalanceData]) | |
86 | + | let currentItemAmount = getUserItemByKey(keyToItem) | |
87 | + | WriteSet([DataEntry(keyToItem, (currentItemAmount + 1)), DataEntry(((BUYITEM + "_") + buyTXId), itemId), newBalanceData]) | |
76 | 88 | } | |
77 | 89 | else throw("Item has not found") | |
78 | 90 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let WAVELET = ((100 * 1000) * 1000) | |
5 | 5 | ||
6 | 6 | let COMMISSION = ((5 * WAVELET) / 1000) | |
7 | 7 | ||
8 | 8 | let TokenPrice = 10 | |
9 | 9 | ||
10 | 10 | let DONATECOUNTERKEY = "$DONATE_NUM" | |
11 | 11 | ||
12 | 12 | let BUYITEM = "$BUY_ITEM" | |
13 | 13 | ||
14 | 14 | let Bag1 = (1 * WAVELET) | |
15 | 15 | ||
16 | 16 | let Bag5 = (5 * WAVELET) | |
17 | 17 | ||
18 | 18 | let Bag10 = (10 * WAVELET) | |
19 | 19 | ||
20 | 20 | let Bag20 = (20 * WAVELET) | |
21 | 21 | ||
22 | 22 | let Bag50 = (50 * WAVELET) | |
23 | 23 | ||
24 | 24 | let Bag100 = (100 * WAVELET) | |
25 | 25 | ||
26 | 26 | let itemMax = 20 | |
27 | 27 | ||
28 | 28 | let prices = [1, 3, 5, 6, 2, 2, 4, 9, 10, 12, 5, 1, 9, 12, 5, 4, 1, 11, 12, 9] | |
29 | 29 | ||
30 | 30 | func IncrementDonateNum () = { | |
31 | 31 | let gameNum = match getInteger(this, DONATECOUNTERKEY) { | |
32 | 32 | case num: Int => | |
33 | 33 | num | |
34 | 34 | case _ => | |
35 | 35 | 0 | |
36 | 36 | } | |
37 | 37 | (gameNum + 1) | |
38 | 38 | } | |
39 | 39 | ||
40 | 40 | ||
41 | 41 | func getBalance (key) = { | |
42 | 42 | let playerBalanceNum = match getInteger(this, key) { | |
43 | 43 | case playerBalanceNum: Int => | |
44 | 44 | playerBalanceNum | |
45 | 45 | case _ => | |
46 | 46 | 0 | |
47 | 47 | } | |
48 | 48 | playerBalanceNum | |
49 | 49 | } | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func isItemExist (oldItemsList,itemId) = { | |
53 | 53 | let rawDataStr = match indexOf(oldItemsList, (itemId + ":")) { | |
54 | 54 | case int: Int => | |
55 | 55 | toString(int) | |
56 | 56 | case _ => | |
57 | 57 | "undefined" | |
58 | 58 | } | |
59 | 59 | rawDataStr | |
60 | 60 | } | |
61 | 61 | ||
62 | 62 | ||
63 | + | func getUserItemByKey (key) = { | |
64 | + | let rawDataStr = match getInteger(this, key) { | |
65 | + | case int: Int => | |
66 | + | int | |
67 | + | case _ => | |
68 | + | 0 | |
69 | + | } | |
70 | + | rawDataStr | |
71 | + | } | |
72 | + | ||
73 | + | ||
63 | 74 | @Callable(i) | |
64 | 75 | func buyItem (itemId) = { | |
65 | 76 | let buyTXId = toBase58String(i.transactionId) | |
66 | 77 | let playerAddress = toString(i.caller) | |
67 | 78 | if (if ((itemId > 0)) | |
68 | 79 | then (itemMax >= itemId) | |
69 | 80 | else false) | |
70 | 81 | then { | |
71 | 82 | let balanceMinus = prices[itemId] | |
72 | 83 | let NewBalance = (getBalance((playerAddress + "_balance")) - balanceMinus) | |
73 | 84 | let newBalanceData = DataEntry((playerAddress + "_balance"), NewBalance) | |
74 | 85 | let keyToItem = ((playerAddress + "_itemID_") + toString(itemId)) | |
75 | - | WriteSet([DataEntry(keyToItem, 1), DataEntry(((BUYITEM + "_") + buyTXId), itemId), newBalanceData]) | |
86 | + | let currentItemAmount = getUserItemByKey(keyToItem) | |
87 | + | WriteSet([DataEntry(keyToItem, (currentItemAmount + 1)), DataEntry(((BUYITEM + "_") + buyTXId), itemId), newBalanceData]) | |
76 | 88 | } | |
77 | 89 | else throw("Item has not found") | |
78 | 90 | } | |
79 | 91 | ||
80 | 92 | ||
81 | 93 | ||
82 | 94 | @Callable(i) | |
83 | 95 | func reset () = { | |
84 | 96 | let playerAddress = toString(i.caller) | |
85 | 97 | let donateData = [DataEntry(DONATECOUNTERKEY, 0), DataEntry((playerAddress + "_balance"), 0)] | |
86 | 98 | WriteSet(donateData) | |
87 | 99 | } | |
88 | 100 | ||
89 | 101 | ||
90 | 102 | ||
91 | 103 | @Callable(i) | |
92 | 104 | func donate () = { | |
93 | 105 | let newGameNum = IncrementDonateNum() | |
94 | 106 | let donateId = toBase58String(i.transactionId) | |
95 | 107 | let pmt = extract(i.payment) | |
96 | 108 | let playerAddress = toString(i.caller) | |
97 | 109 | let betNotInWaves = isDefined(pmt.assetId) | |
98 | 110 | let feeNotInWaves = isDefined(pmt.assetId) | |
99 | 111 | let donateAmt = pmt.amount | |
100 | 112 | if (betNotInWaves) | |
101 | 113 | then throw("Bet amount must be in Waves") | |
102 | 114 | else if (feeNotInWaves) | |
103 | 115 | then throw("Transaction's fee must be in Waves") | |
104 | 116 | else { | |
105 | 117 | let donateAmtValid = if (if (if (if (if (if ((donateAmt == (Bag1 + COMMISSION))) | |
106 | 118 | then true | |
107 | 119 | else (donateAmt == (Bag5 + COMMISSION))) | |
108 | 120 | then true | |
109 | 121 | else (donateAmt == (Bag10 + COMMISSION))) | |
110 | 122 | then true | |
111 | 123 | else (donateAmt == (Bag20 + COMMISSION))) | |
112 | 124 | then true | |
113 | 125 | else (donateAmt == (Bag50 + COMMISSION))) | |
114 | 126 | then true | |
115 | 127 | else (donateAmt == (Bag100 + COMMISSION))) | |
116 | 128 | then true | |
117 | 129 | else false | |
118 | 130 | if (donateAmtValid) | |
119 | 131 | then { | |
120 | 132 | let donateNum = ((donateAmt - COMMISSION) / WAVELET) | |
121 | 133 | let key2Balance = (playerAddress + "_balance") | |
122 | 134 | let newBalance = (getBalance(key2Balance) + (donateNum * TokenPrice)) | |
123 | 135 | let donateData = [DataEntry(DONATECOUNTERKEY, newGameNum), DataEntry(key2Balance, newBalance), DataEntry(donateId, donateNum)] | |
124 | 136 | WriteSet(donateData) | |
125 | 137 | } | |
126 | 138 | else throw("You paid the wrong amount") | |
127 | 139 | } | |
128 | 140 | } | |
129 | 141 | ||
130 | 142 | ||
131 | 143 | @Verifier(tx) | |
132 | 144 | func verify () = if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) | |
133 | 145 | then match tx { | |
134 | 146 | case ttx: TransferTransaction => | |
135 | 147 | true | |
136 | 148 | case stx: SetScriptTransaction => | |
137 | 149 | true | |
138 | 150 | case _ => | |
139 | 151 | false | |
140 | 152 | } | |
141 | 153 | else false | |
142 | 154 |
github/deemru/w8io/026f985 34.05 ms ◑