tx · 4ryAmjCzkm8j48gKaaV8rc5Y74exWeoaxfivozkXNV6j 3N7oHnMaDFKYTEgumQs9mjRESDco6KhQiXW: -0.14000000 Waves 2023.05.09 15:36 [2570354] smart account 3N7oHnMaDFKYTEgumQs9mjRESDco6KhQiXW > SELF 0.00000000 Waves
{ "type": 13, "id": "4ryAmjCzkm8j48gKaaV8rc5Y74exWeoaxfivozkXNV6j", "fee": 14000000, "feeAssetId": null, "timestamp": 1683635827142, "version": 2, "chainId": 84, "sender": "3N7oHnMaDFKYTEgumQs9mjRESDco6KhQiXW", "senderPublicKey": "2M6xzJiyT4ZPQhyMEQoo9GUqBsKBtgTD1BaZ8L4PfPVj", "proofs": [ "5hjXoNmyQtQTrdESot5UyuzJFwjytR1uszSXCyeB3xrTxfRfqdacPzZ62CWgW84DPbjrdxcHaNZgAZNTrWqKgtDs", "25xqStVwxreUxTqw3y4BRHtuKaXXomrgEndNah7robpHpSuuREAKsK8y54Ejb9e9Yrwkwt73vNv88Ka9UFfMdeYi" ], "script": "base64:AAIFAAAAAAAAABIIAhIHCgUBAQEICBIDCgEEEgAAAAAYAAAAAAxhZG1pblB1YktleTEBAAAAIBQCDFCxss6zrB0AAB1lFGH++bkS6T79aRXaqXigSMwKAAAAAAxhZG1pblB1YktleTIBAAAAIBQCDFCxss6zrB0AAB1lFGH++bkS6T79aRXaqXigSMwKAAAAAAxhZG1pblB1YktleTMBAAAAIBQCDFCxss6zrB0AAB1lFGH++bkS6T79aRXaqXigSMwKAAAAABRhZG1pblB1YktleVN0YXJ0U3RvcAEAAAAgFAIMULGyzrOsHQAAHWUUYf75uRLpPv1pFdqpeKBIzAoAAAAACWtleUFjdGl2ZQIAAAAGYWN0aXZlAAAAAAhrZXlDYXVzZQIAAAAOc2h1dGRvd25fY2F1c2UAAAAAEWtleVVzZXJWT1RFQW1vdW50AgAAAAxfVk9URV9hbW91bnQAAAAAC2tleVVzZXJWT1RFAgAAAAVfVk9URQAAAAAMa2V5VG90YWxWT1RFAg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mFkbWluUHViS2V5M1NpZ25lZAAAAAAAAAAAAsj7BCY=", "height": 2570354, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Bf9DMGwZUbrHSHgXu7EMaormBccEpGgtwivYXnZRd8b2 Next: 4kJ9i2Zvoy2CmSwJepBjZKPMSjNkn9wrxUBgUVf9ZGUT Diff:
Old | New | Differences | |
---|---|---|---|
66 | 66 | @Callable(i) | |
67 | 67 | func vote (vote) = if (!(isActive)) | |
68 | 68 | then throw("DApp is inactive at this moment") | |
69 | - | else if ((getVal(keyVoteStart) > height)) | |
70 | - | then throw("Voting has not started yet.") | |
71 | - | else if ((height > getVal(keyVoteEnd))) | |
72 | - | then throw("Voting has already ended.") | |
73 | - | else { | |
74 | - | let totalYes = getVal((keyVoteNumber + keyVoteYes)) | |
75 | - | let totalNo = getVal((keyVoteNumber + keyVoteNo)) | |
76 | - | let userVoteAmount = getUserVoteAmount(i.caller) | |
77 | - | let userVote = getUserVote(i.caller) | |
78 | - | let userENNOLocked = getUserENNOLocked(i.caller) | |
79 | - | let userENNOVotedNew = userENNOLocked | |
80 | - | if ((0 > userENNOVotedNew)) | |
81 | - | then throw("Vote must be more than 0") | |
82 | - | else { | |
83 | - | let newTotalYesVoted = (totalYes + (if ((vote == userVote)) | |
84 | - | then if (vote) | |
85 | - | then userENNOLocked | |
86 | - | else 0 | |
87 | - | else (-1 * userENNOLocked))) | |
88 | - | let newTotalNoVoted = (totalNo + (if ((userVote == vote)) | |
89 | - | then if (!(vote)) | |
90 | - | then userENNOLocked | |
91 | - | else 0 | |
92 | - | else (-1 * userENNOLocked))) | |
69 | + | else { | |
70 | + | let session = toString(getVal(keyVoteNumber)) | |
71 | + | if ((getVal(((keyVoteStart + "_") + session)) > height)) | |
72 | + | then throw("Voting has not started yet.") | |
73 | + | else if ((height > getVal(((keyVoteEnd + "_") + session)))) | |
74 | + | then throw("Voting has already ended.") | |
75 | + | else { | |
76 | + | let totalYes = getVal((keyVoteNumber + keyVoteYes)) | |
77 | + | let totalNo = getVal((keyVoteNumber + keyVoteNo)) | |
78 | + | let userVoteAmount = getUserVoteAmount(i.caller) | |
79 | + | let userVote = getUserVote(i.caller) | |
80 | + | let userENNOLocked = getUserENNOLocked(i.caller) | |
81 | + | let userENNOVotedNew = userENNOLocked | |
82 | + | if ((0 > userENNOVotedNew)) | |
83 | + | then throw("Vote must be more than 0") | |
84 | + | else { | |
85 | + | let newTotalYesVoted = (totalYes + (if ((vote == userVote)) | |
86 | + | then if (vote) | |
87 | + | then userENNOLocked | |
88 | + | else 0 | |
89 | + | else (-1 * userENNOLocked))) | |
90 | + | let newTotalNoVoted = (totalNo + (if ((userVote == vote)) | |
91 | + | then if (!(vote)) | |
92 | + | then userENNOLocked | |
93 | + | else 0 | |
94 | + | else (-1 * userENNOLocked))) | |
93 | 95 | [IntegerEntry((((toString(i.caller) + keyUserVOTEAmount) + "_") + keyVoteNumber), userENNOLocked), BooleanEntry((((toString(i.caller) + keyUserVOTE) + "_") + keyVoteNumber), vote), IntegerEntry((keyVoteNumber + keyVoteYes), newTotalYesVoted), IntegerEntry((keyVoteNumber + keyVoteNo), newTotalNoVoted), IntegerEntry((keyVoteNumber + keyTotalVOTE), (newTotalNoVoted + newTotalYesVoted))] | |
94 | - | } | |
95 | - | } | |
96 | + | } | |
97 | + | } | |
98 | + | } | |
96 | 99 | ||
97 | 100 | ||
98 | 101 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let adminPubKey1 = base58'2M6xzJiyT4ZPQhyMEQoo9GUqBsKBtgTD1BaZ8L4PfPVj' | |
5 | 5 | ||
6 | 6 | let adminPubKey2 = base58'2M6xzJiyT4ZPQhyMEQoo9GUqBsKBtgTD1BaZ8L4PfPVj' | |
7 | 7 | ||
8 | 8 | let adminPubKey3 = base58'2M6xzJiyT4ZPQhyMEQoo9GUqBsKBtgTD1BaZ8L4PfPVj' | |
9 | 9 | ||
10 | 10 | let adminPubKeyStartStop = base58'2M6xzJiyT4ZPQhyMEQoo9GUqBsKBtgTD1BaZ8L4PfPVj' | |
11 | 11 | ||
12 | 12 | let keyActive = "active" | |
13 | 13 | ||
14 | 14 | let keyCause = "shutdown_cause" | |
15 | 15 | ||
16 | 16 | let keyUserVOTEAmount = "_VOTE_amount" | |
17 | 17 | ||
18 | 18 | let keyUserVOTE = "_VOTE" | |
19 | 19 | ||
20 | 20 | let keyTotalVOTE = "_total_VOTE_amount" | |
21 | 21 | ||
22 | 22 | let keyVoteNumber = "vote_session" | |
23 | 23 | ||
24 | 24 | let keyVoteStart = "vote_start_height" | |
25 | 25 | ||
26 | 26 | let keyVoteEnd = "vote_end_height" | |
27 | 27 | ||
28 | 28 | let keyVoteYes = "_yes_amount" | |
29 | 29 | ||
30 | 30 | let keyVoteNo = "_no_amount" | |
31 | 31 | ||
32 | 32 | let keyUserENNOLocked = "_ENNO_amount" | |
33 | 33 | ||
34 | 34 | let keyVoteName = "vote_name" | |
35 | 35 | ||
36 | 36 | let keyVoteDescription = "vote_description" | |
37 | 37 | ||
38 | 38 | let isActive = valueOrElse(getBoolean(this, keyActive), true) | |
39 | 39 | ||
40 | 40 | let stakeData = addressFromPublicKey(base58'Ese6jz6mtrhgwJWdXbAxHNHg2qzae5D2xXWuVF7tLfs8') | |
41 | 41 | ||
42 | 42 | func getUserENNOLocked (user) = valueOrElse(getInteger(stakeData, (toString(user) + keyUserENNOLocked)), 0) | |
43 | 43 | ||
44 | 44 | ||
45 | 45 | func getUserVoteAmount (user) = valueOrElse(getInteger(this, (toString(user) + keyUserVOTEAmount)), 0) | |
46 | 46 | ||
47 | 47 | ||
48 | 48 | func getUserVote (user) = valueOrElse(getBoolean(this, (toString(user) + keyUserVOTE)), false) | |
49 | 49 | ||
50 | 50 | ||
51 | 51 | func getVal (key) = valueOrElse(getInteger(this, key), 0) | |
52 | 52 | ||
53 | 53 | ||
54 | 54 | func suspend (cause) = [BooleanEntry(keyActive, false), StringEntry(keyCause, cause)] | |
55 | 55 | ||
56 | 56 | ||
57 | 57 | @Callable(i) | |
58 | 58 | func initVote (session,start,end,voteName,voteDescription) = if (!(isActive)) | |
59 | 59 | then throw("DApp is inactive at this moment") | |
60 | 60 | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
61 | 61 | then throw("Only admin can call this function") | |
62 | 62 | else [IntegerEntry(keyVoteNumber, session), IntegerEntry(((keyVoteStart + "_") + toString(session)), start), IntegerEntry(((keyVoteEnd + "_") + toString(session)), end), IntegerEntry((toString(session) + keyVoteYes), 0), IntegerEntry((toString(session) + keyVoteNo), 0), StringEntry(((keyVoteName + "_") + toString(session)), voteName), StringEntry(((keyVoteDescription + "_") + toString(session)), voteDescription)] | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | ||
66 | 66 | @Callable(i) | |
67 | 67 | func vote (vote) = if (!(isActive)) | |
68 | 68 | then throw("DApp is inactive at this moment") | |
69 | - | else if ((getVal(keyVoteStart) > height)) | |
70 | - | then throw("Voting has not started yet.") | |
71 | - | else if ((height > getVal(keyVoteEnd))) | |
72 | - | then throw("Voting has already ended.") | |
73 | - | else { | |
74 | - | let totalYes = getVal((keyVoteNumber + keyVoteYes)) | |
75 | - | let totalNo = getVal((keyVoteNumber + keyVoteNo)) | |
76 | - | let userVoteAmount = getUserVoteAmount(i.caller) | |
77 | - | let userVote = getUserVote(i.caller) | |
78 | - | let userENNOLocked = getUserENNOLocked(i.caller) | |
79 | - | let userENNOVotedNew = userENNOLocked | |
80 | - | if ((0 > userENNOVotedNew)) | |
81 | - | then throw("Vote must be more than 0") | |
82 | - | else { | |
83 | - | let newTotalYesVoted = (totalYes + (if ((vote == userVote)) | |
84 | - | then if (vote) | |
85 | - | then userENNOLocked | |
86 | - | else 0 | |
87 | - | else (-1 * userENNOLocked))) | |
88 | - | let newTotalNoVoted = (totalNo + (if ((userVote == vote)) | |
89 | - | then if (!(vote)) | |
90 | - | then userENNOLocked | |
91 | - | else 0 | |
92 | - | else (-1 * userENNOLocked))) | |
69 | + | else { | |
70 | + | let session = toString(getVal(keyVoteNumber)) | |
71 | + | if ((getVal(((keyVoteStart + "_") + session)) > height)) | |
72 | + | then throw("Voting has not started yet.") | |
73 | + | else if ((height > getVal(((keyVoteEnd + "_") + session)))) | |
74 | + | then throw("Voting has already ended.") | |
75 | + | else { | |
76 | + | let totalYes = getVal((keyVoteNumber + keyVoteYes)) | |
77 | + | let totalNo = getVal((keyVoteNumber + keyVoteNo)) | |
78 | + | let userVoteAmount = getUserVoteAmount(i.caller) | |
79 | + | let userVote = getUserVote(i.caller) | |
80 | + | let userENNOLocked = getUserENNOLocked(i.caller) | |
81 | + | let userENNOVotedNew = userENNOLocked | |
82 | + | if ((0 > userENNOVotedNew)) | |
83 | + | then throw("Vote must be more than 0") | |
84 | + | else { | |
85 | + | let newTotalYesVoted = (totalYes + (if ((vote == userVote)) | |
86 | + | then if (vote) | |
87 | + | then userENNOLocked | |
88 | + | else 0 | |
89 | + | else (-1 * userENNOLocked))) | |
90 | + | let newTotalNoVoted = (totalNo + (if ((userVote == vote)) | |
91 | + | then if (!(vote)) | |
92 | + | then userENNOLocked | |
93 | + | else 0 | |
94 | + | else (-1 * userENNOLocked))) | |
93 | 95 | [IntegerEntry((((toString(i.caller) + keyUserVOTEAmount) + "_") + keyVoteNumber), userENNOLocked), BooleanEntry((((toString(i.caller) + keyUserVOTE) + "_") + keyVoteNumber), vote), IntegerEntry((keyVoteNumber + keyVoteYes), newTotalYesVoted), IntegerEntry((keyVoteNumber + keyVoteNo), newTotalNoVoted), IntegerEntry((keyVoteNumber + keyTotalVOTE), (newTotalNoVoted + newTotalYesVoted))] | |
94 | - | } | |
95 | - | } | |
96 | + | } | |
97 | + | } | |
98 | + | } | |
96 | 99 | ||
97 | 100 | ||
98 | 101 | ||
99 | 102 | @Callable(i) | |
100 | 103 | func shutdown () = if (!(isActive)) | |
101 | 104 | then throw(("DApp is already suspended. Cause: " + valueOrElse(getString(this, keyCause), "the cause wasn't specified"))) | |
102 | 105 | else if (!(containsElement([adminPubKey1, adminPubKey2, adminPubKey3, adminPubKeyStartStop], i.callerPublicKey))) | |
103 | 106 | then throw("Only admin can call this function") | |
104 | 107 | else suspend("Paused by admin") | |
105 | 108 | ||
106 | 109 | ||
107 | 110 | @Verifier(tx) | |
108 | 111 | func verify () = match tx { | |
109 | 112 | case d: DataTransaction => | |
110 | 113 | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
111 | 114 | case _ => | |
112 | 115 | let adminPubKey1Signed = if (sigVerify(tx.bodyBytes, tx.proofs[0], adminPubKey1)) | |
113 | 116 | then 1 | |
114 | 117 | else 0 | |
115 | 118 | let adminPubKey2Signed = if (sigVerify(tx.bodyBytes, tx.proofs[1], adminPubKey2)) | |
116 | 119 | then 1 | |
117 | 120 | else 0 | |
118 | 121 | let adminPubKey3Signed = if (sigVerify(tx.bodyBytes, tx.proofs[2], adminPubKey3)) | |
119 | 122 | then 1 | |
120 | 123 | else 0 | |
121 | 124 | (((adminPubKey1Signed + adminPubKey2Signed) + adminPubKey3Signed) >= 2) | |
122 | 125 | } | |
123 | 126 |
github/deemru/w8io/169f3d6 32.57 ms ◑