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