tx · 9A72CE6ypn7Tn33KXBAL9zNEbydDtjGdE8svz76Ps7EE 3N81Dk1WuUv7UKt3inqWVYN81J8VHjoV3MC: -0.01400000 Waves 2022.02.20 18:45 [1932160] smart account 3N81Dk1WuUv7UKt3inqWVYN81J8VHjoV3MC > SELF 0.00000000 Waves
{ "type": 13, "id": "9A72CE6ypn7Tn33KXBAL9zNEbydDtjGdE8svz76Ps7EE", "fee": 1400000, "feeAssetId": null, "timestamp": 1645371943872, "version": 2, "chainId": 84, "sender": "3N81Dk1WuUv7UKt3inqWVYN81J8VHjoV3MC", "senderPublicKey": "5vXdNgZ1TR8AAzcnLumQTQYzcU3AwHj91bZTtiE3roBE", "proofs": [ "4AGNyhDos1rLouKWmuKipzqyWv3fWTq698WDZ1KfwGPYvYiGD4pbNqmAJTWRaCLG3649hp4KwaVNyDTbAAJe1ixU" ], "script": "base64:AAIDAAAAAAAAABYIARIFCgMIAQgSBAoCCAgSBQoDCAgIAAAAHAAAAAAETk9ORQIAAAAETk9ORQAAAAAGVk9URVJTAAAAAAAAAAACAAAAAAZRVU9SVU0AAAAAAAAAAAMAAAAACEZFQVRVUkVEAgAAAAhmZWF0dXJlZAAAAAAIREVMSVNURUQCAAAACGRlbGlzdGVkAAAAAAZWT1RJTkcCAAAABnZvdGluZwAAAAAGUkVWRUFMAgAAAAZyZXZlYWwBAAAADmdldFN0cmluZ0J5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWECAAAABE5PTkUBAAAAD2dldEludGVnZXJCeUtleQAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAA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ECAAAAEVlvdSB2b3RlZCBhbHJlYWR5AwMJAQAAAAIhPQAAAAIFAAAABnN0YXR1cwUAAAAGVk9USU5HCQEAAAACIT0AAAACBQAAAAZzdGF0dXMFAAAABlJFVkVBTAcJAAACAAAAAQIAAAAlVm90aW5nIGlzIG5vdCBhY3RpdmUgb2YgdGhpcyBpdGVtIG5vdwMDCQEAAAACIT0AAAACBQAAAAR2b3RlBQAAAAhGRUFUVVJFRAkBAAAAAiE9AAAAAgUAAAAEdm90ZQUAAAAIREVMSVNURUQHCQAAAgAAAAECAAAAI1Byb3ZpZGVkIHZvdGluZyBvcHRpb24gaXMgaW5jb3JyZWN0BAAAAAluZXdTdGF0dXMDCQAAZwAAAAIFAAAADW5ld1ZvdGVzQ291bnQFAAAABlFVT1JVTQUAAAAEdm90ZQUAAAAGUkVWRUFMCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAMZ2V0S2V5Q29tbWl0AAAAAgUAAAAEaXRlbQUAAAAEdXNlcgUAAAAEdm90ZQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAEGdldEtleVZvdGVzQ291bnQAAAACBQAAAARpdGVtBQAAAAR1c2VyBQAAAA1uZXdWb3Rlc0NvdW50CQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAQZ2V0S2V5SXRlbVN0YXR1cwAAAAEFAAAABGl0ZW0FAAAACW5ld1N0YXR1cwUAAAADbmlsAAAAANyLis0=", "height": 1932160, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 68ihjaaAahY2XytQLUGTa8A7Ksjhtxhc2JnfGB9qaTsP Next: ADywmGrM3EdT2mbLLaMLxDj1FYppTvizVpmBAdbYBtFJ Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "NONE" | |
5 | 5 | ||
6 | + | let VOTERS = 2 | |
7 | + | ||
8 | + | let QUORUM = 3 | |
9 | + | ||
10 | + | let FEATURED = "featured" | |
11 | + | ||
12 | + | let DELISTED = "delisted" | |
13 | + | ||
14 | + | let VOTING = "voting" | |
15 | + | ||
16 | + | let REVEAL = "reveal" | |
17 | + | ||
6 | 18 | func getStringByKey (key) = match getString(this, key) { | |
7 | 19 | case a: String => | |
8 | 20 | a | |
9 | 21 | case _ => | |
10 | - | "" | |
22 | + | "NONE" | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func getIntegerByKey (key) = match getInteger(this, key) { | |
27 | + | case a: Int => | |
28 | + | a | |
29 | + | case _ => | |
30 | + | 0 | |
11 | 31 | } | |
12 | 32 | ||
13 | 33 | ||
14 | 34 | func getKeyItem (supplier,title) = { | |
15 | - | let | |
16 | - | ("item_" + toBase58String(sha256(toBytes( | |
35 | + | let supplierTitle = (supplier + title) | |
36 | + | ("item_" + toBase58String(sha256(toBytes(supplierTitle)))) | |
17 | 37 | } | |
18 | 38 | ||
19 | 39 | ||
24 | 44 | ||
25 | 45 | ||
26 | 46 | func getKeyItemData (item) = (item + "_data") | |
47 | + | ||
48 | + | ||
49 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commmit") | |
50 | + | ||
51 | + | ||
52 | + | func getKeyCommitsCount (item) = (item + "_cmtcnt") | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getKeyItemStatus (item) = (item + "_status") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyVotesCount (item,vote) = ((item + "_res:") + vote) | |
62 | + | ||
63 | + | ||
64 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
65 | + | ||
66 | + | ||
67 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
68 | + | ||
69 | + | ||
70 | + | func getValueUserItemCounter (user,item) = { | |
71 | + | let userItemCounterKey = getKeyUserItemCounter(user, item) | |
72 | + | match getInteger(this, userItemCounterKey) { | |
73 | + | case a: Int => | |
74 | + | a | |
75 | + | case _ => | |
76 | + | 0 | |
77 | + | } | |
78 | + | } | |
79 | + | ||
80 | + | ||
81 | + | func getUserItemPrice (item) = { | |
82 | + | let keyItemPrice = getKeyItemPrice(item) | |
83 | + | getInteger(this, keyItemPrice) | |
84 | + | } | |
85 | + | ||
86 | + | ||
87 | + | func getValueCommit (item,user) = getStringByKey(getKeyCommit(item, user)) | |
88 | + | ||
89 | + | ||
90 | + | func getValueCommitsCount (item) = getIntegerByKey(getKeyCommitsCount(item)) | |
91 | + | ||
92 | + | ||
93 | + | func getValueReveal (item,user) = getStringByKey(getKeyReveal(item, user)) | |
94 | + | ||
95 | + | ||
96 | + | func getValueItemStatus (item) = getStringByKey(getKeyItemStatus(item)) | |
97 | + | ||
98 | + | ||
99 | + | func getValueVotesCount (item,vote) = getIntegerByKey(getKeyVotesCount(item, vote)) | |
27 | 100 | ||
28 | 101 | ||
29 | 102 | func getValueItemSupplier (account) = match getString(this, account) { | |
46 | 119 | } | |
47 | 120 | ||
48 | 121 | ||
122 | + | ||
123 | + | @Callable(i) | |
124 | + | func voteCommit (item,hash) = { | |
125 | + | let user = toBase58String(i.caller.bytes) | |
126 | + | let commitsCount = getValueCommitsCount(item) | |
127 | + | let status = getValueItemStatus(item) | |
128 | + | if ((commitsCount >= VOTERS)) | |
129 | + | then throw("Reached max numer of voters") | |
130 | + | else if ((getValueCommit(item, user) != NONE)) | |
131 | + | then throw("You voted already") | |
132 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
133 | + | then throw("Item does not exist") | |
134 | + | else if (if ((status != NONE)) | |
135 | + | then (status != VOTING) | |
136 | + | else false) | |
137 | + | then throw("Voting is not active for this item noew") | |
138 | + | else { | |
139 | + | let newStatus = if ((commitsCount == VOTERS)) | |
140 | + | then REVEAL | |
141 | + | else VOTING | |
142 | + | WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commitsCount + 1)), DataEntry(getKeyItemStatus(item), newStatus)]) | |
143 | + | } | |
144 | + | } | |
145 | + | ||
146 | + | ||
147 | + | ||
148 | + | @Callable(i) | |
149 | + | func voteReveal (item,vote,salt) = { | |
150 | + | let user = toBase58String(i.caller.bytes) | |
151 | + | let status = getValueItemStatus(item) | |
152 | + | let newVotesCount = (getValueVotesCount(item, vote) + 1) | |
153 | + | let saltedVote = ((item + vote) + salt) | |
154 | + | if ((toBase58String(sha256(toBytes(saltedVote))) != getValueCommit(item, user))) | |
155 | + | then throw("Reveal data is not valid") | |
156 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
157 | + | then throw("Max number of voters not reached") | |
158 | + | else if ((getValueReveal(item, user) != NONE)) | |
159 | + | then throw("You voted already") | |
160 | + | else if (if ((status != VOTING)) | |
161 | + | then (status != REVEAL) | |
162 | + | else false) | |
163 | + | then throw("Voting is not active of this item now") | |
164 | + | else if (if ((vote != FEATURED)) | |
165 | + | then (vote != DELISTED) | |
166 | + | else false) | |
167 | + | then throw("Provided voting option is incorrect") | |
168 | + | else { | |
169 | + | let newStatus = if ((newVotesCount >= QUORUM)) | |
170 | + | then vote | |
171 | + | else REVEAL | |
172 | + | WriteSet([DataEntry(getKeyCommit(item, user), vote), DataEntry(getKeyVotesCount(item, user), newVotesCount), DataEntry(getKeyItemStatus(item), newStatus)]) | |
173 | + | } | |
174 | + | } | |
175 | + | ||
176 | + |
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 | + | let VOTERS = 2 | |
7 | + | ||
8 | + | let QUORUM = 3 | |
9 | + | ||
10 | + | let FEATURED = "featured" | |
11 | + | ||
12 | + | let DELISTED = "delisted" | |
13 | + | ||
14 | + | let VOTING = "voting" | |
15 | + | ||
16 | + | let REVEAL = "reveal" | |
17 | + | ||
6 | 18 | func getStringByKey (key) = match getString(this, key) { | |
7 | 19 | case a: String => | |
8 | 20 | a | |
9 | 21 | case _ => | |
10 | - | "" | |
22 | + | "NONE" | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func getIntegerByKey (key) = match getInteger(this, key) { | |
27 | + | case a: Int => | |
28 | + | a | |
29 | + | case _ => | |
30 | + | 0 | |
11 | 31 | } | |
12 | 32 | ||
13 | 33 | ||
14 | 34 | func getKeyItem (supplier,title) = { | |
15 | - | let | |
16 | - | ("item_" + toBase58String(sha256(toBytes( | |
35 | + | let supplierTitle = (supplier + title) | |
36 | + | ("item_" + toBase58String(sha256(toBytes(supplierTitle)))) | |
17 | 37 | } | |
18 | 38 | ||
19 | 39 | ||
20 | 40 | func getKeyItemSupplier (item) = (item + "_owner") | |
21 | 41 | ||
22 | 42 | ||
23 | 43 | func getKeyItemPrice (item) = (item + "_price") | |
24 | 44 | ||
25 | 45 | ||
26 | 46 | func getKeyItemData (item) = (item + "_data") | |
47 | + | ||
48 | + | ||
49 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commmit") | |
50 | + | ||
51 | + | ||
52 | + | func getKeyCommitsCount (item) = (item + "_cmtcnt") | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getKeyItemStatus (item) = (item + "_status") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyVotesCount (item,vote) = ((item + "_res:") + vote) | |
62 | + | ||
63 | + | ||
64 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
65 | + | ||
66 | + | ||
67 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
68 | + | ||
69 | + | ||
70 | + | func getValueUserItemCounter (user,item) = { | |
71 | + | let userItemCounterKey = getKeyUserItemCounter(user, item) | |
72 | + | match getInteger(this, userItemCounterKey) { | |
73 | + | case a: Int => | |
74 | + | a | |
75 | + | case _ => | |
76 | + | 0 | |
77 | + | } | |
78 | + | } | |
79 | + | ||
80 | + | ||
81 | + | func getUserItemPrice (item) = { | |
82 | + | let keyItemPrice = getKeyItemPrice(item) | |
83 | + | getInteger(this, keyItemPrice) | |
84 | + | } | |
85 | + | ||
86 | + | ||
87 | + | func getValueCommit (item,user) = getStringByKey(getKeyCommit(item, user)) | |
88 | + | ||
89 | + | ||
90 | + | func getValueCommitsCount (item) = getIntegerByKey(getKeyCommitsCount(item)) | |
91 | + | ||
92 | + | ||
93 | + | func getValueReveal (item,user) = getStringByKey(getKeyReveal(item, user)) | |
94 | + | ||
95 | + | ||
96 | + | func getValueItemStatus (item) = getStringByKey(getKeyItemStatus(item)) | |
97 | + | ||
98 | + | ||
99 | + | func getValueVotesCount (item,vote) = getIntegerByKey(getKeyVotesCount(item, vote)) | |
27 | 100 | ||
28 | 101 | ||
29 | 102 | func getValueItemSupplier (account) = match getString(this, account) { | |
30 | 103 | case a: String => | |
31 | 104 | a | |
32 | 105 | case _ => | |
33 | 106 | "NONE" | |
34 | 107 | } | |
35 | 108 | ||
36 | 109 | ||
37 | 110 | @Callable(i) | |
38 | 111 | func addItem (title,price,data) = { | |
39 | 112 | let supplierAddress = toBase58String(i.caller.bytes) | |
40 | 113 | let item = getKeyItem(supplierAddress, title) | |
41 | 114 | if ((0 >= price)) | |
42 | 115 | then throw("Purchase amount cannot be less than item price") | |
43 | 116 | else if ((getValueItemSupplier(item) != NONE)) | |
44 | 117 | then throw("An item is already exists") | |
45 | 118 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
46 | 119 | } | |
47 | 120 | ||
48 | 121 | ||
122 | + | ||
123 | + | @Callable(i) | |
124 | + | func voteCommit (item,hash) = { | |
125 | + | let user = toBase58String(i.caller.bytes) | |
126 | + | let commitsCount = getValueCommitsCount(item) | |
127 | + | let status = getValueItemStatus(item) | |
128 | + | if ((commitsCount >= VOTERS)) | |
129 | + | then throw("Reached max numer of voters") | |
130 | + | else if ((getValueCommit(item, user) != NONE)) | |
131 | + | then throw("You voted already") | |
132 | + | else if ((getKeyItemSupplier(item) == NONE)) | |
133 | + | then throw("Item does not exist") | |
134 | + | else if (if ((status != NONE)) | |
135 | + | then (status != VOTING) | |
136 | + | else false) | |
137 | + | then throw("Voting is not active for this item noew") | |
138 | + | else { | |
139 | + | let newStatus = if ((commitsCount == VOTERS)) | |
140 | + | then REVEAL | |
141 | + | else VOTING | |
142 | + | WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commitsCount + 1)), DataEntry(getKeyItemStatus(item), newStatus)]) | |
143 | + | } | |
144 | + | } | |
145 | + | ||
146 | + | ||
147 | + | ||
148 | + | @Callable(i) | |
149 | + | func voteReveal (item,vote,salt) = { | |
150 | + | let user = toBase58String(i.caller.bytes) | |
151 | + | let status = getValueItemStatus(item) | |
152 | + | let newVotesCount = (getValueVotesCount(item, vote) + 1) | |
153 | + | let saltedVote = ((item + vote) + salt) | |
154 | + | if ((toBase58String(sha256(toBytes(saltedVote))) != getValueCommit(item, user))) | |
155 | + | then throw("Reveal data is not valid") | |
156 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
157 | + | then throw("Max number of voters not reached") | |
158 | + | else if ((getValueReveal(item, user) != NONE)) | |
159 | + | then throw("You voted already") | |
160 | + | else if (if ((status != VOTING)) | |
161 | + | then (status != REVEAL) | |
162 | + | else false) | |
163 | + | then throw("Voting is not active of this item now") | |
164 | + | else if (if ((vote != FEATURED)) | |
165 | + | then (vote != DELISTED) | |
166 | + | else false) | |
167 | + | then throw("Provided voting option is incorrect") | |
168 | + | else { | |
169 | + | let newStatus = if ((newVotesCount >= QUORUM)) | |
170 | + | then vote | |
171 | + | else REVEAL | |
172 | + | WriteSet([DataEntry(getKeyCommit(item, user), vote), DataEntry(getKeyVotesCount(item, user), newVotesCount), DataEntry(getKeyItemStatus(item), newStatus)]) | |
173 | + | } | |
174 | + | } | |
175 | + | ||
176 | + |
github/deemru/w8io/169f3d6 26.61 ms ◑