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