tx · BDqNLsQnyvBkM4vLVvKGnzdnuv7By6CjhfohmErNW8h5 3MpEvJUwR46tdPKYd9mfoSeigDVDJzNDp8y: -0.01000000 Waves 2021.07.07 14:12 [1603113] smart account 3MpEvJUwR46tdPKYd9mfoSeigDVDJzNDp8y > SELF 0.00000000 Waves
{ "type": 13, "id": "BDqNLsQnyvBkM4vLVvKGnzdnuv7By6CjhfohmErNW8h5", "fee": 1000000, "feeAssetId": null, "timestamp": 1625656384556, "version": 2, "chainId": 84, "sender": "3MpEvJUwR46tdPKYd9mfoSeigDVDJzNDp8y", "senderPublicKey": "AjfGmMcujRDveyKiyrN2DkvnXKsxRmq4XFA9kZjb3iZh", "proofs": [ "5E5xpuaUMN4whxkTBFGQKB4LnhbXfKMuv9dTRsQQPXbLVnhkF1PLuYxkZd8A4nMiAAMGqj24P4gS2EuK1Y7ZABfb" ], "script": "base64:AAIFAAAAAAAAA9QIAhIFCgMIAQgSAwoBCBIAEgQKAggIEgUKAwgICBoKCgJhMRIETk9ORRoUCgJhMhIOZ2V0TnVtYmVyQnlLZXkaCQoCYTMSA2tleRoJCgJhNBIDbnVtGg0KAmE1EgckbWF0Y2gwGgcKAmE2EgFhGhEKAmE3EgtnZXRTdHJCeUtleRoJCgJhOBIDc3RyGhUKAmE5Eg9nZXRLZXlJdGVtUHJpY2UaCgoCYjESBGl0ZW0aFwoCYjISEWdldFZhbHVlSXRlbVByaWNlGhsKAmIzEhVnZXRLZXlVc2VySXRlbUNvdW50ZXIaCgoCYjQSBHVzZXIaHQoCYjUSF2dldFZhbHVlVXNlckl0ZW1Db3VudGVyGhAKAmI2EgpnZXRLZXlJdGVtGg4KAmI3EghzdXBwbGllchoLCgJiOBIFdGl0bGUaFAoCYjkSDmdldEtleUl0ZW1EYXRhGhgKAmMxEhJnZXRLZXlJdGVtU3VwcGxpZXIaGgoCYzISFGdldFZhbHVlSXRlbVN1cHBsaWVyGhsKAmMzEhVnZXRLZXlCYWxhbmNlU3VwcGxpZXIaDQoC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jNwUAAAACZTMFAAAAAmM5BQAAAANuaWwAAAAAjlhh8A==", "height": 1603113, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4oTMuQVxA1bx7NVJJqZJZbSvvGB5WQEDsMWVjT2AJoLK Next: AM1GqkWzqgghV8jc2ft4RfLy5dxJgLtFxmvox7PjqepZ Diff:
Old | New | Differences | |
---|---|---|---|
57 | 57 | ||
58 | 58 | let VOTERS = 3 | |
59 | 59 | ||
60 | + | let QUORUM = 2 | |
61 | + | ||
60 | 62 | let VOTING = "voting" | |
61 | 63 | ||
62 | 64 | let REVEAL = "reveal" | |
65 | + | ||
66 | + | let FEATURED = "featured" | |
67 | + | ||
68 | + | let DELISTED = "delisted" | |
63 | 69 | ||
64 | 70 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
65 | 71 | ||
73 | 79 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
74 | 80 | ||
75 | 81 | ||
82 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
83 | + | ||
84 | + | ||
85 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
86 | + | ||
87 | + | ||
76 | 88 | func getKeyItemStatus (item) = (item + "_status") | |
77 | 89 | ||
78 | 90 | ||
79 | 91 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
92 | + | ||
93 | + | ||
94 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
95 | + | ||
96 | + | ||
97 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
80 | 98 | ||
81 | 99 | ||
82 | 100 | @Callable(i) | |
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 vote") | |
180 | + | else if (if ((status == FEATURED)) | |
181 | + | then true | |
182 | + | else (status == DELISTED)) | |
183 | + | then throw("vote has finished") | |
184 | + | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
185 | + | then vote | |
186 | + | else REVEAL)] | |
187 | + | } | |
188 | + | ||
189 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | func getNumberByKey (key) = { | |
7 | 7 | let num = match getInteger(this, key) { | |
8 | 8 | case a: Int => | |
9 | 9 | a | |
10 | 10 | case _ => | |
11 | 11 | 0 | |
12 | 12 | } | |
13 | 13 | num | |
14 | 14 | } | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func getStrByKey (key) = { | |
18 | 18 | let str = match getString(this, key) { | |
19 | 19 | case a: String => | |
20 | 20 | a | |
21 | 21 | case _ => | |
22 | 22 | NONE | |
23 | 23 | } | |
24 | 24 | str | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getKeyItemData (item) = (item + "_data") | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | let VOTERS = 3 | |
59 | 59 | ||
60 | + | let QUORUM = 2 | |
61 | + | ||
60 | 62 | let VOTING = "voting" | |
61 | 63 | ||
62 | 64 | let REVEAL = "reveal" | |
65 | + | ||
66 | + | let FEATURED = "featured" | |
67 | + | ||
68 | + | let DELISTED = "delisted" | |
63 | 69 | ||
64 | 70 | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
65 | 71 | ||
66 | 72 | ||
67 | 73 | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
68 | 74 | ||
69 | 75 | ||
70 | 76 | func getKeyCommitsCount (item) = (item + "_comcnt") | |
71 | 77 | ||
72 | 78 | ||
73 | 79 | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
74 | 80 | ||
75 | 81 | ||
82 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
83 | + | ||
84 | + | ||
85 | + | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
86 | + | ||
87 | + | ||
76 | 88 | func getKeyItemStatus (item) = (item + "_status") | |
77 | 89 | ||
78 | 90 | ||
79 | 91 | func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item)) | |
92 | + | ||
93 | + | ||
94 | + | func getKeyVoteCount (item,vote) = ((item + "_res:") + vote) | |
95 | + | ||
96 | + | ||
97 | + | func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote)) | |
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 ONLY HHEUAWHEUAS") | |
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("b1") | |
134 | 152 | else if ((getKeyItemSupplier(item) == NONE)) | |
135 | 153 | then throw("b2") | |
136 | 154 | else if (if ((status != NONE)) | |
137 | 155 | then (status != VOTING) | |
138 | 156 | else false) | |
139 | 157 | then throw("b3") | |
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 vote") | |
180 | + | else if (if ((status == FEATURED)) | |
181 | + | then true | |
182 | + | else (status == DELISTED)) | |
183 | + | then throw("vote has finished") | |
184 | + | else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM)) | |
185 | + | then vote | |
186 | + | else REVEAL)] | |
187 | + | } | |
188 | + | ||
189 | + |
github/deemru/w8io/026f985 83.39 ms ◑