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