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