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