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