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+DcpBVAG0dTZ5QIAuA7CaS8wuiEOK6KQOBSERbTgAMcHJvcG9zYWxUaW1lCQBoAgkAaAIJAGgCCQBoAgDoBwA8ADwAGAADARFjb3VudFByb3Bvc2Fsc0tleQACAmNwAQtwcm9wb3NhbEtleQEKcHJvcG9zYWxJZAkAuQkCCQDMCAICAXAJAMwIAgkApAMBBQpwcm9wb3NhbElkBQNuaWwFA1NFUAESdW5sb2NrVGltZXN0YW1wS2V5AQR1c2VyCQC5CQIJAMwIAgICdXQJAMwIAgkA2AQBCAUEdXNlcgVieXRlcwUDbmlsBQNTRVABEHVzZXJEZXBvc2l0ZWRLZXkBBHVzZXIJALkJAgkAzAgCAgJ1ZAkAzAgCCQDYBAEIBQR1c2VyBWJ5dGVzBQNuaWwFA1NFUAETdXNlclByb3Bvc2FsVm90ZUtleQIKcHJvcG9zYWxJZAR1c2VyCQC5CQIJAMwIAgICdXAJAMwIAgkApAMBBQpwcm9wb3NhbElkCQDMCAIJANgEAQgFBHVzZ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G9zYWxBbGl2ZQEFAmlkCQACAQIQcHJvcG9zYWxOb3RBbGl2ZQQIcHJvcG9zYWwJAQtnZXRQcm9wb3NhbAEFAmlkBAp1bmxvY2tUaW1lCQCWAwEJAMwIAgkAZAIIBQhwcm9wb3NhbAJfNAUMcHJvcG9zYWxUaW1lCQDMCAIJARJnZXRVbmxvY2tUaW1lc3RhbXABCAUBaQZjYWxsZXIFA25pbAQLcHJldml1c1ZvdGUJAQtnZXRVc2VyVm90ZQIFAmlkCAUBaQZjYWxsZXIECXZvdGVQb3dlcgkBHHVzZXJEZXBvc2l0ZWRSZXB1dGF0aW9uQXNzZXQBCAUBaQZjYWxsZXIJAMwIAgkBC3NldFByb3Bvc2FsBwUCaWQIBQhwcm9wb3NhbAJfMQgFCHByb3Bvc2FsAl8yCAUIcHJvcG9zYWwCXzMIBQhwcm9wb3NhbAJfNAkAZQIIBQhwcm9wb3NhbAJfNQMJAGYCBQtwcmV2aXVzVm90ZQAABQtwcmV2aXVzVm90ZQkAZAIAAAMFBHZvdGUFCXZvdGVQb3dlcgAACQBlAggFCHByb3Bvc2FsAl82AwkAZgIAAAULcHJldml1c1ZvdGUFC3ByZXZpdXNWb3RlCQBkAgAAAwUEdm90ZQAABQl2b3RlUG93ZXIFA25pbAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXnA+hks", "height": 2761030, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DnDqbQmvr2vAMYSyGzb6STzYwVk6hTd6FtobZxZy3FS5 Next: 3RSsrMipRS1JTc1qaA7zr383JRgs8LAirkghcVrY4Xwo Diff:
OldNewDifferences
77
88 let proposalTime = ((((1000 * 60) * 60) * 24) * 3)
99
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+}
1134
1235
1336 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))
2043 case _ =>
2144 throw("proposal not found")
2245 }, SEP)
23- $Tuple6(fromBase16String(savedString[0]), savedString[1], savedString[2], parseInt(savedString[3]), parseInt(savedString[4]), parseInt(savedString[5]))
46+ $Tuple6(addressFromStringValue(savedString[0]), savedString[1], savedString[2], parseIntValue(savedString[3]), parseIntValue(savedString[4]), parseIntValue(savedString[5]))
2447 }
2548
2649
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))
5551 then if ((i.payments[0].assetId == reputationAsset))
5652 then true
5753 else throw("only reputation assets")
5854 else throw("only 1 payment")
5955
6056
61-func getUnlockTimestamp (address) = match getInteger(this, unlockTimestampKey(address)) {
57+func getUnlockTimestamp (user) = match getInteger(this, unlockTimestampKey(user)) {
6258 case a: Int =>
6359 a
6460 case _ =>
7470 }
7571
7672
77-func countVotesFor (id) = match getInteger(this, proposalCountVotesForKey(id)) {
73+func userDepositedReputationAsset (user) = match getInteger(this, userDepositedKey(user)) {
7874 case a: Int =>
7975 a
8076 case _ =>
8278 }
8379
8480
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-
11781 func isProposalAlive (id) = if (if ((countProposals() > id))
118- then ((proposalTimestampCreation(id) + proposalTime) > lastBlock.timestamp)
82+ then ((getProposal(id)._4 + proposalTime) > lastBlock.timestamp)
11983 else false)
12084 then true
121- else throw("proposalNotAlive")
85+ else throw("proposal not alive")
12286
12387
12488 @Callable(i)
12589 func deposit () = {
126- let checks = [pmtReputationAsset(i)]
90+ let checks = [isPayReputationAsset(i)]
12791 if ((checks == checks))
12892 then {
12993 let currentKey = toBase58String(i.caller.bytes)
130- let currentAmount = balanceReputationAsset(i.caller.bytes)
94+ let currentAmount = userDepositedReputationAsset(i.caller)
13195 let newAmount = (currentAmount + i.payments[0].amount)
13296 [IntegerEntry(currentKey, newAmount)]
13397 }
148112 let newAmount = (currentAmount - amount)
149113 if ((0 > amount))
150114 then throw("Can't withdraw negative amount")
151- else if ((getUnlockTimestamp(i.caller.bytes) > lastBlock.timestamp))
115+ else if ((getUnlockTimestamp(i.caller) > lastBlock.timestamp))
152116 then throw("Locked")
153117 else if ((0 > newAmount))
154118 then throw("Not enough balance")
158122
159123
160124 @Callable(i)
161-func createProposalNew (title,text) = {
125+func createProposal (title,text) = {
162126 let count = countProposals()
163127 [setProposal(count, i.caller, toBase16String(title), toBase16String(text), lastBlock.timestamp, 0, 0)]
164128 }
166130
167131
168132 @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)))))]
187149 }
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")
193150
194151
195152 @Verifier(tx)
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let SEP = "__"
55
66 let reputationAsset = base58'88Tkdpqchhiqc9tNNG3SWQ2gfhZB4rBJKhMNS5Xmxhqw'
77
88 let proposalTime = ((((1000 * 60) * 60) * 24) * 3)
99
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+}
1134
1235
1336 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))
1437
1538
1639 func getProposal (id) = {
1740 let savedString = split( match getString(this, proposalKey(id)) {
1841 case s: String =>
1942 s
2043 case _ =>
2144 throw("proposal not found")
2245 }, SEP)
23- $Tuple6(fromBase16String(savedString[0]), savedString[1], savedString[2], parseInt(savedString[3]), parseInt(savedString[4]), parseInt(savedString[5]))
46+ $Tuple6(addressFromStringValue(savedString[0]), savedString[1], savedString[2], parseIntValue(savedString[3]), parseIntValue(savedString[4]), parseIntValue(savedString[5]))
2447 }
2548
2649
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))
5551 then if ((i.payments[0].assetId == reputationAsset))
5652 then true
5753 else throw("only reputation assets")
5854 else throw("only 1 payment")
5955
6056
61-func getUnlockTimestamp (address) = match getInteger(this, unlockTimestampKey(address)) {
57+func getUnlockTimestamp (user) = match getInteger(this, unlockTimestampKey(user)) {
6258 case a: Int =>
6359 a
6460 case _ =>
6561 0
6662 }
6763
6864
6965 func countProposals () = match getInteger(this, countProposalsKey()) {
7066 case a: Int =>
7167 a
7268 case _ =>
7369 0
7470 }
7571
7672
77-func countVotesFor (id) = match getInteger(this, proposalCountVotesForKey(id)) {
73+func userDepositedReputationAsset (user) = match getInteger(this, userDepositedKey(user)) {
7874 case a: Int =>
7975 a
8076 case _ =>
8177 0
8278 }
8379
8480
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-
11781 func isProposalAlive (id) = if (if ((countProposals() > id))
118- then ((proposalTimestampCreation(id) + proposalTime) > lastBlock.timestamp)
82+ then ((getProposal(id)._4 + proposalTime) > lastBlock.timestamp)
11983 else false)
12084 then true
121- else throw("proposalNotAlive")
85+ else throw("proposal not alive")
12286
12387
12488 @Callable(i)
12589 func deposit () = {
126- let checks = [pmtReputationAsset(i)]
90+ let checks = [isPayReputationAsset(i)]
12791 if ((checks == checks))
12892 then {
12993 let currentKey = toBase58String(i.caller.bytes)
130- let currentAmount = balanceReputationAsset(i.caller.bytes)
94+ let currentAmount = userDepositedReputationAsset(i.caller)
13195 let newAmount = (currentAmount + i.payments[0].amount)
13296 [IntegerEntry(currentKey, newAmount)]
13397 }
13498 else throw("onlyReputationAsset")
13599 }
136100
137101
138102
139103 @Callable(i)
140104 func withdraw (amount) = {
141105 let currentKey = toBase58String(i.caller.bytes)
142106 let currentAmount = match getInteger(this, currentKey) {
143107 case a: Int =>
144108 a
145109 case _ =>
146110 0
147111 }
148112 let newAmount = (currentAmount - amount)
149113 if ((0 > amount))
150114 then throw("Can't withdraw negative amount")
151- else if ((getUnlockTimestamp(i.caller.bytes) > lastBlock.timestamp))
115+ else if ((getUnlockTimestamp(i.caller) > lastBlock.timestamp))
152116 then throw("Locked")
153117 else if ((0 > newAmount))
154118 then throw("Not enough balance")
155119 else [IntegerEntry(currentKey, newAmount), ScriptTransfer(i.caller, amount, reputationAsset)]
156120 }
157121
158122
159123
160124 @Callable(i)
161-func createProposalNew (title,text) = {
125+func createProposal (title,text) = {
162126 let count = countProposals()
163127 [setProposal(count, i.caller, toBase16String(title), toBase16String(text), lastBlock.timestamp, 0, 0)]
164128 }
165129
166130
167131
168132 @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)))))]
187149 }
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")
193150
194151
195152 @Verifier(tx)
196153 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
197154

github/deemru/w8io/6500d08 
68.79 ms