tx · Eu4ZUxXSzux8gxzQ5NgSd9Q2fsroLQcUNT2UPQ8QUbG4 3N5rNyYSAsaP9QL2eQq286RhevB8msHFffu: -0.01400000 Waves 2020.09.11 16:53 [1172735] smart account 3N5rNyYSAsaP9QL2eQq286RhevB8msHFffu > SELF 0.00000000 Waves
{ "type": 13, "id": "Eu4ZUxXSzux8gxzQ5NgSd9Q2fsroLQcUNT2UPQ8QUbG4", "fee": 1400000, "feeAssetId": null, "timestamp": 1599832459417, "version": 2, "chainId": 84, "sender": "3N5rNyYSAsaP9QL2eQq286RhevB8msHFffu", "senderPublicKey": "CBTEuFN6ku1LNaPuGHHTMh2CBb3kPa5D73XXTJvKydun", "proofs": [ "3qrpxDVqq4iXZHBsxfG89Rk4zx3VtCD3HuMec134K8Eu3Ba8hysX39pKJU3jAF8DQ7orJbSXy2NLhe8GFxwLXpaF" ], "script": "base64:AAIDAAAAAAAAACAIARIHCgUICAgICBIECgIICBIDCgEIEgMKAQgSAwoBCAAAAA0AAAAABnVwVm90ZQIAAAAGdXB2b3RlAAAAAAxhZG1pbkFkZHJlc3MBAAAAGgFUOLYhWIA2WAg9IJQBVCmgZJeEnZPD9jSLAAAAAAVkeXpJZAEAAAAgfqtB2c5SyrdhjTSeT2NUMvY45D97zjqBcAiarzFPFmsBAAAADWdldFByb2ZpbGVLZXkAAAABAAAAAmlkCQABLAAAAAIFAAAAAmlkAgAAABRfZW50cmVwcmVuZXVyUHJvZmlsZQEAAAAMZ2V0U3RhdHVzS2V5AAAAAQAAAAJpZAkAASwAAAACBQAAAAJpZAIAAAAHX3N0YXR1cwEAAAARZ2V0Vm90ZXJBbW91bnRLZXkAAAACAAAAAmlkAAAABnZvdGVJZAkAASwAAAACCQABLAAAAAIJAAEsAAAAAgUAAAACaWQCAAAAAV8FAAAABnZvdGVJZAIAAAAHX2Ftb3VudAEAAAAKZ2V0Vm90ZUtleQAAAAIAAAACaWQAAAAEdHlwZQMJAAAAAAAAAgUAAAAEdHlwZQIAAAAGd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IFAAAADWN1cnJlbnRBbW91bnQFAAAABWR5eklkBQAAAANuaWwJAAACAAAAAQIAAAA2Q2FuJ3Qgd2l0aGRyYXcgdm90ZSBhbW91bnQgd2hpbGUgdm90aW5nIGlzIHN0aWxsIG9wZW4uCQAAAgAAAAECAAAAJVlvdSBkaWRuJ3Qgdm90ZSBmb3IgdGhpcyBlbnRyZXByZW5ldXIAAAAAcCdywA==", "height": 1172735, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6fefZLiPHpWLS8x1Q8epL6WFoW7Bv1DKzBf8E7zJZTyv Next: C7WcVVowR6tq4aiRVXHGkRjuMDfbqf8DoEQtW6iPDXLF Diff:
Old | New | Differences | |
---|---|---|---|
11 | 11 | ||
12 | 12 | ||
13 | 13 | func getStatusKey (id) = (id + "_status") | |
14 | + | ||
15 | + | ||
16 | + | func getVoterAmountKey (id,voteId) = (((id + "_") + voteId) + "_amount") | |
14 | 17 | ||
15 | 18 | ||
16 | 19 | func getVoteKey (id,type) = if ((type == "upvote")) | |
74 | 77 | @Callable(i) | |
75 | 78 | func vote (voteId,vote) = { | |
76 | 79 | let pmt = extract(i.payment) | |
80 | + | let voter = toBase58String(i.caller.bytes) | |
77 | 81 | if ((pmt.amount == 0)) | |
78 | 82 | then throw("You cannot vote without paying voting fee") | |
79 | 83 | else if ((pmt.assetId != base58'9XTqBQeJvdMs8VNHv6rXiJLJichg2acG7wCfYcTajQ1G')) | |
80 | 84 | then throw("You can only vote with DYZRUPT token") | |
81 | - | else if (canVote( | |
85 | + | else if (canVote(voter, voteId)) | |
82 | 86 | then if (profileExist(voteId)) | |
83 | 87 | then if ((getVoteStatus(voteId) == "open")) | |
84 | 88 | then if ((vote == upVote)) | |
85 | 89 | then { | |
86 | 90 | let voteCount = getVoteCount(voteId, vote) | |
87 | 91 | let newVoteCount = (voteCount + 1) | |
88 | - | ScriptResult(WriteSet([DataEntry(getVoteKey(voteId, vote), newVoteCount), DataEntry(getVoterKey( | |
92 | + | ScriptResult(WriteSet([DataEntry(getVoteKey(voteId, vote), newVoteCount), DataEntry(getVoterKey(voter, voteId), voteId), DataEntry(getVoterAmountKey(voter, voteId), pmt.amount)]), TransferSet([ScriptTransfer(this, pmt.amount, dyzId)])) | |
89 | 93 | } | |
90 | 94 | else throw("Not a valid vote value") | |
91 | 95 | else throw("This profile is not open for voting") | |
112 | 116 | else throw("Invalid ID") | |
113 | 117 | ||
114 | 118 | ||
119 | + | ||
120 | + | @Callable(i) | |
121 | + | func withdraw (voteId) = { | |
122 | + | let voter = toBase58String(i.caller.bytes) | |
123 | + | if ((getVoter(voter, voteId) != "")) | |
124 | + | then if ((getVoteStatus(voteId) == "closed")) | |
125 | + | then { | |
126 | + | let currentKey = getVoterAmountKey(voter, voteId) | |
127 | + | let currentAmount = match getInteger(this, currentKey) { | |
128 | + | case a: Int => | |
129 | + | a | |
130 | + | case _ => | |
131 | + | throw("You didn't vote for this entrepreneur") | |
132 | + | } | |
133 | + | if ((currentAmount == 0)) | |
134 | + | then throw("Seems you have previously withdrawn.") | |
135 | + | else ScriptResult(WriteSet([DataEntry(currentKey, 0)]), TransferSet([ScriptTransfer(i.caller, currentAmount, dyzId)])) | |
136 | + | } | |
137 | + | else throw("Can't withdraw vote amount while voting is still open.") | |
138 | + | else throw("You didn't vote for this entrepreneur") | |
139 | + | } | |
140 | + | ||
141 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let upVote = "upvote" | |
5 | 5 | ||
6 | 6 | let adminAddress = base58'3Mu5woJ54s7vHJgaeNcJ4C9ByfdmMF2jpjC' | |
7 | 7 | ||
8 | 8 | let dyzId = base58'9XTqBQeJvdMs8VNHv6rXiJLJichg2acG7wCfYcTajQ1G' | |
9 | 9 | ||
10 | 10 | func getProfileKey (id) = (id + "_entrepreneurProfile") | |
11 | 11 | ||
12 | 12 | ||
13 | 13 | func getStatusKey (id) = (id + "_status") | |
14 | + | ||
15 | + | ||
16 | + | func getVoterAmountKey (id,voteId) = (((id + "_") + voteId) + "_amount") | |
14 | 17 | ||
15 | 18 | ||
16 | 19 | func getVoteKey (id,type) = if ((type == "upvote")) | |
17 | 20 | then (id + "_upvote") | |
18 | 21 | else throw("Invalid vote type") | |
19 | 22 | ||
20 | 23 | ||
21 | 24 | func profileExist (id) = match getString(this, getProfileKey(id)) { | |
22 | 25 | case a: String => | |
23 | 26 | true | |
24 | 27 | case _ => | |
25 | 28 | false | |
26 | 29 | } | |
27 | 30 | ||
28 | 31 | ||
29 | 32 | func getVoteStatus (voteId) = match getString(this, getStatusKey(voteId)) { | |
30 | 33 | case a: String => | |
31 | 34 | a | |
32 | 35 | case _ => | |
33 | 36 | false | |
34 | 37 | } | |
35 | 38 | ||
36 | 39 | ||
37 | 40 | func getVoteCount (voteId,vote) = match getInteger(this, getVoteKey(voteId, vote)) { | |
38 | 41 | case a: Int => | |
39 | 42 | a | |
40 | 43 | case _ => | |
41 | 44 | throw("Not a valid vote ID") | |
42 | 45 | } | |
43 | 46 | ||
44 | 47 | ||
45 | 48 | func getVoterKey (address,voteId) = ((((address + "_") + voteId) + "_") + "vote") | |
46 | 49 | ||
47 | 50 | ||
48 | 51 | func getVoter (address,voteId) = match getString(this, getVoterKey(address, voteId)) { | |
49 | 52 | case a: String => | |
50 | 53 | a | |
51 | 54 | case _ => | |
52 | 55 | "" | |
53 | 56 | } | |
54 | 57 | ||
55 | 58 | ||
56 | 59 | func canVote (address,voteId) = { | |
57 | 60 | let voter = getVoter(address, voteId) | |
58 | 61 | if ((voter == "")) | |
59 | 62 | then true | |
60 | 63 | else false | |
61 | 64 | } | |
62 | 65 | ||
63 | 66 | ||
64 | 67 | @Callable(i) | |
65 | 68 | func addEntrepreneurProfile (name,avatar,bio,gender,location) = if ((i.caller.bytes != adminAddress)) | |
66 | 69 | then throw("Only Dyzrupt Admin can call this dApp function") | |
67 | 70 | else { | |
68 | 71 | let transactionId = toBase58String(i.transactionId) | |
69 | 72 | WriteSet([DataEntry(getProfileKey(transactionId), ((((((((name + "_") + avatar) + "_") + bio) + "_") + gender) + "_") + location)), DataEntry(getVoteKey(transactionId, "upvote"), 0), DataEntry(getStatusKey(transactionId), "open")]) | |
70 | 73 | } | |
71 | 74 | ||
72 | 75 | ||
73 | 76 | ||
74 | 77 | @Callable(i) | |
75 | 78 | func vote (voteId,vote) = { | |
76 | 79 | let pmt = extract(i.payment) | |
80 | + | let voter = toBase58String(i.caller.bytes) | |
77 | 81 | if ((pmt.amount == 0)) | |
78 | 82 | then throw("You cannot vote without paying voting fee") | |
79 | 83 | else if ((pmt.assetId != base58'9XTqBQeJvdMs8VNHv6rXiJLJichg2acG7wCfYcTajQ1G')) | |
80 | 84 | then throw("You can only vote with DYZRUPT token") | |
81 | - | else if (canVote( | |
85 | + | else if (canVote(voter, voteId)) | |
82 | 86 | then if (profileExist(voteId)) | |
83 | 87 | then if ((getVoteStatus(voteId) == "open")) | |
84 | 88 | then if ((vote == upVote)) | |
85 | 89 | then { | |
86 | 90 | let voteCount = getVoteCount(voteId, vote) | |
87 | 91 | let newVoteCount = (voteCount + 1) | |
88 | - | ScriptResult(WriteSet([DataEntry(getVoteKey(voteId, vote), newVoteCount), DataEntry(getVoterKey( | |
92 | + | ScriptResult(WriteSet([DataEntry(getVoteKey(voteId, vote), newVoteCount), DataEntry(getVoterKey(voter, voteId), voteId), DataEntry(getVoterAmountKey(voter, voteId), pmt.amount)]), TransferSet([ScriptTransfer(this, pmt.amount, dyzId)])) | |
89 | 93 | } | |
90 | 94 | else throw("Not a valid vote value") | |
91 | 95 | else throw("This profile is not open for voting") | |
92 | 96 | else throw("Invalid Profile") | |
93 | 97 | else throw("You can't vote twice") | |
94 | 98 | } | |
95 | 99 | ||
96 | 100 | ||
97 | 101 | ||
98 | 102 | @Callable(i) | |
99 | 103 | func openVote (voteId) = if ((i.caller.bytes != adminAddress)) | |
100 | 104 | then throw("Only Dyzrupt Admin can call this dApp function") | |
101 | 105 | else if (profileExist(voteId)) | |
102 | 106 | then WriteSet([DataEntry(getStatusKey(voteId), "open")]) | |
103 | 107 | else throw("Invalid ID") | |
104 | 108 | ||
105 | 109 | ||
106 | 110 | ||
107 | 111 | @Callable(i) | |
108 | 112 | func closeVote (voteId) = if ((i.caller.bytes != adminAddress)) | |
109 | 113 | then throw("Only Dyzrupt Admin can call this dApp function") | |
110 | 114 | else if (profileExist(voteId)) | |
111 | 115 | then WriteSet([DataEntry(getStatusKey(voteId), "closed")]) | |
112 | 116 | else throw("Invalid ID") | |
113 | 117 | ||
114 | 118 | ||
119 | + | ||
120 | + | @Callable(i) | |
121 | + | func withdraw (voteId) = { | |
122 | + | let voter = toBase58String(i.caller.bytes) | |
123 | + | if ((getVoter(voter, voteId) != "")) | |
124 | + | then if ((getVoteStatus(voteId) == "closed")) | |
125 | + | then { | |
126 | + | let currentKey = getVoterAmountKey(voter, voteId) | |
127 | + | let currentAmount = match getInteger(this, currentKey) { | |
128 | + | case a: Int => | |
129 | + | a | |
130 | + | case _ => | |
131 | + | throw("You didn't vote for this entrepreneur") | |
132 | + | } | |
133 | + | if ((currentAmount == 0)) | |
134 | + | then throw("Seems you have previously withdrawn.") | |
135 | + | else ScriptResult(WriteSet([DataEntry(currentKey, 0)]), TransferSet([ScriptTransfer(i.caller, currentAmount, dyzId)])) | |
136 | + | } | |
137 | + | else throw("Can't withdraw vote amount while voting is still open.") | |
138 | + | else throw("You didn't vote for this entrepreneur") | |
139 | + | } | |
140 | + | ||
141 | + |
github/deemru/w8io/026f985 32.78 ms ◑