tx · 64e2puVpfDrwBNNJqpKT399YncThTazbBgdqWawMYaPJ 3N86AryjXNvAuNs3mV9xKPTjXnAYQimiHDF: -0.01000000 Waves 2023.09.18 18:51 [2761030] smart account 3N86AryjXNvAuNs3mV9xKPTjXnAYQimiHDF > SELF 0.00000000 Waves
{ "type": 13, "id": "64e2puVpfDrwBNNJqpKT399YncThTazbBgdqWawMYaPJ", "fee": 1000000, "feeAssetId": null, "timestamp": 1695052283512, "version": 2, "chainId": 84, "sender": "3N86AryjXNvAuNs3mV9xKPTjXnAYQimiHDF", "senderPublicKey": "7Zo8C4qkZishvcPg5SUixQPySKeM49Jeui21Tih7iPr9", "proofs": [ "3rxjMApTxgpRMVWqRy1Rjup4DS7jRbaMJuqSk7FmApYKvxcHbQmQdgn9fhhvJXhJu2uYsFvpwHDRLru9a3SdFVca" ], "script": "base64:BgIVCAISABIDCgEBEgQKAgICEgQKAgEEEQADU0VQAgJfXwAPcmVwdXRhdGlvbkFzc2V0ASBp6x+DcpBVAG0dTZ5QIAuA7CaS8wuiEOK6KQOBSERbTgAMcHJvcG9zYWxUaW1lCQBoAgkAaAIJAGgCCQBoAgDoBwA8ADwAGAADARFjb3VudFByb3Bvc2Fsc0tleQACAmNwAQtwcm9wb3NhbEtleQEKcHJvcG9zYWxJZAkAuQkCCQDMCAICAXAJAMwIAgkApAMBBQpwcm9wb3NhbElkBQNuaWwFA1NFUAESdW5sb2NrVGltZXN0YW1wS2V5AQR1c2VyCQC5CQIJAMwIAgICdXQJAMwIAgkA2AQBCAUEdXNlcgVieXRlcwUDbmlsBQNTRVABEHVzZXJEZXBvc2l0ZWRLZXkBBHVzZXIJALkJAgkAzAgCAgJ1ZAkAzAgCCQDYBAEIBQR1c2VyBWJ5dGVzBQNuaWwFA1NFUAETdXNlclByb3Bvc2FsVm90ZUtleQIKcHJvcG9zYWxJZAR1c2VyCQC5CQIJAMwIAgICdXAJAMwIAgkApAMBBQpwcm9wb3NhbElkCQDMCAIJANgEAQgFBHVzZX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9zYWxBbGl2ZQEFAmlkCQACAQIQcHJvcG9zYWxOb3RBbGl2ZQQIcHJvcG9zYWwJAQtnZXRQcm9wb3NhbAEFAmlkBAp1bmxvY2tUaW1lCQCWAwEJAMwIAgkAZAIIBQhwcm9wb3NhbAJfNAUMcHJvcG9zYWxUaW1lCQDMCAIJARJnZXRVbmxvY2tUaW1lc3RhbXABCAUBaQZjYWxsZXIFA25pbAQLcHJldml1c1ZvdGUJAQtnZXRVc2VyVm90ZQIFAmlkCAUBaQZjYWxsZXIECXZvdGVQb3dlcgkBHHVzZXJEZXBvc2l0ZWRSZXB1dGF0aW9uQXNzZXQBCAUBaQZjYWxsZXIJAMwIAgkBC3NldFByb3Bvc2FsBwUCaWQIBQhwcm9wb3NhbAJfMQgFCHByb3Bvc2FsAl8yCAUIcHJvcG9zYWwCXzMIBQhwcm9wb3NhbAJfNAkAZQIIBQhwcm9wb3NhbAJfNQMJAGYCBQtwcmV2aXVzVm90ZQAABQtwcmV2aXVzVm90ZQkAZAIAAAMFBHZvdGUFCXZvdGVQb3dlcgAACQBlAggFCHByb3Bvc2FsAl82AwkAZgIAAAULcHJldml1c1ZvdGUFC3ByZXZpdXNWb3RlCQBkAgAAAwUEdm90ZQAABQl2b3RlUG93ZXIFA25pbAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXnA+hks", "height": 2761030, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DnDqbQmvr2vAMYSyGzb6STzYwVk6hTd6FtobZxZy3FS5 Next: 3RSsrMipRS1JTc1qaA7zr383JRgs8LAirkghcVrY4Xwo Diff:
Old | New | Differences | |
---|---|---|---|
7 | 7 | ||
8 | 8 | let proposalTime = ((((1000 * 60) * 60) * 24) * 3) | |
9 | 9 | ||
10 | - | func proposalKey (id) = makeString(["p", toString(id)], SEP) | |
10 | + | func countProposalsKey () = "cp" | |
11 | + | ||
12 | + | ||
13 | + | func proposalKey (proposalId) = makeString(["p", toString(proposalId)], SEP) | |
14 | + | ||
15 | + | ||
16 | + | func unlockTimestampKey (user) = makeString(["ut", toBase58String(user.bytes)], SEP) | |
17 | + | ||
18 | + | ||
19 | + | func userDepositedKey (user) = makeString(["ud", toBase58String(user.bytes)], SEP) | |
20 | + | ||
21 | + | ||
22 | + | func userProposalVoteKey (proposalId,user) = makeString(["up", toString(proposalId), toBase58String(user.bytes)], SEP) | |
23 | + | ||
24 | + | ||
25 | + | func setUserVote (proposalId,user,votePower) = StringEntry(userProposalVoteKey(proposalId, user), toString(votePower)) | |
26 | + | ||
27 | + | ||
28 | + | func getUserVote (proposalId,user) = match getInteger(userProposalVoteKey(proposalId, user)) { | |
29 | + | case i: Int => | |
30 | + | i | |
31 | + | case _ => | |
32 | + | 0 | |
33 | + | } | |
11 | 34 | ||
12 | 35 | ||
13 | 36 | func setProposal (id,creator,title,text,timestampCreation,countVotesFor,CountVotesAgainst) = StringEntry(proposalKey(id), makeString_11C([toBase16String(creator.bytes), title, text, toString(timestampCreation), toString(countVotesFor), toString(CountVotesAgainst)], SEP)) | |
20 | 43 | case _ => | |
21 | 44 | throw("proposal not found") | |
22 | 45 | }, SEP) | |
23 | - | $Tuple6( | |
46 | + | $Tuple6(addressFromStringValue(savedString[0]), savedString[1], savedString[2], parseIntValue(savedString[3]), parseIntValue(savedString[4]), parseIntValue(savedString[5])) | |
24 | 47 | } | |
25 | 48 | ||
26 | 49 | ||
27 | - | func unlockTimestampKey (address) = makeString(["ut", toBase58String(address)], SEP) | |
28 | - | ||
29 | - | ||
30 | - | func countProposalsKey () = "cp" | |
31 | - | ||
32 | - | ||
33 | - | func proposalTitleKey (id) = makeString(["pti", toString(id)], SEP) | |
34 | - | ||
35 | - | ||
36 | - | func proposalTextKey (id) = makeString(["pte", toString(id)], SEP) | |
37 | - | ||
38 | - | ||
39 | - | func proposalTimestampCreationKey (id) = makeString(["ptc", toString(id)], SEP) | |
40 | - | ||
41 | - | ||
42 | - | func proposalCountVotesForKey (id) = makeString(["pcvf", toString(id)], SEP) | |
43 | - | ||
44 | - | ||
45 | - | func proposalCountVotesAgainstKey (id) = makeString(["pcva", toString(id)], SEP) | |
46 | - | ||
47 | - | ||
48 | - | func userProposalVoteKey (address,id) = makeString(["upv", toString(id), toBase58String(address)], SEP) | |
49 | - | ||
50 | - | ||
51 | - | func userProposalVotePowerKey (address,id) = makeString(["upvp", toString(id), toBase58String(address)], SEP) | |
52 | - | ||
53 | - | ||
54 | - | func pmtReputationAsset (i) = if ((size(i.payments) == 1)) | |
50 | + | func isPayReputationAsset (i) = if ((size(i.payments) == 1)) | |
55 | 51 | then if ((i.payments[0].assetId == reputationAsset)) | |
56 | 52 | then true | |
57 | 53 | else throw("only reputation assets") | |
58 | 54 | else throw("only 1 payment") | |
59 | 55 | ||
60 | 56 | ||
61 | - | func getUnlockTimestamp ( | |
57 | + | func getUnlockTimestamp (user) = match getInteger(this, unlockTimestampKey(user)) { | |
62 | 58 | case a: Int => | |
63 | 59 | a | |
64 | 60 | case _ => | |
74 | 70 | } | |
75 | 71 | ||
76 | 72 | ||
77 | - | func | |
73 | + | func userDepositedReputationAsset (user) = match getInteger(this, userDepositedKey(user)) { | |
78 | 74 | case a: Int => | |
79 | 75 | a | |
80 | 76 | case _ => | |
82 | 78 | } | |
83 | 79 | ||
84 | 80 | ||
85 | - | func countVotesAgainst (id) = match getInteger(this, proposalCountVotesAgainstKey(id)) { | |
86 | - | case a: Int => | |
87 | - | a | |
88 | - | case _ => | |
89 | - | 0 | |
90 | - | } | |
91 | - | ||
92 | - | ||
93 | - | func countVotesUser (address,id) = match getInteger(this, userProposalVotePowerKey(address, id)) { | |
94 | - | case a: Int => | |
95 | - | a | |
96 | - | case _ => | |
97 | - | 0 | |
98 | - | } | |
99 | - | ||
100 | - | ||
101 | - | func balanceReputationAsset (address) = match getInteger(this, toBase58String(address)) { | |
102 | - | case a: Int => | |
103 | - | a | |
104 | - | case _ => | |
105 | - | 0 | |
106 | - | } | |
107 | - | ||
108 | - | ||
109 | - | func proposalTimestampCreation (id) = match getInteger(this, proposalTimestampCreationKey(id)) { | |
110 | - | case a: Int => | |
111 | - | a | |
112 | - | case _ => | |
113 | - | throw("proposal not created") | |
114 | - | } | |
115 | - | ||
116 | - | ||
117 | 81 | func isProposalAlive (id) = if (if ((countProposals() > id)) | |
118 | - | then (( | |
82 | + | then ((getProposal(id)._4 + proposalTime) > lastBlock.timestamp) | |
119 | 83 | else false) | |
120 | 84 | then true | |
121 | - | else throw(" | |
85 | + | else throw("proposal not alive") | |
122 | 86 | ||
123 | 87 | ||
124 | 88 | @Callable(i) | |
125 | 89 | func deposit () = { | |
126 | - | let checks = [ | |
90 | + | let checks = [isPayReputationAsset(i)] | |
127 | 91 | if ((checks == checks)) | |
128 | 92 | then { | |
129 | 93 | let currentKey = toBase58String(i.caller.bytes) | |
130 | - | let currentAmount = | |
94 | + | let currentAmount = userDepositedReputationAsset(i.caller) | |
131 | 95 | let newAmount = (currentAmount + i.payments[0].amount) | |
132 | 96 | [IntegerEntry(currentKey, newAmount)] | |
133 | 97 | } | |
148 | 112 | let newAmount = (currentAmount - amount) | |
149 | 113 | if ((0 > amount)) | |
150 | 114 | then throw("Can't withdraw negative amount") | |
151 | - | else if ((getUnlockTimestamp(i.caller | |
115 | + | else if ((getUnlockTimestamp(i.caller) > lastBlock.timestamp)) | |
152 | 116 | then throw("Locked") | |
153 | 117 | else if ((0 > newAmount)) | |
154 | 118 | then throw("Not enough balance") | |
158 | 122 | ||
159 | 123 | ||
160 | 124 | @Callable(i) | |
161 | - | func | |
125 | + | func createProposal (title,text) = { | |
162 | 126 | let count = countProposals() | |
163 | 127 | [setProposal(count, i.caller, toBase16String(title), toBase16String(text), lastBlock.timestamp, 0, 0)] | |
164 | 128 | } | |
166 | 130 | ||
167 | 131 | ||
168 | 132 | @Callable(i) | |
169 | - | func createProposal (title,text) = { | |
170 | - | let count = countProposals() | |
171 | - | [StringEntry(proposalTitleKey(count), title), StringEntry(proposalTextKey(count), text), IntegerEntry(proposalTimestampCreationKey(count), lastBlock.timestamp), IntegerEntry(countProposalsKey(), (count + 1))] | |
172 | - | } | |
173 | - | ||
174 | - | ||
175 | - | ||
176 | - | @Callable(i) | |
177 | - | func vote (id,vote) = if (isProposalAlive(id)) | |
178 | - | then { | |
179 | - | let unlockTime = max([(proposalTimestampCreation(id) + proposalTime), getUnlockTimestamp(i.caller.bytes)]) | |
180 | - | let u = match getBoolean(this, userProposalVoteKey(i.caller.bytes, id)) { | |
181 | - | case a: Boolean => | |
182 | - | if (a) | |
183 | - | then IntegerEntry(proposalCountVotesForKey(id), (countVotesFor(id) - countVotesUser(i.caller.bytes, id))) | |
184 | - | else IntegerEntry(proposalCountVotesAgainstKey(id), (countVotesFor(id) - countVotesUser(i.caller.bytes, id))) | |
185 | - | case _ => | |
186 | - | unit | |
133 | + | func vote (id,vote) = if (!(isProposalAlive(id))) | |
134 | + | then throw("proposalNotAlive") | |
135 | + | else { | |
136 | + | let proposal = getProposal(id) | |
137 | + | let unlockTime = max([(proposal._4 + proposalTime), getUnlockTimestamp(i.caller)]) | |
138 | + | let previusVote = getUserVote(id, i.caller) | |
139 | + | let votePower = userDepositedReputationAsset(i.caller) | |
140 | + | [setProposal(id, proposal._1, proposal._2, proposal._3, proposal._4, (proposal._5 - (if ((previusVote > 0)) | |
141 | + | then previusVote | |
142 | + | else (0 + (if (vote) | |
143 | + | then votePower | |
144 | + | else 0)))), (proposal._6 - (if ((0 > previusVote)) | |
145 | + | then previusVote | |
146 | + | else (0 + (if (vote) | |
147 | + | then 0 | |
148 | + | else votePower)))))] | |
187 | 149 | } | |
188 | - | if ((vote == true)) | |
189 | - | then [IntegerEntry(proposalCountVotesForKey(id), (countVotesFor(id) + balanceReputationAsset(i.caller.bytes))), IntegerEntry(unlockTimestampKey(i.caller.bytes), unlockTime), BooleanEntry(userProposalVoteKey(i.caller.bytes, id), vote), IntegerEntry(userProposalVotePowerKey(i.caller.bytes, id), balanceReputationAsset(i.caller.bytes))] | |
190 | - | else [IntegerEntry(proposalCountVotesAgainstKey(id), (countVotesAgainst(id) + balanceReputationAsset(i.caller.bytes))), IntegerEntry(unlockTimestampKey(i.caller.bytes), unlockTime), BooleanEntry(userProposalVoteKey(i.caller.bytes, id), vote), IntegerEntry(userProposalVotePowerKey(i.caller.bytes, id), balanceReputationAsset(i.caller.bytes))] | |
191 | - | } | |
192 | - | else throw("proposalNotAlive") | |
193 | 150 | ||
194 | 151 | ||
195 | 152 | @Verifier(tx) |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | 6 | let reputationAsset = base58'88Tkdpqchhiqc9tNNG3SWQ2gfhZB4rBJKhMNS5Xmxhqw' | |
7 | 7 | ||
8 | 8 | let proposalTime = ((((1000 * 60) * 60) * 24) * 3) | |
9 | 9 | ||
10 | - | func proposalKey (id) = makeString(["p", toString(id)], SEP) | |
10 | + | func countProposalsKey () = "cp" | |
11 | + | ||
12 | + | ||
13 | + | func proposalKey (proposalId) = makeString(["p", toString(proposalId)], SEP) | |
14 | + | ||
15 | + | ||
16 | + | func unlockTimestampKey (user) = makeString(["ut", toBase58String(user.bytes)], SEP) | |
17 | + | ||
18 | + | ||
19 | + | func userDepositedKey (user) = makeString(["ud", toBase58String(user.bytes)], SEP) | |
20 | + | ||
21 | + | ||
22 | + | func userProposalVoteKey (proposalId,user) = makeString(["up", toString(proposalId), toBase58String(user.bytes)], SEP) | |
23 | + | ||
24 | + | ||
25 | + | func setUserVote (proposalId,user,votePower) = StringEntry(userProposalVoteKey(proposalId, user), toString(votePower)) | |
26 | + | ||
27 | + | ||
28 | + | func getUserVote (proposalId,user) = match getInteger(userProposalVoteKey(proposalId, user)) { | |
29 | + | case i: Int => | |
30 | + | i | |
31 | + | case _ => | |
32 | + | 0 | |
33 | + | } | |
11 | 34 | ||
12 | 35 | ||
13 | 36 | func setProposal (id,creator,title,text,timestampCreation,countVotesFor,CountVotesAgainst) = StringEntry(proposalKey(id), makeString_11C([toBase16String(creator.bytes), title, text, toString(timestampCreation), toString(countVotesFor), toString(CountVotesAgainst)], SEP)) | |
14 | 37 | ||
15 | 38 | ||
16 | 39 | func getProposal (id) = { | |
17 | 40 | let savedString = split( match getString(this, proposalKey(id)) { | |
18 | 41 | case s: String => | |
19 | 42 | s | |
20 | 43 | case _ => | |
21 | 44 | throw("proposal not found") | |
22 | 45 | }, SEP) | |
23 | - | $Tuple6( | |
46 | + | $Tuple6(addressFromStringValue(savedString[0]), savedString[1], savedString[2], parseIntValue(savedString[3]), parseIntValue(savedString[4]), parseIntValue(savedString[5])) | |
24 | 47 | } | |
25 | 48 | ||
26 | 49 | ||
27 | - | func unlockTimestampKey (address) = makeString(["ut", toBase58String(address)], SEP) | |
28 | - | ||
29 | - | ||
30 | - | func countProposalsKey () = "cp" | |
31 | - | ||
32 | - | ||
33 | - | func proposalTitleKey (id) = makeString(["pti", toString(id)], SEP) | |
34 | - | ||
35 | - | ||
36 | - | func proposalTextKey (id) = makeString(["pte", toString(id)], SEP) | |
37 | - | ||
38 | - | ||
39 | - | func proposalTimestampCreationKey (id) = makeString(["ptc", toString(id)], SEP) | |
40 | - | ||
41 | - | ||
42 | - | func proposalCountVotesForKey (id) = makeString(["pcvf", toString(id)], SEP) | |
43 | - | ||
44 | - | ||
45 | - | func proposalCountVotesAgainstKey (id) = makeString(["pcva", toString(id)], SEP) | |
46 | - | ||
47 | - | ||
48 | - | func userProposalVoteKey (address,id) = makeString(["upv", toString(id), toBase58String(address)], SEP) | |
49 | - | ||
50 | - | ||
51 | - | func userProposalVotePowerKey (address,id) = makeString(["upvp", toString(id), toBase58String(address)], SEP) | |
52 | - | ||
53 | - | ||
54 | - | func pmtReputationAsset (i) = if ((size(i.payments) == 1)) | |
50 | + | func isPayReputationAsset (i) = if ((size(i.payments) == 1)) | |
55 | 51 | then if ((i.payments[0].assetId == reputationAsset)) | |
56 | 52 | then true | |
57 | 53 | else throw("only reputation assets") | |
58 | 54 | else throw("only 1 payment") | |
59 | 55 | ||
60 | 56 | ||
61 | - | func getUnlockTimestamp ( | |
57 | + | func getUnlockTimestamp (user) = match getInteger(this, unlockTimestampKey(user)) { | |
62 | 58 | case a: Int => | |
63 | 59 | a | |
64 | 60 | case _ => | |
65 | 61 | 0 | |
66 | 62 | } | |
67 | 63 | ||
68 | 64 | ||
69 | 65 | func countProposals () = match getInteger(this, countProposalsKey()) { | |
70 | 66 | case a: Int => | |
71 | 67 | a | |
72 | 68 | case _ => | |
73 | 69 | 0 | |
74 | 70 | } | |
75 | 71 | ||
76 | 72 | ||
77 | - | func | |
73 | + | func userDepositedReputationAsset (user) = match getInteger(this, userDepositedKey(user)) { | |
78 | 74 | case a: Int => | |
79 | 75 | a | |
80 | 76 | case _ => | |
81 | 77 | 0 | |
82 | 78 | } | |
83 | 79 | ||
84 | 80 | ||
85 | - | func countVotesAgainst (id) = match getInteger(this, proposalCountVotesAgainstKey(id)) { | |
86 | - | case a: Int => | |
87 | - | a | |
88 | - | case _ => | |
89 | - | 0 | |
90 | - | } | |
91 | - | ||
92 | - | ||
93 | - | func countVotesUser (address,id) = match getInteger(this, userProposalVotePowerKey(address, id)) { | |
94 | - | case a: Int => | |
95 | - | a | |
96 | - | case _ => | |
97 | - | 0 | |
98 | - | } | |
99 | - | ||
100 | - | ||
101 | - | func balanceReputationAsset (address) = match getInteger(this, toBase58String(address)) { | |
102 | - | case a: Int => | |
103 | - | a | |
104 | - | case _ => | |
105 | - | 0 | |
106 | - | } | |
107 | - | ||
108 | - | ||
109 | - | func proposalTimestampCreation (id) = match getInteger(this, proposalTimestampCreationKey(id)) { | |
110 | - | case a: Int => | |
111 | - | a | |
112 | - | case _ => | |
113 | - | throw("proposal not created") | |
114 | - | } | |
115 | - | ||
116 | - | ||
117 | 81 | func isProposalAlive (id) = if (if ((countProposals() > id)) | |
118 | - | then (( | |
82 | + | then ((getProposal(id)._4 + proposalTime) > lastBlock.timestamp) | |
119 | 83 | else false) | |
120 | 84 | then true | |
121 | - | else throw(" | |
85 | + | else throw("proposal not alive") | |
122 | 86 | ||
123 | 87 | ||
124 | 88 | @Callable(i) | |
125 | 89 | func deposit () = { | |
126 | - | let checks = [ | |
90 | + | let checks = [isPayReputationAsset(i)] | |
127 | 91 | if ((checks == checks)) | |
128 | 92 | then { | |
129 | 93 | let currentKey = toBase58String(i.caller.bytes) | |
130 | - | let currentAmount = | |
94 | + | let currentAmount = userDepositedReputationAsset(i.caller) | |
131 | 95 | let newAmount = (currentAmount + i.payments[0].amount) | |
132 | 96 | [IntegerEntry(currentKey, newAmount)] | |
133 | 97 | } | |
134 | 98 | else throw("onlyReputationAsset") | |
135 | 99 | } | |
136 | 100 | ||
137 | 101 | ||
138 | 102 | ||
139 | 103 | @Callable(i) | |
140 | 104 | func withdraw (amount) = { | |
141 | 105 | let currentKey = toBase58String(i.caller.bytes) | |
142 | 106 | let currentAmount = match getInteger(this, currentKey) { | |
143 | 107 | case a: Int => | |
144 | 108 | a | |
145 | 109 | case _ => | |
146 | 110 | 0 | |
147 | 111 | } | |
148 | 112 | let newAmount = (currentAmount - amount) | |
149 | 113 | if ((0 > amount)) | |
150 | 114 | then throw("Can't withdraw negative amount") | |
151 | - | else if ((getUnlockTimestamp(i.caller | |
115 | + | else if ((getUnlockTimestamp(i.caller) > lastBlock.timestamp)) | |
152 | 116 | then throw("Locked") | |
153 | 117 | else if ((0 > newAmount)) | |
154 | 118 | then throw("Not enough balance") | |
155 | 119 | else [IntegerEntry(currentKey, newAmount), ScriptTransfer(i.caller, amount, reputationAsset)] | |
156 | 120 | } | |
157 | 121 | ||
158 | 122 | ||
159 | 123 | ||
160 | 124 | @Callable(i) | |
161 | - | func | |
125 | + | func createProposal (title,text) = { | |
162 | 126 | let count = countProposals() | |
163 | 127 | [setProposal(count, i.caller, toBase16String(title), toBase16String(text), lastBlock.timestamp, 0, 0)] | |
164 | 128 | } | |
165 | 129 | ||
166 | 130 | ||
167 | 131 | ||
168 | 132 | @Callable(i) | |
169 | - | func createProposal (title,text) = { | |
170 | - | let count = countProposals() | |
171 | - | [StringEntry(proposalTitleKey(count), title), StringEntry(proposalTextKey(count), text), IntegerEntry(proposalTimestampCreationKey(count), lastBlock.timestamp), IntegerEntry(countProposalsKey(), (count + 1))] | |
172 | - | } | |
173 | - | ||
174 | - | ||
175 | - | ||
176 | - | @Callable(i) | |
177 | - | func vote (id,vote) = if (isProposalAlive(id)) | |
178 | - | then { | |
179 | - | let unlockTime = max([(proposalTimestampCreation(id) + proposalTime), getUnlockTimestamp(i.caller.bytes)]) | |
180 | - | let u = match getBoolean(this, userProposalVoteKey(i.caller.bytes, id)) { | |
181 | - | case a: Boolean => | |
182 | - | if (a) | |
183 | - | then IntegerEntry(proposalCountVotesForKey(id), (countVotesFor(id) - countVotesUser(i.caller.bytes, id))) | |
184 | - | else IntegerEntry(proposalCountVotesAgainstKey(id), (countVotesFor(id) - countVotesUser(i.caller.bytes, id))) | |
185 | - | case _ => | |
186 | - | unit | |
133 | + | func vote (id,vote) = if (!(isProposalAlive(id))) | |
134 | + | then throw("proposalNotAlive") | |
135 | + | else { | |
136 | + | let proposal = getProposal(id) | |
137 | + | let unlockTime = max([(proposal._4 + proposalTime), getUnlockTimestamp(i.caller)]) | |
138 | + | let previusVote = getUserVote(id, i.caller) | |
139 | + | let votePower = userDepositedReputationAsset(i.caller) | |
140 | + | [setProposal(id, proposal._1, proposal._2, proposal._3, proposal._4, (proposal._5 - (if ((previusVote > 0)) | |
141 | + | then previusVote | |
142 | + | else (0 + (if (vote) | |
143 | + | then votePower | |
144 | + | else 0)))), (proposal._6 - (if ((0 > previusVote)) | |
145 | + | then previusVote | |
146 | + | else (0 + (if (vote) | |
147 | + | then 0 | |
148 | + | else votePower)))))] | |
187 | 149 | } | |
188 | - | if ((vote == true)) | |
189 | - | then [IntegerEntry(proposalCountVotesForKey(id), (countVotesFor(id) + balanceReputationAsset(i.caller.bytes))), IntegerEntry(unlockTimestampKey(i.caller.bytes), unlockTime), BooleanEntry(userProposalVoteKey(i.caller.bytes, id), vote), IntegerEntry(userProposalVotePowerKey(i.caller.bytes, id), balanceReputationAsset(i.caller.bytes))] | |
190 | - | else [IntegerEntry(proposalCountVotesAgainstKey(id), (countVotesAgainst(id) + balanceReputationAsset(i.caller.bytes))), IntegerEntry(unlockTimestampKey(i.caller.bytes), unlockTime), BooleanEntry(userProposalVoteKey(i.caller.bytes, id), vote), IntegerEntry(userProposalVotePowerKey(i.caller.bytes, id), balanceReputationAsset(i.caller.bytes))] | |
191 | - | } | |
192 | - | else throw("proposalNotAlive") | |
193 | 150 | ||
194 | 151 | ||
195 | 152 | @Verifier(tx) | |
196 | 153 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
197 | 154 |
github/deemru/w8io/169f3d6 45.18 ms ◑