tx · JBgW23iTKgqtc5xsZPepM13D3yZwbRi8jcaMKXyfHLsX 3MzuDDfQ6XjDgLnkQYZ8LKAiyZpvBcaQWjp: -0.01400000 Waves 2019.12.24 03:56 [822387] smart account 3MzuDDfQ6XjDgLnkQYZ8LKAiyZpvBcaQWjp > SELF 0.00000000 Waves
{ "type": 13, "id": "JBgW23iTKgqtc5xsZPepM13D3yZwbRi8jcaMKXyfHLsX", "fee": 1400000, "feeAssetId": null, "timestamp": 1577149030983, "version": 1, "sender": "3MzuDDfQ6XjDgLnkQYZ8LKAiyZpvBcaQWjp", "senderPublicKey": "4W6E752eFruwwdXebxxGPcoyY5VpUMkAAuS5DH9oA7Eg", "proofs": [ "2Y1oL22P8oFTQhBXGrTQHmVRcywezEsvR2EmLt9xzG1cayvhGpC7RZNF3AZzmqoEzwsAvxHXBtQPTDg33f5pT2wj" ], "script": "base64:AAIDAAAAAAAAABAIARIFCgMIAQgSAwoBCBIAAAAADQAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQUAAAADc3RyAQAAAA9nZXRLZXlJdGVtUHJpY2UAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAGX3ByaWNlAQAAABFnZXRWYWx1ZUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkBAAAADmdldE51bWJlckJ5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dldFZhbHVlQmFsYW5jZVN1cHBsaWVyAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzAwkAAGcAAAACAAAAAAAAAAAABQAAAAdiYWxhbmNlCQAAAgAAAAECAAAAFGluc3VmZmljaWVudCBiYWxhbmNlCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwAAAAAAAAAAAAUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMJAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAdiYWxhbmNlBQAAAAR1bml0BQAAAANuaWwAAAAA6nOiyw==", "chainId": 84, "height": 822387, "spentComplexity": 0 } View: original | compacted Prev: 8qGLFgKzGtescT6ZsfJnQQngbozrhnVc2oErvGnLqwcS Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let VOTERS = 3 | |
5 | - | ||
6 | - | let QUORUM = 2 | |
7 | - | ||
8 | - | let VOTING = "voting" | |
9 | - | ||
10 | - | let REVEAL = "reveal" | |
11 | - | ||
12 | - | let FEATURED = "featured" | |
13 | - | ||
14 | - | let DELISTED = "delisted" | |
15 | - | ||
16 | 4 | let NONE = "none" | |
17 | 5 | ||
18 | 6 | func getNumberByKey (key) = { | |
64 | 52 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
65 | 53 | ||
66 | 54 | ||
67 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyItemSupplier(account)) | |
68 | - | ||
69 | - | ||
70 | - | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
71 | - | ||
72 | - | ||
73 | - | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
74 | - | ||
75 | - | ||
76 | - | func getKeyCommitsCount (item) = (item + "_comctn") | |
77 | - | ||
78 | - | ||
79 | - | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
80 | - | ||
81 | - | ||
82 | - | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
83 | - | ||
84 | - | ||
85 | - | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
86 | - | ||
87 | - | ||
88 | - | func getKeyItemStatus (item) = (item + "_status") | |
89 | - | ||
90 | - | ||
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)) | |
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
98 | 56 | ||
99 | 57 | ||
100 | 58 | @Callable(i) | |
104 | 62 | if ((0 >= price)) | |
105 | 63 | then throw("purchase amount cannot be less than item price") | |
106 | 64 | else if ((getValueItemSupplier(item) != NONE)) | |
107 | - | then throw("an item | |
65 | + | then throw("an item is already exist") | |
108 | 66 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
109 | 67 | } | |
110 | 68 | ||
141 | 99 | } | |
142 | 100 | ||
143 | 101 | ||
144 | - | ||
145 | - | @Callable(i) | |
146 | - | func voteCommit (item,hash) = { | |
147 | - | let user = toBase58String(i.caller.bytes) | |
148 | - | let commits = getValueCommitsCount(item) | |
149 | - | let status = getValueItemStatus(item) | |
150 | - | if ((commits >= VOTERS)) | |
151 | - | then throw("reached max num of voters") | |
152 | - | else if ((getValueCommit(item, user) != NONE)) | |
153 | - | then throw("user has already participated") | |
154 | - | else if ((getKeyItemSupplier(item) == NONE)) | |
155 | - | then throw("item does not exist") | |
156 | - | else if (if ((status != NONE)) | |
157 | - | then (status != VOTING) | |
158 | - | else false) | |
159 | - | then throw("voting is not possible") | |
160 | - | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
161 | - | then REVEAL | |
162 | - | else VOTING)]) | |
163 | - | } | |
164 | - | ||
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 ((toBase58String(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 num of voters hasn-t 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 ((status == FEATURED)) | |
187 | - | then true | |
188 | - | else (status == 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 | - |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let VOTERS = 3 | |
5 | - | ||
6 | - | let QUORUM = 2 | |
7 | - | ||
8 | - | let VOTING = "voting" | |
9 | - | ||
10 | - | let REVEAL = "reveal" | |
11 | - | ||
12 | - | let FEATURED = "featured" | |
13 | - | ||
14 | - | let DELISTED = "delisted" | |
15 | - | ||
16 | 4 | let NONE = "none" | |
17 | 5 | ||
18 | 6 | func getNumberByKey (key) = { | |
19 | 7 | let num = match getInteger(this, key) { | |
20 | 8 | case a: Int => | |
21 | 9 | a | |
22 | 10 | case _ => | |
23 | 11 | 0 | |
24 | 12 | } | |
25 | 13 | num | |
26 | 14 | } | |
27 | 15 | ||
28 | 16 | ||
29 | 17 | func getStrByKey (key) = { | |
30 | 18 | let str = match getString(this, key) { | |
31 | 19 | case a: String => | |
32 | 20 | a | |
33 | 21 | case _ => | |
34 | 22 | NONE | |
35 | 23 | } | |
36 | 24 | str | |
37 | 25 | } | |
38 | 26 | ||
39 | 27 | ||
40 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
41 | 29 | ||
42 | 30 | ||
43 | 31 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
44 | 32 | ||
45 | 33 | ||
46 | 34 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
47 | 35 | ||
48 | 36 | ||
49 | 37 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
50 | 38 | ||
51 | 39 | ||
52 | 40 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
53 | 41 | ||
54 | 42 | ||
55 | 43 | func getKeyItemData (item) = (item + "_data") | |
56 | 44 | ||
57 | 45 | ||
58 | 46 | func getKeyItemSupplier (item) = (item + "_owner") | |
59 | 47 | ||
60 | 48 | ||
61 | 49 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
62 | 50 | ||
63 | 51 | ||
64 | 52 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
65 | 53 | ||
66 | 54 | ||
67 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyItemSupplier(account)) | |
68 | - | ||
69 | - | ||
70 | - | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
71 | - | ||
72 | - | ||
73 | - | func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user)) | |
74 | - | ||
75 | - | ||
76 | - | func getKeyCommitsCount (item) = (item + "_comctn") | |
77 | - | ||
78 | - | ||
79 | - | func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item)) | |
80 | - | ||
81 | - | ||
82 | - | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
83 | - | ||
84 | - | ||
85 | - | func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user)) | |
86 | - | ||
87 | - | ||
88 | - | func getKeyItemStatus (item) = (item + "_status") | |
89 | - | ||
90 | - | ||
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)) | |
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
98 | 56 | ||
99 | 57 | ||
100 | 58 | @Callable(i) | |
101 | 59 | func addItem (title,price,data) = { | |
102 | 60 | let supplierAddress = toBase58String(i.caller.bytes) | |
103 | 61 | let item = getKeyItem(supplierAddress, title) | |
104 | 62 | if ((0 >= price)) | |
105 | 63 | then throw("purchase amount cannot be less than item price") | |
106 | 64 | else if ((getValueItemSupplier(item) != NONE)) | |
107 | - | then throw("an item | |
65 | + | then throw("an item is already exist") | |
108 | 66 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
109 | 67 | } | |
110 | 68 | ||
111 | 69 | ||
112 | 70 | ||
113 | 71 | @Callable(i) | |
114 | 72 | func purchase (item) = { | |
115 | 73 | let pmt = extract(i.payment) | |
116 | 74 | if (isDefined(pmt.assetId)) | |
117 | 75 | then throw("WAVES tokens only at the moment") | |
118 | 76 | else { | |
119 | 77 | let userAddress = toBase58String(i.caller.bytes) | |
120 | 78 | let price = getValueItemPrice(item) | |
121 | 79 | let supplierAddress = getValueItemSupplier(item) | |
122 | 80 | if ((price > pmt.amount)) | |
123 | 81 | then throw("purchase amount cannot be less than item price") | |
124 | 82 | else if ((pmt.amount > price)) | |
125 | 83 | then throw("purchase amount cannot be higher than item price") | |
126 | 84 | else if ((supplierAddress == NONE)) | |
127 | 85 | then throw("supplier does not exist") | |
128 | 86 | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
129 | 87 | } | |
130 | 88 | } | |
131 | 89 | ||
132 | 90 | ||
133 | 91 | ||
134 | 92 | @Callable(i) | |
135 | 93 | func withdraw () = { | |
136 | 94 | let supplierAddress = toBase58String(i.caller.bytes) | |
137 | 95 | let balance = getValueBalanceSupplier(supplierAddress) | |
138 | 96 | if ((0 >= balance)) | |
139 | 97 | then throw("insufficient balance") | |
140 | 98 | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
141 | 99 | } | |
142 | 100 | ||
143 | 101 | ||
144 | - | ||
145 | - | @Callable(i) | |
146 | - | func voteCommit (item,hash) = { | |
147 | - | let user = toBase58String(i.caller.bytes) | |
148 | - | let commits = getValueCommitsCount(item) | |
149 | - | let status = getValueItemStatus(item) | |
150 | - | if ((commits >= VOTERS)) | |
151 | - | then throw("reached max num of voters") | |
152 | - | else if ((getValueCommit(item, user) != NONE)) | |
153 | - | then throw("user has already participated") | |
154 | - | else if ((getKeyItemSupplier(item) == NONE)) | |
155 | - | then throw("item does not exist") | |
156 | - | else if (if ((status != NONE)) | |
157 | - | then (status != VOTING) | |
158 | - | else false) | |
159 | - | then throw("voting is not possible") | |
160 | - | else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS)) | |
161 | - | then REVEAL | |
162 | - | else VOTING)]) | |
163 | - | } | |
164 | - | ||
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 ((toBase58String(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 num of voters hasn-t 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 ((status == FEATURED)) | |
187 | - | then true | |
188 | - | else (status == 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 | - |
github/deemru/w8io/6500d08 40.78 ms ◑