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