tx · Fx5ACseYxVZU52MtutD5RkjvTepebGGdx4QGM9hGPtKK 3MyJoBjw9nC4uhgWULVJUaEZEL6z9As7Yfq: -0.00900000 Waves 2022.07.12 19:40 [2136757] smart account 3MyJoBjw9nC4uhgWULVJUaEZEL6z9As7Yfq > SELF 0.00000000 Waves
{ "type": 13, "id": "Fx5ACseYxVZU52MtutD5RkjvTepebGGdx4QGM9hGPtKK", "fee": 900000, "feeAssetId": null, "timestamp": 1657644018305, "version": 2, "chainId": 84, "sender": "3MyJoBjw9nC4uhgWULVJUaEZEL6z9As7Yfq", "senderPublicKey": "6E1saVK6whrqLsuLBQRGg6smask3XK5nkfiAWyGd3pEm", "proofs": [ "5eFmUBH6ZWs4tWfKVgUDVgRs8hT85M4DGirPzC5kLrTGzsV9crjBGzAt53pGHWCG8ZdDncJzzh9ZJFBbpaDwL8oB" ], "script": "base64:AAIFAAAAAAAAABcIAhIDCgEIEgMKAQgSAwoBCBIECgIIBAAAABMAAAAADVZPVElOR19CTE9DS1MAAAAAAAAAAGQAAAAAC1ZPVEVfQ0xPU0VEAgAAAAZDTE9TRUQAAAAAC1ZPVEVfT1BFTkVEAgAAAARPUEVOAAAAAAxEWVpfQVNTRVRfSUQBAAAAIN86bNLcP4xP9VBjVIPIz45BypCk5SNOYrbRgrI4NIymAAAAAA5NSU5fRFlaX0FNT1VOVAAAAAAABfXhAAAAAAAPc3RhdHVzS2V5UHJlZml4AgAAAAdzdGF0dXNfAAAAAA1vcGVuS2V5UHJlZml4AgAAAAVvcGVuXwAAAAAOdG90YWxZZXNTdWZmaXgCAAAACl90b3RhbF95ZXMAAAAADXRvdGFsTm9TdWZmaXgCAAAACV90b3RhbF9ubwAAAAAPcmVwYXltZW50UHJlZml4AgAAAApyZXBheW1lbnRfAQAAAAxnZXRTdGF0dXNLZXkAAAABAAAAAmlkCQABLAAAAAIFAAAAD3N0YXR1c0tleVByZWZpeAUAAAACaWQBAAAACmdldE9wZW5LZXkAAAABAAAAAmlkCQABLAAA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ZvdGVzU29GYXIAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAACW5vVm90ZUtleQUAAAAKbmV3Tm9Wb3RlcwkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgUAAAAMcmVwYXltZW50S2V5BQAAAAZhbW91bnQFAAAAA25pbAUAAAADbmlsBQAAAAhuZXdFbnRyeQAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5csSM4A==", "height": 2136757, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: ghoHbqxVaDGFUWyUFrY8KcVxd2XYcCNfKrSW6Ax1uuT Next: 3NTbYMkchWtihfgiK8ogfP47R67pETNCCEi3AehbTaaq Diff:
Old | New | Differences | |
---|---|---|---|
52 | 52 | n | |
53 | 53 | case _ => | |
54 | 54 | -1 | |
55 | + | } | |
56 | + | ||
57 | + | ||
58 | + | func isAllowed (address) = match getBoolean(this, (toString(address) + "_allowed")) { | |
59 | + | case b: Boolean => | |
60 | + | b | |
61 | + | case _ => | |
62 | + | false | |
55 | 63 | } | |
56 | 64 | ||
57 | 65 | ||
110 | 118 | else { | |
111 | 119 | let payment = value(i.payments[0]) | |
112 | 120 | let caller = i.caller | |
113 | - | let amount = payment.amount | |
114 | - | if (!(isDefined(payment.assetId))) | |
115 | - | then throw("Payment in Waves not allowed!") | |
121 | + | if (isAllowed(caller)) | |
122 | + | then throw("Address not allowed to vote!") | |
116 | 123 | else { | |
117 | - | let | |
118 | - | | |
119 | - | | |
120 | - | | |
121 | - | | |
122 | - | | |
123 | - | | |
124 | - | | |
125 | - | then throw(" | |
126 | - | else | |
127 | - | | |
128 | - | if (( | |
129 | - | then throw(" | |
124 | + | let amount = payment.amount | |
125 | + | if (!(isDefined(payment.assetId))) | |
126 | + | then throw("Payment in Waves not allowed!") | |
127 | + | else { | |
128 | + | let assetId = toBase58String(value(payment.assetId)) | |
129 | + | let repaymentKey = getRepaymentKey(id, caller) | |
130 | + | let refundAmount = getRefundAmount(repaymentKey) | |
131 | + | if ((refundAmount != -1)) | |
132 | + | then throw("Only one vote per id per address!") | |
133 | + | else if ((assetId != toBase58String(DYZ_ASSET_ID))) | |
134 | + | then throw("payment in DZY necessary!") | |
135 | + | else if ((amount != MIN_DYZ_AMOUNT)) | |
136 | + | then throw("payment amount wrong!") | |
130 | 137 | else { | |
131 | - | let openHeight = match getInteger(this, getOpenKey(id)) { | |
132 | - | case a: Int => | |
133 | - | a | |
134 | - | case _ => | |
135 | - | 0 | |
136 | - | } | |
137 | - | if ((height > (openHeight + VOTING_BLOCKS))) | |
138 | - | then throw("voting ended!") | |
138 | + | let voteStatus = getVoteStatus(id) | |
139 | + | if ((voteStatus == VOTE_CLOSED)) | |
140 | + | then throw("vote closed!") | |
139 | 141 | else { | |
140 | - | let newEntry = if ((vote == "yes")) | |
141 | - | then { | |
142 | - | let yesVoteKey = getTotalYesKey(id) | |
143 | - | let yesVotesSoFar = match getInteger(this, yesVoteKey) { | |
144 | - | case a: Int => | |
145 | - | a | |
146 | - | case _ => | |
147 | - | 0 | |
142 | + | let openHeight = match getInteger(this, getOpenKey(id)) { | |
143 | + | case a: Int => | |
144 | + | a | |
145 | + | case _ => | |
146 | + | 0 | |
147 | + | } | |
148 | + | if ((height > (openHeight + VOTING_BLOCKS))) | |
149 | + | then throw("voting ended!") | |
150 | + | else { | |
151 | + | let newEntry = if ((vote == true)) | |
152 | + | then { | |
153 | + | let yesVoteKey = getTotalYesKey(id) | |
154 | + | let yesVotesSoFar = match getInteger(this, yesVoteKey) { | |
155 | + | case a: Int => | |
156 | + | a | |
157 | + | case _ => | |
158 | + | 0 | |
159 | + | } | |
160 | + | let newYesVotes = (yesVotesSoFar + 1) | |
161 | + | [IntegerEntry(yesVoteKey, newYesVotes), IntegerEntry(repaymentKey, amount)] | |
162 | + | } | |
163 | + | else if ((vote == false)) | |
164 | + | then { | |
165 | + | let noVoteKey = getTotalNoKey(id) | |
166 | + | let noVotesSoFar = match getInteger(this, noVoteKey) { | |
167 | + | case a: Int => | |
168 | + | a | |
169 | + | case _ => | |
170 | + | 0 | |
171 | + | } | |
172 | + | let newNoVotes = (noVotesSoFar + 1) | |
173 | + | [IntegerEntry(noVoteKey, newNoVotes), IntegerEntry(repaymentKey, amount)] | |
174 | + | } | |
175 | + | else nil | |
176 | + | newEntry | |
148 | 177 | } | |
149 | - | let newYesVotes = (yesVotesSoFar + 1) | |
150 | - | [IntegerEntry(yesVoteKey, newYesVotes), IntegerEntry(repaymentKey, amount)] | |
151 | - | } | |
152 | - | else if ((vote == "no")) | |
153 | - | then { | |
154 | - | let noVoteKey = getTotalNoKey(id) | |
155 | - | let noVotesSoFar = match getInteger(this, noVoteKey) { | |
156 | - | case a: Int => | |
157 | - | a | |
158 | - | case _ => | |
159 | - | 0 | |
160 | - | } | |
161 | - | let newNoVotes = (noVotesSoFar + 1) | |
162 | - | [IntegerEntry(noVoteKey, newNoVotes), IntegerEntry(repaymentKey, amount)] | |
163 | - | } | |
164 | - | else nil | |
165 | - | newEntry | |
166 | 178 | } | |
167 | 179 | } | |
168 | - | ||
180 | + | } | |
169 | 181 | } | |
170 | 182 | } | |
171 | 183 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let VOTING_BLOCKS = 100 | |
5 | 5 | ||
6 | 6 | let VOTE_CLOSED = "CLOSED" | |
7 | 7 | ||
8 | 8 | let VOTE_OPENED = "OPEN" | |
9 | 9 | ||
10 | 10 | let DYZ_ASSET_ID = base58'G2Pb7CMztps7XEVGCiUuJkLiS3ZCo69APQNbJs2nz21j' | |
11 | 11 | ||
12 | 12 | let MIN_DYZ_AMOUNT = 100000000 | |
13 | 13 | ||
14 | 14 | let statusKeyPrefix = "status_" | |
15 | 15 | ||
16 | 16 | let openKeyPrefix = "open_" | |
17 | 17 | ||
18 | 18 | let totalYesSuffix = "_total_yes" | |
19 | 19 | ||
20 | 20 | let totalNoSuffix = "_total_no" | |
21 | 21 | ||
22 | 22 | let repaymentPrefix = "repayment_" | |
23 | 23 | ||
24 | 24 | func getStatusKey (id) = (statusKeyPrefix + id) | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func getOpenKey (id) = (openKeyPrefix + id) | |
28 | 28 | ||
29 | 29 | ||
30 | 30 | func getTotalYesKey (id) = (id + totalYesSuffix) | |
31 | 31 | ||
32 | 32 | ||
33 | 33 | func getTotalNoKey (id) = (id + totalNoSuffix) | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func getVoteStatus (id) = getString(this, getStatusKey(id)) | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | func getRepaymentKey (id,address) = (((repaymentPrefix + id) + "_") + toString(address)) | |
40 | 40 | ||
41 | 41 | ||
42 | 42 | func getStartHeight (id) = match getInteger(this, getOpenKey(id)) { | |
43 | 43 | case n: Int => | |
44 | 44 | n | |
45 | 45 | case _ => | |
46 | 46 | -1 | |
47 | 47 | } | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | func getRefundAmount (repaymentKey) = match getInteger(this, repaymentKey) { | |
51 | 51 | case n: Int => | |
52 | 52 | n | |
53 | 53 | case _ => | |
54 | 54 | -1 | |
55 | + | } | |
56 | + | ||
57 | + | ||
58 | + | func isAllowed (address) = match getBoolean(this, (toString(address) + "_allowed")) { | |
59 | + | case b: Boolean => | |
60 | + | b | |
61 | + | case _ => | |
62 | + | false | |
55 | 63 | } | |
56 | 64 | ||
57 | 65 | ||
58 | 66 | @Callable(i) | |
59 | 67 | func openVote (id) = { | |
60 | 68 | let startHeightKey = getOpenKey(id) | |
61 | 69 | let alreadyVoting = getStartHeight(id) | |
62 | 70 | if ((alreadyVoting != -1)) | |
63 | 71 | then throw("Vote already ongoing for id!") | |
64 | 72 | else { | |
65 | 73 | let statusKey = getStatusKey(id) | |
66 | 74 | [StringEntry(statusKey, VOTE_OPENED), IntegerEntry(startHeightKey, height)] | |
67 | 75 | } | |
68 | 76 | } | |
69 | 77 | ||
70 | 78 | ||
71 | 79 | ||
72 | 80 | @Callable(i) | |
73 | 81 | func closeVote (id) = { | |
74 | 82 | let currentStartHeight = getStartHeight(id) | |
75 | 83 | if ((currentStartHeight == -1)) | |
76 | 84 | then throw("No vote found for id!") | |
77 | 85 | else if (((currentStartHeight + VOTING_BLOCKS) > height)) | |
78 | 86 | then throw("Vote can not be closed yet!") | |
79 | 87 | else { | |
80 | 88 | let statusKey = getStatusKey(id) | |
81 | 89 | [StringEntry(statusKey, VOTE_CLOSED)] | |
82 | 90 | } | |
83 | 91 | } | |
84 | 92 | ||
85 | 93 | ||
86 | 94 | ||
87 | 95 | @Callable(i) | |
88 | 96 | func claim (id) = { | |
89 | 97 | let startHeight = getStartHeight(id) | |
90 | 98 | if ((startHeight == -1)) | |
91 | 99 | then throw("No vote started for this id!") | |
92 | 100 | else if (((startHeight + VOTING_BLOCKS) >= height)) | |
93 | 101 | then throw("You can only claim after vote ends!") | |
94 | 102 | else { | |
95 | 103 | let caller = i.caller | |
96 | 104 | let repaymentKey = getRepaymentKey(id, caller) | |
97 | 105 | let repayAmount = getRefundAmount(repaymentKey) | |
98 | 106 | let statusKey = getStatusKey(id) | |
99 | 107 | if ((repayAmount > 0)) | |
100 | 108 | then [ScriptTransfer(caller, repayAmount, DYZ_ASSET_ID), StringEntry(statusKey, VOTE_CLOSED), IntegerEntry(repaymentKey, 0)] | |
101 | 109 | else throw("Nothing to claim!") | |
102 | 110 | } | |
103 | 111 | } | |
104 | 112 | ||
105 | 113 | ||
106 | 114 | ||
107 | 115 | @Callable(i) | |
108 | 116 | func vote (id,vote) = if ((size(i.payments) != 1)) | |
109 | 117 | then throw("One payment in DZY needs to be attached") | |
110 | 118 | else { | |
111 | 119 | let payment = value(i.payments[0]) | |
112 | 120 | let caller = i.caller | |
113 | - | let amount = payment.amount | |
114 | - | if (!(isDefined(payment.assetId))) | |
115 | - | then throw("Payment in Waves not allowed!") | |
121 | + | if (isAllowed(caller)) | |
122 | + | then throw("Address not allowed to vote!") | |
116 | 123 | else { | |
117 | - | let | |
118 | - | | |
119 | - | | |
120 | - | | |
121 | - | | |
122 | - | | |
123 | - | | |
124 | - | | |
125 | - | then throw(" | |
126 | - | else | |
127 | - | | |
128 | - | if (( | |
129 | - | then throw(" | |
124 | + | let amount = payment.amount | |
125 | + | if (!(isDefined(payment.assetId))) | |
126 | + | then throw("Payment in Waves not allowed!") | |
127 | + | else { | |
128 | + | let assetId = toBase58String(value(payment.assetId)) | |
129 | + | let repaymentKey = getRepaymentKey(id, caller) | |
130 | + | let refundAmount = getRefundAmount(repaymentKey) | |
131 | + | if ((refundAmount != -1)) | |
132 | + | then throw("Only one vote per id per address!") | |
133 | + | else if ((assetId != toBase58String(DYZ_ASSET_ID))) | |
134 | + | then throw("payment in DZY necessary!") | |
135 | + | else if ((amount != MIN_DYZ_AMOUNT)) | |
136 | + | then throw("payment amount wrong!") | |
130 | 137 | else { | |
131 | - | let openHeight = match getInteger(this, getOpenKey(id)) { | |
132 | - | case a: Int => | |
133 | - | a | |
134 | - | case _ => | |
135 | - | 0 | |
136 | - | } | |
137 | - | if ((height > (openHeight + VOTING_BLOCKS))) | |
138 | - | then throw("voting ended!") | |
138 | + | let voteStatus = getVoteStatus(id) | |
139 | + | if ((voteStatus == VOTE_CLOSED)) | |
140 | + | then throw("vote closed!") | |
139 | 141 | else { | |
140 | - | let newEntry = if ((vote == "yes")) | |
141 | - | then { | |
142 | - | let yesVoteKey = getTotalYesKey(id) | |
143 | - | let yesVotesSoFar = match getInteger(this, yesVoteKey) { | |
144 | - | case a: Int => | |
145 | - | a | |
146 | - | case _ => | |
147 | - | 0 | |
142 | + | let openHeight = match getInteger(this, getOpenKey(id)) { | |
143 | + | case a: Int => | |
144 | + | a | |
145 | + | case _ => | |
146 | + | 0 | |
147 | + | } | |
148 | + | if ((height > (openHeight + VOTING_BLOCKS))) | |
149 | + | then throw("voting ended!") | |
150 | + | else { | |
151 | + | let newEntry = if ((vote == true)) | |
152 | + | then { | |
153 | + | let yesVoteKey = getTotalYesKey(id) | |
154 | + | let yesVotesSoFar = match getInteger(this, yesVoteKey) { | |
155 | + | case a: Int => | |
156 | + | a | |
157 | + | case _ => | |
158 | + | 0 | |
159 | + | } | |
160 | + | let newYesVotes = (yesVotesSoFar + 1) | |
161 | + | [IntegerEntry(yesVoteKey, newYesVotes), IntegerEntry(repaymentKey, amount)] | |
162 | + | } | |
163 | + | else if ((vote == false)) | |
164 | + | then { | |
165 | + | let noVoteKey = getTotalNoKey(id) | |
166 | + | let noVotesSoFar = match getInteger(this, noVoteKey) { | |
167 | + | case a: Int => | |
168 | + | a | |
169 | + | case _ => | |
170 | + | 0 | |
171 | + | } | |
172 | + | let newNoVotes = (noVotesSoFar + 1) | |
173 | + | [IntegerEntry(noVoteKey, newNoVotes), IntegerEntry(repaymentKey, amount)] | |
174 | + | } | |
175 | + | else nil | |
176 | + | newEntry | |
148 | 177 | } | |
149 | - | let newYesVotes = (yesVotesSoFar + 1) | |
150 | - | [IntegerEntry(yesVoteKey, newYesVotes), IntegerEntry(repaymentKey, amount)] | |
151 | - | } | |
152 | - | else if ((vote == "no")) | |
153 | - | then { | |
154 | - | let noVoteKey = getTotalNoKey(id) | |
155 | - | let noVotesSoFar = match getInteger(this, noVoteKey) { | |
156 | - | case a: Int => | |
157 | - | a | |
158 | - | case _ => | |
159 | - | 0 | |
160 | - | } | |
161 | - | let newNoVotes = (noVotesSoFar + 1) | |
162 | - | [IntegerEntry(noVoteKey, newNoVotes), IntegerEntry(repaymentKey, amount)] | |
163 | - | } | |
164 | - | else nil | |
165 | - | newEntry | |
166 | 178 | } | |
167 | 179 | } | |
168 | - | ||
180 | + | } | |
169 | 181 | } | |
170 | 182 | } | |
171 | 183 | ||
172 | 184 | ||
173 | 185 | @Verifier(tx) | |
174 | 186 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
175 | 187 |
github/deemru/w8io/169f3d6 75.38 ms ◑