tx · 8H1ayE7nm48vp3Rn6eMhteBorsxKc8rGKTMvS31on4qt 3ND6EFqVoR6r9jWRL87nSf2Zs5AMiNnGWD3: -0.01000000 Waves 2021.07.08 14:29 [1604565] smart account 3ND6EFqVoR6r9jWRL87nSf2Zs5AMiNnGWD3 > SELF 0.00000000 Waves
{ "type": 13, "id": "8H1ayE7nm48vp3Rn6eMhteBorsxKc8rGKTMvS31on4qt", "fee": 1000000, "feeAssetId": null, "timestamp": 1625743769676, "version": 2, "chainId": 84, "sender": "3ND6EFqVoR6r9jWRL87nSf2Zs5AMiNnGWD3", "senderPublicKey": "KUUrvP3E8GJqJe8m89JhbWoFxA5Y6ZArXcUs6XDthT6", "proofs": [ "5dcmRSN8CAQhL8NrxYuCVDMpg4rqEYZsGng7ZF3efFdMPDtDZpFxUe3KyeAnR2FgGoZ4RFCrdgYu4umqyMxiQmdb" ], "script": "base64:AAIDAAAAAAAAAz0IARIFCgMIAQgSBAoCCAgSBQoDCAgIGgoKAmExEgROT05FGgwKAmEyEgZWT1RFUlMaDAoCYTMSBlFVT1JVTRoOCgJhNBIIRkVBVFVSRUQaDgoCYTUSCERFTElTVEVEGgwKAmE2EgZWT1RJTkcaDAoCYTcSBlJFVkVBTBoUCgJhOBIOZ2V0U3RyaW5nQnlLZXkaCQoCYTkSA2tleRoNCgJiMRIHJG1hdGNoMBoHCgJiMhIBYRoVCgJiMxIPZ2V0SW50ZWdlckJ5S2V5GhAKAmI0EgpnZXRLZXlJdGVtGg4KAmI1EghzdXBwbGllchoLCgJiNhIFdGl0bGUaEwoCYjcSDXN1cHBsaWVyVGl0bGUaGAoCYjgSEmdldEtleUl0ZW1TdXBwbGllchoKCgJiORIEaXRlbRoVCgJjMRIPZ2V0S2V5SXRlbVByaWNlGhQKAmMyEg5nZXRLZXlJdGVtRGF0YRoSCgJjMxIMZ2V0S2V5Q29tbWl0GgoKAmM0EgR1c2VyGhgKAmM1EhJnZXRLZXlDb21taXRzQ291bnQaEgoCYzYSDGdldE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iOQUAAAACYzQFAAAAAmExCQAAAgAAAAECAAAAEVlvdSBWb3RlZCBBbHJlYWR5AwMJAQAAAAIhPQAAAAIFAAAAAmU1BQAAAAJhNgkBAAAAAiE9AAAAAgUAAAACZTUFAAAAAmE3BwkAAAIAAAABAgAAACZWb3RpbmcgaXMgbm90IGFjdGl2ZSBmb3IgdGhpcyBpdGVtIG5vdwMDCQEAAAACIT0AAAACBQAAAAJjOQUAAAACYTQJAQAAAAIhPQAAAAIFAAAAAmM5BQAAAAJhNQcJAAACAAAAAQIAAAAjUHJvdmlkZWQgdm90aW5nIG9wdGlvbiBpcyBpbmNvcnJlY3QEAAAAAmU2AwkAAGcAAAACBQAAAAJlOAUAAAACYTMFAAAAAmM5BQAAAAJhNwkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAAmM2AAAAAgUAAAACYjkFAAAAAmM0BQAAAAJjOQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAAmM4AAAAAgUAAAACYjkFAAAAAmM5BQAAAAJlOAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAAmM3AAAAAQUAAAACYjkFAAAAAmU2BQAAAANuaWwAAAAAwMOmkg==", "height": 1604565, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8bQBiW1Ls5PgrUgZGde395t6gyaUzUYsCT9WTAwS2hpE Next: 2BaQqHwYrXmhqq2UrR91KMH1mA3vSuxc3ZAg7hvbgEFq 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 FEATURED = "featured" | |
11 | + | ||
12 | + | let DELISTED = "delisted" | |
13 | + | ||
14 | + | let VOTING = "voting" | |
15 | + | ||
16 | + | let REVEAL = "reveal" | |
17 | + | ||
18 | + | func getStringByKey (key) = match getString(this, key) { | |
19 | + | case a: String => | |
20 | + | a | |
21 | + | case _ => | |
22 | + | NONE | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func getIntegerByKey (key) = match getInteger(this, key) { | |
27 | + | case a: Int => | |
28 | + | a | |
29 | + | case _ => | |
30 | + | 0 | |
31 | + | } | |
32 | + | ||
5 | 33 | ||
6 | 34 | func getKeyItem (supplier,title) = { | |
7 | 35 | let supplierTitle = (supplier + title) | |
18 | 46 | func getKeyItemData (item) = (item + "_data") | |
19 | 47 | ||
20 | 48 | ||
21 | - | func getValueItemSupplier (item) = { | |
22 | - | let key = match getString(this, (item + "_owner")) { | |
23 | - | case t: String => | |
24 | - | t | |
25 | - | case _ => | |
26 | - | NONE | |
27 | - | } | |
28 | - | key | |
29 | - | } | |
49 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | + | ||
51 | + | ||
52 | + | func getKeyCommitsCount (item) = (item + "_cmtcnt") | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getKeyItemStatus (item) = (item + "_status") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyVotesCount (item,vote) = ((item + "_res:") + vote) | |
62 | + | ||
63 | + | ||
64 | + | func getValueItemSupplier (account) = getStringByKey(getKeyItemSupplier(account)) | |
65 | + | ||
66 | + | ||
67 | + | func getValueCommit (item,user) = getStringByKey(getKeyCommit(item, user)) | |
68 | + | ||
69 | + | ||
70 | + | func getValueCommitsCount (item) = getIntegerByKey(getKeyCommitsCount(item)) | |
71 | + | ||
72 | + | ||
73 | + | func getValueReveal (item,user) = getStringByKey(getKeyReveal(item, user)) | |
74 | + | ||
75 | + | ||
76 | + | func getValueItemStatus (item) = getStringByKey(getKeyItemStatus(item)) | |
77 | + | ||
78 | + | ||
79 | + | func getValueVotesCount (item,vote) = getIntegerByKey(getKeyVotesCount(item, vote)) | |
30 | 80 | ||
31 | 81 | ||
32 | 82 | @Callable(i) | |
41 | 91 | } | |
42 | 92 | ||
43 | 93 | ||
94 | + | ||
95 | + | @Callable(i) | |
96 | + | func voteCommit (item,hash) = { | |
97 | + | let user = toBase58String(i.caller.bytes) | |
98 | + | let commitsCount = getValueCommitsCount(item) | |
99 | + | let status = getValueItemStatus(item) | |
100 | + | if ((commitsCount >= VOTERS)) | |
101 | + | then throw("Reached max number of voters") | |
102 | + | else if ((getValueCommit(item, user) != NONE)) | |
103 | + | then throw("Your Voted already") | |
104 | + | else if ((getValueItemSupplier(getKeyItemSupplier(item)) == NONE)) | |
105 | + | then throw("Item Does not exist") | |
106 | + | else if (if ((status != NONE)) | |
107 | + | then (status != VOTING) | |
108 | + | else false) | |
109 | + | then throw("Voting is not active for this Item now") | |
110 | + | else { | |
111 | + | let newStatus = if ((commitsCount == VOTERS)) | |
112 | + | then REVEAL | |
113 | + | else VOTING | |
114 | + | WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commitsCount + 1)), DataEntry(getKeyItemStatus(item), newStatus)]) | |
115 | + | } | |
116 | + | } | |
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | @Callable(i) | |
121 | + | func voteReveal (item,vote,salt) = { | |
122 | + | let user = toBase58String(i.caller.bytes) | |
123 | + | let status = getValueItemStatus(item) | |
124 | + | let newVotesCount = (getValueVotesCount(item, vote) + 1) | |
125 | + | let saltedVote = ((item + vote) + salt) | |
126 | + | if ((toBase58String(sha256(toBytes(saltedVote))) != getValueCommit(item, user))) | |
127 | + | then throw("Reveal data is not valid") | |
128 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
129 | + | then throw("Max Number of Voters not reached") | |
130 | + | else if ((getValueReveal(item, user) != NONE)) | |
131 | + | then throw("You Voted Already") | |
132 | + | else if (if ((status != VOTING)) | |
133 | + | then (status != REVEAL) | |
134 | + | else false) | |
135 | + | then throw("Voting is not active for this item now") | |
136 | + | else if (if ((vote != FEATURED)) | |
137 | + | then (vote != DELISTED) | |
138 | + | else false) | |
139 | + | then throw("Provided voting option is incorrect") | |
140 | + | else { | |
141 | + | let newStatus = if ((newVotesCount >= QUORUM)) | |
142 | + | then vote | |
143 | + | else REVEAL | |
144 | + | WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVotesCount(item, vote), newVotesCount), DataEntry(getKeyItemStatus(item), newStatus)]) | |
145 | + | } | |
146 | + | } | |
147 | + | ||
148 | + |
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 FEATURED = "featured" | |
11 | + | ||
12 | + | let DELISTED = "delisted" | |
13 | + | ||
14 | + | let VOTING = "voting" | |
15 | + | ||
16 | + | let REVEAL = "reveal" | |
17 | + | ||
18 | + | func getStringByKey (key) = match getString(this, key) { | |
19 | + | case a: String => | |
20 | + | a | |
21 | + | case _ => | |
22 | + | NONE | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func getIntegerByKey (key) = match getInteger(this, key) { | |
27 | + | case a: Int => | |
28 | + | a | |
29 | + | case _ => | |
30 | + | 0 | |
31 | + | } | |
32 | + | ||
5 | 33 | ||
6 | 34 | func getKeyItem (supplier,title) = { | |
7 | 35 | let supplierTitle = (supplier + title) | |
8 | 36 | ("item_" + toBase58String(sha256(toBytes(supplierTitle)))) | |
9 | 37 | } | |
10 | 38 | ||
11 | 39 | ||
12 | 40 | func getKeyItemSupplier (item) = (item + "_owner") | |
13 | 41 | ||
14 | 42 | ||
15 | 43 | func getKeyItemPrice (item) = (item + "_price") | |
16 | 44 | ||
17 | 45 | ||
18 | 46 | func getKeyItemData (item) = (item + "_data") | |
19 | 47 | ||
20 | 48 | ||
21 | - | func getValueItemSupplier (item) = { | |
22 | - | let key = match getString(this, (item + "_owner")) { | |
23 | - | case t: String => | |
24 | - | t | |
25 | - | case _ => | |
26 | - | NONE | |
27 | - | } | |
28 | - | key | |
29 | - | } | |
49 | + | func getKeyCommit (item,user) = (((item + "_") + user) + "_commit") | |
50 | + | ||
51 | + | ||
52 | + | func getKeyCommitsCount (item) = (item + "_cmtcnt") | |
53 | + | ||
54 | + | ||
55 | + | func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal") | |
56 | + | ||
57 | + | ||
58 | + | func getKeyItemStatus (item) = (item + "_status") | |
59 | + | ||
60 | + | ||
61 | + | func getKeyVotesCount (item,vote) = ((item + "_res:") + vote) | |
62 | + | ||
63 | + | ||
64 | + | func getValueItemSupplier (account) = getStringByKey(getKeyItemSupplier(account)) | |
65 | + | ||
66 | + | ||
67 | + | func getValueCommit (item,user) = getStringByKey(getKeyCommit(item, user)) | |
68 | + | ||
69 | + | ||
70 | + | func getValueCommitsCount (item) = getIntegerByKey(getKeyCommitsCount(item)) | |
71 | + | ||
72 | + | ||
73 | + | func getValueReveal (item,user) = getStringByKey(getKeyReveal(item, user)) | |
74 | + | ||
75 | + | ||
76 | + | func getValueItemStatus (item) = getStringByKey(getKeyItemStatus(item)) | |
77 | + | ||
78 | + | ||
79 | + | func getValueVotesCount (item,vote) = getIntegerByKey(getKeyVotesCount(item, vote)) | |
30 | 80 | ||
31 | 81 | ||
32 | 82 | @Callable(i) | |
33 | 83 | func addItem (title,price,data) = { | |
34 | 84 | let supplierAddress = toBase58String(i.caller.bytes) | |
35 | 85 | let item = getKeyItem(supplierAddress, title) | |
36 | 86 | if ((0 >= price)) | |
37 | 87 | then throw("purchase amount cannot be less than item price") | |
38 | 88 | else if ((getValueItemSupplier(item) != NONE)) | |
39 | 89 | then throw("An item already exists") | |
40 | 90 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
41 | 91 | } | |
42 | 92 | ||
43 | 93 | ||
94 | + | ||
95 | + | @Callable(i) | |
96 | + | func voteCommit (item,hash) = { | |
97 | + | let user = toBase58String(i.caller.bytes) | |
98 | + | let commitsCount = getValueCommitsCount(item) | |
99 | + | let status = getValueItemStatus(item) | |
100 | + | if ((commitsCount >= VOTERS)) | |
101 | + | then throw("Reached max number of voters") | |
102 | + | else if ((getValueCommit(item, user) != NONE)) | |
103 | + | then throw("Your Voted already") | |
104 | + | else if ((getValueItemSupplier(getKeyItemSupplier(item)) == NONE)) | |
105 | + | then throw("Item Does not exist") | |
106 | + | else if (if ((status != NONE)) | |
107 | + | then (status != VOTING) | |
108 | + | else false) | |
109 | + | then throw("Voting is not active for this Item now") | |
110 | + | else { | |
111 | + | let newStatus = if ((commitsCount == VOTERS)) | |
112 | + | then REVEAL | |
113 | + | else VOTING | |
114 | + | WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitsCount(item), (commitsCount + 1)), DataEntry(getKeyItemStatus(item), newStatus)]) | |
115 | + | } | |
116 | + | } | |
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | @Callable(i) | |
121 | + | func voteReveal (item,vote,salt) = { | |
122 | + | let user = toBase58String(i.caller.bytes) | |
123 | + | let status = getValueItemStatus(item) | |
124 | + | let newVotesCount = (getValueVotesCount(item, vote) + 1) | |
125 | + | let saltedVote = ((item + vote) + salt) | |
126 | + | if ((toBase58String(sha256(toBytes(saltedVote))) != getValueCommit(item, user))) | |
127 | + | then throw("Reveal data is not valid") | |
128 | + | else if ((VOTERS > getValueCommitsCount(item))) | |
129 | + | then throw("Max Number of Voters not reached") | |
130 | + | else if ((getValueReveal(item, user) != NONE)) | |
131 | + | then throw("You Voted Already") | |
132 | + | else if (if ((status != VOTING)) | |
133 | + | then (status != REVEAL) | |
134 | + | else false) | |
135 | + | then throw("Voting is not active for this item now") | |
136 | + | else if (if ((vote != FEATURED)) | |
137 | + | then (vote != DELISTED) | |
138 | + | else false) | |
139 | + | then throw("Provided voting option is incorrect") | |
140 | + | else { | |
141 | + | let newStatus = if ((newVotesCount >= QUORUM)) | |
142 | + | then vote | |
143 | + | else REVEAL | |
144 | + | WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVotesCount(item, vote), newVotesCount), DataEntry(getKeyItemStatus(item), newStatus)]) | |
145 | + | } | |
146 | + | } | |
147 | + | ||
148 | + |
github/deemru/w8io/026f985 37.12 ms ◑