tx · 6q8kjtgE3kPQrYV1aU1EDta44aXe8e9k3vLrRkrq97bo 3MuKEDU6qPggcs65swNH6JcUbS7hB6jVzrA: -0.01000000 Waves 2023.09.20 18:20 [2763885] smart account 3MuKEDU6qPggcs65swNH6JcUbS7hB6jVzrA > SELF 0.00000000 Waves
{ "type": 13, "id": "6q8kjtgE3kPQrYV1aU1EDta44aXe8e9k3vLrRkrq97bo", "fee": 1000000, "feeAssetId": null, "timestamp": 1695223278801, "version": 2, "chainId": 84, "sender": "3MuKEDU6qPggcs65swNH6JcUbS7hB6jVzrA", "senderPublicKey": "GkZtgtQPEtE9JoxK1tzKc1t7uw12vz6aqKhDcBi136yV", "proofs": [ "wNFB4wqJx7dpc3yhBc8vf1eLrjFS19pdN948pP5fPW2QThFzHSNUrauP6H87WbQXdAi7ZjDXfAXZrrj4zkfXYeX" ], "script": "base64:BgIVCAISABIDCgEBEgQKAgICEgQKAgEEEQADU0VQAgJfXwAPcmVwdXRhdGlvbkFzc2V0ASBxggycON8pyCFInplKujKGtzqQhMOf+vAbfdt6zmK1aAAMcHJvcG9zYWxUaW1lCQBoAgkAaAIJAGgCCQBoAgDoBwA8ADwAGAADARFjb3VudFByb3Bvc2Fsc0tleQACAmNwAQtwcm9wb3NhbEtleQEKcHJvcG9zYWxJZAkAuQkCCQDMCAICAXAJAMwIAgkApAMBBQpwcm9wb3NhbElkBQNuaWwFA1NFUAEYZ3JlYXRlc3RWb3RlVGltZXN0YW1wS2V5AQR1c2VyCQC5CQIJAMwIAgICdXQJAMwIAgkA2AQBCAUEdXNlcgVieXRlcwUDbmlsBQNTRVABEHVzZXJEZXBvc2l0ZWRLZXkBBHVzZXIJALkJAgkAzAgCAgJ1ZAkAzAgCCQDYBAEIBQR1c2VyBWJ5dGVzBQNuaWwFA1NFUAETdXNlclByb3Bvc2FsVm90ZUtleQIKcHJvcG9zYWxJZAR1c2VyCQC5CQIJAMwIAgICdXAJAMwIAgkApAMBBQpwcm9wb3NhbElkCQDMCAIJAN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3dlcgUDbmlsAQJ0eAEGdmVyaWZ5AAkA9AMDCAUCdHgJYm9keUJ5dGVzCQCRAwIIBQJ0eAZwcm9vZnMAAAgFAnR4D3NlbmRlclB1YmxpY0tleTCMSYY=", "height": 2763885, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 4pjT18sgChf2DJkc191M5De7FN2JCyC39avJ3EJUUyPg Next: GLkqH8ReVo1iGXiQzm3fGHzWyuCeMSDzARnsiZgVGKpb Diff:
Old | New | Differences | |
---|---|---|---|
13 | 13 | func proposalKey (proposalId) = makeString(["p", toString(proposalId)], SEP) | |
14 | 14 | ||
15 | 15 | ||
16 | - | func | |
16 | + | func greatestVoteTimestampKey (user) = makeString(["ut", toBase58String(user.bytes)], SEP) | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func userDepositedKey (user) = makeString(["ud", toBase58String(user.bytes)], SEP) | |
54 | 54 | else throw("only 1 payment") | |
55 | 55 | ||
56 | 56 | ||
57 | - | func getUnlockTimestamp (user) = match getInteger(this, | |
57 | + | func getUnlockTimestamp (user) = match getInteger(this, greatestVoteTimestampKey(user)) { | |
58 | 58 | case a: Int => | |
59 | - | a | |
59 | + | (a + proposalTime) | |
60 | 60 | case _ => | |
61 | 61 | 0 | |
62 | 62 | } | |
111 | 111 | let newAmount = (currentAmount - amount) | |
112 | 112 | if ((0 > amount)) | |
113 | 113 | then throw("Can't withdraw negative amount") | |
114 | - | else if ((getUnlockTimestamp(i.caller) | |
114 | + | else if ((lastBlock.timestamp > getUnlockTimestamp(i.caller))) | |
115 | 115 | then throw("Locked") | |
116 | 116 | else if ((0 > newAmount)) | |
117 | 117 | then throw("Not enough balance") |
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'8e65zYSAcGfmQnVX462UEMWf6PmHgtckyGcrEMXKZZaF' | |
7 | 7 | ||
8 | 8 | let proposalTime = ((((1000 * 60) * 60) * 24) * 3) | |
9 | 9 | ||
10 | 10 | func countProposalsKey () = "cp" | |
11 | 11 | ||
12 | 12 | ||
13 | 13 | func proposalKey (proposalId) = makeString(["p", toString(proposalId)], SEP) | |
14 | 14 | ||
15 | 15 | ||
16 | - | func | |
16 | + | func greatestVoteTimestampKey (user) = makeString(["ut", toBase58String(user.bytes)], SEP) | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | func userDepositedKey (user) = makeString(["ud", toBase58String(user.bytes)], SEP) | |
20 | 20 | ||
21 | 21 | ||
22 | 22 | func userProposalVoteKey (proposalId,user) = makeString(["up", toString(proposalId), toBase58String(user.bytes)], SEP) | |
23 | 23 | ||
24 | 24 | ||
25 | 25 | func setUserVote (proposalId,user,votePower) = IntegerEntry(userProposalVoteKey(proposalId, user), votePower) | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getUserVote (proposalId,user) = match getInteger(userProposalVoteKey(proposalId, user)) { | |
29 | 29 | case i: Int => | |
30 | 30 | i | |
31 | 31 | case _ => | |
32 | 32 | 0 | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 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)) | |
37 | 37 | ||
38 | 38 | ||
39 | 39 | func getProposal (id) = { | |
40 | 40 | let savedString = split( match getString(this, proposalKey(id)) { | |
41 | 41 | case s: String => | |
42 | 42 | s | |
43 | 43 | case _ => | |
44 | 44 | throw("proposal not found") | |
45 | 45 | }, SEP) | |
46 | 46 | $Tuple6(Address(fromBase16String(savedString[0])), savedString[1], savedString[2], parseIntValue(savedString[3]), parseIntValue(savedString[4]), parseIntValue(savedString[5])) | |
47 | 47 | } | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | func isPayReputationAsset (i) = if ((size(i.payments) == 1)) | |
51 | 51 | then if ((i.payments[0].assetId == reputationAsset)) | |
52 | 52 | then true | |
53 | 53 | else throw("only reputation assets") | |
54 | 54 | else throw("only 1 payment") | |
55 | 55 | ||
56 | 56 | ||
57 | - | func getUnlockTimestamp (user) = match getInteger(this, | |
57 | + | func getUnlockTimestamp (user) = match getInteger(this, greatestVoteTimestampKey(user)) { | |
58 | 58 | case a: Int => | |
59 | - | a | |
59 | + | (a + proposalTime) | |
60 | 60 | case _ => | |
61 | 61 | 0 | |
62 | 62 | } | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func countProposals () = match getInteger(this, countProposalsKey()) { | |
66 | 66 | case a: Int => | |
67 | 67 | a | |
68 | 68 | case _ => | |
69 | 69 | 0 | |
70 | 70 | } | |
71 | 71 | ||
72 | 72 | ||
73 | 73 | func userDepositedReputationAsset (user) = match getInteger(this, userDepositedKey(user)) { | |
74 | 74 | case a: Int => | |
75 | 75 | a | |
76 | 76 | case _ => | |
77 | 77 | 0 | |
78 | 78 | } | |
79 | 79 | ||
80 | 80 | ||
81 | 81 | func isProposalAlive (id) = if (if ((countProposals() > id)) | |
82 | 82 | then ((getProposal(id)._4 + proposalTime) > lastBlock.timestamp) | |
83 | 83 | else false) | |
84 | 84 | then true | |
85 | 85 | else throw("proposal not alive") | |
86 | 86 | ||
87 | 87 | ||
88 | 88 | @Callable(i) | |
89 | 89 | func deposit () = { | |
90 | 90 | let checks = [isPayReputationAsset(i)] | |
91 | 91 | if ((checks == checks)) | |
92 | 92 | then { | |
93 | 93 | let currentAmount = userDepositedReputationAsset(i.caller) | |
94 | 94 | let newAmount = (currentAmount + i.payments[0].amount) | |
95 | 95 | [IntegerEntry(userDepositedKey(i.caller), newAmount)] | |
96 | 96 | } | |
97 | 97 | else throw("onlyReputationAsset") | |
98 | 98 | } | |
99 | 99 | ||
100 | 100 | ||
101 | 101 | ||
102 | 102 | @Callable(i) | |
103 | 103 | func withdraw (amount) = { | |
104 | 104 | let currentKey = toBase58String(i.caller.bytes) | |
105 | 105 | let currentAmount = match getInteger(this, currentKey) { | |
106 | 106 | case a: Int => | |
107 | 107 | a | |
108 | 108 | case _ => | |
109 | 109 | 0 | |
110 | 110 | } | |
111 | 111 | let newAmount = (currentAmount - amount) | |
112 | 112 | if ((0 > amount)) | |
113 | 113 | then throw("Can't withdraw negative amount") | |
114 | - | else if ((getUnlockTimestamp(i.caller) | |
114 | + | else if ((lastBlock.timestamp > getUnlockTimestamp(i.caller))) | |
115 | 115 | then throw("Locked") | |
116 | 116 | else if ((0 > newAmount)) | |
117 | 117 | then throw("Not enough balance") | |
118 | 118 | else [IntegerEntry(currentKey, newAmount), ScriptTransfer(i.caller, amount, reputationAsset)] | |
119 | 119 | } | |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | 123 | @Callable(i) | |
124 | 124 | func createProposal (title,text) = { | |
125 | 125 | let count = countProposals() | |
126 | 126 | [setProposal(count, i.caller, toBase16String(title), toBase16String(text), lastBlock.timestamp, 0, 0), IntegerEntry(countProposalsKey(), (count + 1))] | |
127 | 127 | } | |
128 | 128 | ||
129 | 129 | ||
130 | 130 | ||
131 | 131 | @Callable(i) | |
132 | 132 | func vote (proposalId,vote) = if (!(isProposalAlive(proposalId))) | |
133 | 133 | then throw("proposalNotAlive") | |
134 | 134 | else { | |
135 | 135 | let proposal = getProposal(proposalId) | |
136 | 136 | let unlockTime = max([(proposal._4 + proposalTime), getUnlockTimestamp(i.caller)]) | |
137 | 137 | let previusVote = getUserVote(proposalId, i.caller) | |
138 | 138 | let votePower = userDepositedReputationAsset(i.caller) | |
139 | 139 | let minusFor = if ((previusVote > 0)) | |
140 | 140 | then previusVote | |
141 | 141 | else 0 | |
142 | 142 | let minusAgainst = if ((0 > previusVote)) | |
143 | 143 | then -(previusVote) | |
144 | 144 | else 0 | |
145 | 145 | let plusFor = if ((vote == true)) | |
146 | 146 | then votePower | |
147 | 147 | else 0 | |
148 | 148 | let plusAgainst = if ((vote == false)) | |
149 | 149 | then votePower | |
150 | 150 | else 0 | |
151 | 151 | [setProposal(proposalId, proposal._1, proposal._2, proposal._3, proposal._4, ((proposal._5 - minusFor) + plusFor), ((proposal._6 - minusAgainst) + plusAgainst)), setUserVote(proposalId, i.caller, if (vote) | |
152 | 152 | then votePower | |
153 | 153 | else -(votePower))] | |
154 | 154 | } | |
155 | 155 | ||
156 | 156 | ||
157 | 157 | @Verifier(tx) | |
158 | 158 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
159 | 159 |
github/deemru/w8io/fabc49c 31.57 ms ◑