tx · AVpRTwsoD2iQKCsRZAHTDdUNkSj9iXze222qHyuDZ1Yv 3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR: -0.01400000 Waves 2019.07.20 04:45 [593571] smart account 3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR > SELF 0.00000000 Waves
{ "type": 13, "id": "AVpRTwsoD2iQKCsRZAHTDdUNkSj9iXze222qHyuDZ1Yv", "fee": 1400000, "feeAssetId": null, "timestamp": 1563587125651, "version": 1, "sender": "3N7MT5t1Gmyb9tcpdoUrd47pxXtTkAcgLsR", "senderPublicKey": "Adn8NfJZ8ZXuWNMXb9VaY6X6kh6k6G3KMb1WQUesFUV", "proofs": [ "4UUkjr9mZy5fdcYTiHQ8AdnfxkZ855bM7SJj5bPDAQXMahVATZLhyWdLSeCcFXRC1Yfvj9AnGw6SrtJpEC8JZFBb" ], "script": "base64:AAIDAAAAAAAAAAAAAAAeAAAAAA5vd25lclB1YmxpY0tleQEAAAAgAnfP9tCFuj2k2BUY5PW9DVGxrCHBHKJwugv8WyiaGXIAAAAABE5PTkUCAAAABG5vbmUAAAAABlZPVEVSUwAAAAAAAAAAAwAAAAAGUVVPUlVNAAAAAAAAAAACAAAAAAZWT1RJTkcCAAAABnZvdGluZwAAAAAGUkVWRUFMAgAAAAZyZXZlYWwAAAAACEZFQVRVUkVEAgAAAAhmZWF0dXJlZAAAAAAIREVMSVNURUQCAAAACGRlbGlzdGVkAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAA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gAAABhhbiBpdGVtIGlzIGFscmVhZHkgZXhpc3QJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABJnZXRLZXlJdGVtU3VwcGxpZXIAAAABBQAAAARpdGVtBQAAAA9zdXBwbGllckFkZHJlc3MJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA9nZXRLZXlJdGVtUHJpY2UAAAABBQAAAARpdGVtBQAAAAVwcmljZQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAADmdldEtleUl0ZW1EYXRhAAAAAQUAAAAEaXRlbQUAAAAEZGF0YQUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAQAAAAHJG1hdGNoMAUAAAACdHgDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAFFNldFNjcmlwdFRyYW5zYWN0aW9uBAAAAAFkBQAAAAckbWF0Y2gwCQAB9AAAAAMIBQAAAAJ0eAAAAAlib2R5Qnl0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAUAAAAOb3duZXJQdWJsaWNLZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAD0RhdGFUcmFuc2FjdGlvbgQAAAABZAUAAAAHJG1hdGNoMAYDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAE1RyYW5zZmVyVHJhbnNhY3Rpb24EAAAAAWQFAAAAByRtYXRjaDAGBxQ+K+c=", "chainId": 84, "height": 593571, "spentComplexity": 0 } View: original | compacted Prev: GYnxM71YvMp6wtjcJX9KgVWNT4jdQUBBf6zVSZ5XRAsT Next: GbCTF6wgEJEanmzjwuyYgXTZ3RSR4QqmbrNJD9Z4qVbd Diff:
Old | New | Differences | |
---|---|---|---|
100 | 100 | ||
101 | 101 | ||
102 | 102 | @Callable(i) | |
103 | + | func voteReveal (item,vote,salt) = { | |
104 | + | let user = toBase58String(i.caller.bytes) | |
105 | + | let status = getValueItemStatus(item) | |
106 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
107 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
108 | + | then throw("reveal data is not valid") | |
109 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
110 | + | then throw("max num of voters hasn't been reached yet") | |
111 | + | else if ((getValueReveal(item, user) != NONE)) | |
112 | + | then throw("user has already participated") | |
113 | + | else if (if ((status != VOTING)) | |
114 | + | then (status != REVEAL) | |
115 | + | else false) | |
116 | + | then throw("wrong status") | |
117 | + | else if (if ((vote != FEATURED)) | |
118 | + | then (vote != DELISTED) | |
119 | + | else false) | |
120 | + | then throw("wrong vote") | |
121 | + | else if (if ((status == FEATURED)) | |
122 | + | then true | |
123 | + | else (status == DELISTED)) | |
124 | + | then throw("vote has finished") | |
125 | + | else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
126 | + | then vote | |
127 | + | else REVEAL)]) | |
128 | + | } | |
129 | + | ||
130 | + | ||
131 | + | ||
132 | + | @Callable(i) | |
103 | 133 | func voteCommit (item,hash) = { | |
104 | 134 | let user = toBase58String(i.caller.bytes) | |
105 | 135 | let commits = getValueCommitsCount(item) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let ownerPublicKey = base58'Adn8NfJZ8ZXuWNMXb9VaY6X6kh6k6G3KMb1WQUesFUV' | |
5 | 5 | ||
6 | 6 | let NONE = "none" | |
7 | 7 | ||
8 | 8 | let VOTERS = 3 | |
9 | 9 | ||
10 | 10 | let QUORUM = 2 | |
11 | 11 | ||
12 | 12 | let VOTING = "voting" | |
13 | 13 | ||
14 | 14 | let REVEAL = "reveal" | |
15 | 15 | ||
16 | 16 | let FEATURED = "featured" | |
17 | 17 | ||
18 | 18 | let DELISTED = "delisted" | |
19 | 19 | ||
20 | 20 | func getNumberByKey (key) = { | |
21 | 21 | let num = match getInteger(this, key) { | |
22 | 22 | case a: Int => | |
23 | 23 | a | |
24 | 24 | case _ => | |
25 | 25 | 0 | |
26 | 26 | } | |
27 | 27 | num | |
28 | 28 | } | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getStrByKey (key) = { | |
32 | 32 | let str = match getString(this, key) { | |
33 | 33 | case a: String => | |
34 | 34 | a | |
35 | 35 | case _ => | |
36 | 36 | NONE | |
37 | 37 | } | |
38 | 38 | str | |
39 | 39 | } | |
40 | 40 | ||
41 | 41 | ||
42 | 42 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func getKeyCommitsCount (item) = (item + "_comcnt") | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func getKeyItemStatus (item) = (item + "_status") | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
67 | 67 | ||
68 | 68 | ||
69 | 69 | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
70 | 70 | ||
71 | 71 | ||
72 | 72 | func getKeyItemPrice (item) = (item + "_price") | |
73 | 73 | ||
74 | 74 | ||
75 | 75 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
76 | 76 | ||
77 | 77 | ||
78 | 78 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
82 | 82 | ||
83 | 83 | ||
84 | 84 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
85 | 85 | ||
86 | 86 | ||
87 | 87 | func getKeyItemData (item) = (item + "_data") | |
88 | 88 | ||
89 | 89 | ||
90 | 90 | func getKeyItemSupplier (item) = (item + "_owner") | |
91 | 91 | ||
92 | 92 | ||
93 | 93 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
94 | 94 | ||
95 | 95 | ||
96 | 96 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
97 | 97 | ||
98 | 98 | ||
99 | 99 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
100 | 100 | ||
101 | 101 | ||
102 | 102 | @Callable(i) | |
103 | + | func voteReveal (item,vote,salt) = { | |
104 | + | let user = toBase58String(i.caller.bytes) | |
105 | + | let status = getValueItemStatus(item) | |
106 | + | let newVoteCount = (getValueVoteCount(item, vote) + 1) | |
107 | + | if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user))) | |
108 | + | then throw("reveal data is not valid") | |
109 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
110 | + | then throw("max num of voters hasn't been reached yet") | |
111 | + | else if ((getValueReveal(item, user) != NONE)) | |
112 | + | then throw("user has already participated") | |
113 | + | else if (if ((status != VOTING)) | |
114 | + | then (status != REVEAL) | |
115 | + | else false) | |
116 | + | then throw("wrong status") | |
117 | + | else if (if ((vote != FEATURED)) | |
118 | + | then (vote != DELISTED) | |
119 | + | else false) | |
120 | + | then throw("wrong vote") | |
121 | + | else if (if ((status == FEATURED)) | |
122 | + | then true | |
123 | + | else (status == DELISTED)) | |
124 | + | then throw("vote has finished") | |
125 | + | else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
126 | + | then vote | |
127 | + | else REVEAL)]) | |
128 | + | } | |
129 | + | ||
130 | + | ||
131 | + | ||
132 | + | @Callable(i) | |
103 | 133 | func voteCommit (item,hash) = { | |
104 | 134 | let user = toBase58String(i.caller.bytes) | |
105 | 135 | let commits = getValueCommitsCount(item) | |
106 | 136 | let status = getValueItemStatus(item) | |
107 | 137 | if ((commits >= VOTERS)) | |
108 | 138 | then throw("reached max num of voters") | |
109 | 139 | else if ((getValueCommit(item, user) != NONE)) | |
110 | 140 | then throw("user has already participated") | |
111 | 141 | else if ((getKeyItemSupplier(item) == NONE)) | |
112 | 142 | then throw("item does not exist") | |
113 | 143 | else if (if ((status != NONE)) | |
114 | 144 | then (status != VOTING) | |
115 | 145 | else false) | |
116 | 146 | then throw("voting is not possible") | |
117 | 147 | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
118 | 148 | then REVEAL | |
119 | 149 | else VOTING)]) | |
120 | 150 | } | |
121 | 151 | ||
122 | 152 | ||
123 | 153 | ||
124 | 154 | @Callable(i) | |
125 | 155 | func purchase (item) = { | |
126 | 156 | let pmt = extract(i.payment) | |
127 | 157 | if (isDefined(pmt.assetId)) | |
128 | 158 | then throw("can use WAVES only at the moment") | |
129 | 159 | else { | |
130 | 160 | let userAddress = toBase58String(i.caller.bytes) | |
131 | 161 | let price = getValueItemPrice(item) | |
132 | 162 | let supplierAddress = getValueItemSupplier(item) | |
133 | 163 | if ((price > pmt.amount)) | |
134 | 164 | then throw("purchase amount cannot be less than item price") | |
135 | 165 | else if ((pmt.amount > price)) | |
136 | 166 | then throw("purchase amount cannot be higher than item price") | |
137 | 167 | else if ((supplierAddress == NONE)) | |
138 | 168 | then throw("supplier does not exist") | |
139 | 169 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
140 | 170 | } | |
141 | 171 | } | |
142 | 172 | ||
143 | 173 | ||
144 | 174 | ||
145 | 175 | @Callable(i) | |
146 | 176 | func withdraw () = { | |
147 | 177 | let supplierAddress = toBase58String(i.caller.bytes) | |
148 | 178 | let balance = getValueBalanceSupplier(supplierAddress) | |
149 | 179 | if ((0 >= balance)) | |
150 | 180 | then throw("insufficient balance") | |
151 | 181 | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
152 | 182 | } | |
153 | 183 | ||
154 | 184 | ||
155 | 185 | ||
156 | 186 | @Callable(i) | |
157 | 187 | func addItem (title,price,data) = { | |
158 | 188 | let supplierAddress = toBase58String(i.caller.bytes) | |
159 | 189 | let item = getKeyItem(supplierAddress, title) | |
160 | 190 | if ((0 >= price)) | |
161 | 191 | then throw("purchase amount cannot be less than item price") | |
162 | 192 | else if ((getValueItemSupplier(item) != NONE)) | |
163 | 193 | then throw("an item is already exist") | |
164 | 194 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
165 | 195 | } | |
166 | 196 | ||
167 | 197 | ||
168 | 198 | @Verifier(tx) | |
169 | 199 | func verify () = match tx { | |
170 | 200 | case d: SetScriptTransaction => | |
171 | 201 | sigVerify(tx.bodyBytes, tx.proofs[0], ownerPublicKey) | |
172 | 202 | case d: DataTransaction => | |
173 | 203 | true | |
174 | 204 | case d: TransferTransaction => | |
175 | 205 | true | |
176 | 206 | case _ => | |
177 | 207 | false | |
178 | 208 | } | |
179 | 209 |
github/deemru/w8io/169f3d6 61.98 ms ◑