39 | | - | func getBooleanByKey (key) = valueOrElse(getBoolean(this, key), false) |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | func getIntegerByKey (key) = valueOrElse(getInteger(this, key), 0) |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | func keyUserAddr (caller) = ("user_" + caller) |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func keyUserName (caller) = ("user_name_" + caller) |
---|
49 | | - | |
---|
50 | | - | |
---|
51 | | - | func keyUserDesc (caller) = ("user_desc_" + caller) |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func keyUserSocial (caller) = ("user_social_" + caller) |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | func keyUserThumb (caller) = ("user_thumb_" + caller) |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | func keyUserStatus (caller) = ("user_status_" + caller) |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | func keyUserDate (caller) = ("user_date_" + caller) |
---|
64 | | - | |
---|
65 | | - | |
---|
66 | | - | func keyArtistAgentAddr (artistAddr) = ("artist_agent_" + artistAddr) |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func keyAgentArtistAddr (agentAddr,artistAddr) = ((("agent_" + agentAddr) + "_") + artistAddr) |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func keyPrimaryShare (artistAddr) = ("artist_agent_primary_" + artistAddr) |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | func keySecondaryShare (artistAddr) = ("artist_agent_secondary_" + artistAddr) |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | func validateCID (cid) = if (contains(cid, "/")) |
---|
79 | | - | then if (if ((76 > size(cid))) |
---|
80 | | - | then (size(split(cid, "/")[0]) == 59) |
---|
81 | | - | else false) |
---|
82 | | - | then (16 > size(split(cid, "/")[1])) |
---|
83 | | - | else false |
---|
84 | | - | else false |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | func validUserData (caller,name,description,thumb,isAnUpdate) = { |
---|
88 | | - | let validCID = if ((size(thumb) != 0)) |
---|
89 | | - | then validateCID(thumb) |
---|
90 | | - | else true |
---|
91 | | - | if (!(validCID)) |
---|
92 | | - | then throw("CID don't match requirement!") |
---|
93 | | - | else if (if ((name == "")) |
---|
94 | | - | then true |
---|
95 | | - | else (description == "")) |
---|
96 | | - | then throw("Name and description cannot be empty") |
---|
97 | | - | else if ((size(description) > 600)) |
---|
98 | | - | then throw("600 Char. max description") |
---|
99 | | - | else if ((size(name) > 45)) |
---|
100 | | - | then throw("45 Char. max name") |
---|
101 | | - | else { |
---|
102 | | - | let status = getStringByKey(keyUserStatus(caller)) |
---|
103 | | - | if (if ((status == userSuspended)) |
---|
104 | | - | then true |
---|
105 | | - | else (status == userRemoved)) |
---|
106 | | - | then throw("Account suspended/ removed.") |
---|
107 | | - | else if (if (!(isAnUpdate)) |
---|
108 | | - | then (status == userRegistered) |
---|
109 | | - | else false) |
---|
110 | | - | then throw("Already registered") |
---|
111 | | - | else if (if (if (!(isAnUpdate)) |
---|
112 | | - | then (status == "") |
---|
113 | | - | else false) |
---|
114 | | - | then whitelistedonly |
---|
115 | | - | else false) |
---|
116 | | - | then throw("Can't register, get approved first.") |
---|
117 | | - | else if (if (if (isAnUpdate) |
---|
118 | | - | then (status == "") |
---|
119 | | - | else false) |
---|
120 | | - | then true |
---|
121 | | - | else if (isAnUpdate) |
---|
122 | | - | then (status == userAllowed) |
---|
123 | | - | else false) |
---|
124 | | - | then throw("Register first") |
---|
125 | | - | else true |
---|
126 | | - | } |
---|
| 6 | + | @Callable(i) |
---|
| 7 | + | func default () = { |
---|
| 8 | + | let y = invoke(addressFromStringValue("3PCbvPVQfSvVu88ip8Fm5YjwJhjEYk1Txhk"), "withdrawVestedAllUSDN", [false, true], nil) |
---|
| 9 | + | if ((y == y)) |
---|
| 10 | + | then nil |
---|
| 11 | + | else throw("Strict value is not equal to itself.") |
---|
130 | | - | func validateNewStatus (status,address,currentStatus) = { |
---|
131 | | - | let allStatus = [userVerified, userRegistered, userSuspended, userRemoved, userAllowed, userChangeRequired] |
---|
132 | | - | let statusToSet = if (containsElement(allStatus, status)) |
---|
133 | | - | then status |
---|
134 | | - | else if (if ((status == userReset)) |
---|
135 | | - | then (currentStatus == userAllowed) |
---|
136 | | - | else false) |
---|
137 | | - | then "" |
---|
138 | | - | else throw("Unknown status") |
---|
139 | | - | let userIsRegistered = getIntegerByKey(keyUserDate(address)) |
---|
140 | | - | if (if ((userIsRegistered == 0)) |
---|
141 | | - | then (statusToSet != userAllowed) |
---|
142 | | - | else false) |
---|
143 | | - | then throw("You cant set this status, user is not registered.") |
---|
144 | | - | else if (if ((currentStatus == userAllowed)) |
---|
145 | | - | then (statusToSet == userAllowed) |
---|
146 | | - | else false) |
---|
147 | | - | then throw("User already allowed") |
---|
148 | | - | else if (if ((currentStatus == userRegistered)) |
---|
149 | | - | then (statusToSet == userAllowed) |
---|
150 | | - | else false) |
---|
151 | | - | then throw("User already allowed & registered") |
---|
152 | | - | else if (if ((currentStatus == userVerified)) |
---|
153 | | - | then (statusToSet == userAllowed) |
---|
154 | | - | else false) |
---|
155 | | - | then throw("User already allowed & verified") |
---|
156 | | - | else statusToSet |
---|
157 | | - | } |
---|
158 | | - | |
---|
159 | | - | |
---|
160 | | - | func makeJSON (name,thumb,date) = (((((("{\"user_name\": \"" + name) + "\", \"user_thumb\":\"") + thumb) + "\",\"user_date\":\"") + date) + "\"}") |
---|
161 | | - | |
---|
162 | | - | |
---|
163 | | - | @Callable(invoke) |
---|
164 | | - | func appRunning (isLive,message) = { |
---|
165 | | - | let caller = toString(invoke.caller) |
---|
166 | | - | let id = toBase58String(invoke.transactionId) |
---|
167 | | - | if (containsElement([chris, joep, toString(this)], caller)) |
---|
168 | | - | then [BooleanEntry(dappRunningKey, isLive), StringEntry(maintenanceMSGKey, message)] |
---|
169 | | - | else throw("You are not allowed to change this") |
---|
170 | | - | } |
---|
171 | | - | |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | @Callable(invoke) |
---|
175 | | - | func registrationMode (WLonly) = { |
---|
176 | | - | let caller = toString(invoke.caller) |
---|
177 | | - | let id = toBase58String(invoke.transactionId) |
---|
178 | | - | if (containsElement([chris, toString(this)], caller)) |
---|
179 | | - | then [BooleanEntry(whitelistedonlyKey, WLonly)] |
---|
180 | | - | else throw("You are not allowed to change this") |
---|
181 | | - | } |
---|
182 | | - | |
---|
183 | | - | |
---|
184 | | - | |
---|
185 | | - | @Callable(invoke) |
---|
186 | | - | func registerUser (name,description,thumb,social) = if (!(dappRunning)) |
---|
187 | | - | then throw(maintenanceMSG) |
---|
188 | | - | else { |
---|
189 | | - | let caller = toString(invoke.caller) |
---|
190 | | - | let id = toBase58String(invoke.transactionId) |
---|
191 | | - | let timestamp = lastBlock.timestamp |
---|
192 | | - | if (!(validUserData(caller, name, description, thumb, false))) |
---|
193 | | - | then throw("Something went wrong") |
---|
194 | | - | else { |
---|
195 | | - | let json = makeJSON(toBase64String(toBytes(name)), toBase64String(toBytes(thumb)), toString(timestamp)) |
---|
196 | | - | [IntegerEntry(keyUserDate(caller), timestamp), StringEntry(keyUserAddr(caller), ((id + "_") + toString(timestamp))), StringEntry(keyUserName(caller), name), StringEntry(keyUserDesc(caller), description), StringEntry(keyUserSocial(caller), social), StringEntry(keyUserThumb(caller), thumb), StringEntry(keyUserStatus(caller), userRegistered), DeleteEntry(("ALLOWED_" + caller)), StringEntry(((userRegistered + "_") + caller), json)] |
---|
197 | | - | } |
---|
198 | | - | } |
---|
199 | | - | |
---|
200 | | - | |
---|
201 | | - | |
---|
202 | | - | @Callable(invoke) |
---|
203 | | - | func updateUser (name,description,thumb,social) = if (!(dappRunning)) |
---|
204 | | - | then throw(maintenanceMSG) |
---|
205 | | - | else { |
---|
206 | | - | let caller = toString(invoke.caller) |
---|
207 | | - | let id = toBase58String(invoke.transactionId) |
---|
208 | | - | let status = getStringByKey(keyUserStatus(caller)) |
---|
209 | | - | if (!(validUserData(caller, name, description, thumb, true))) |
---|
210 | | - | then throw("Something went wrong") |
---|
211 | | - | else { |
---|
212 | | - | let date = getIntegerByKey(keyUserDate(caller)) |
---|
213 | | - | let json = makeJSON(toBase64String(toBytes(name)), toBase64String(toBytes(thumb)), toString(date)) |
---|
214 | | - | [StringEntry(keyUserName(caller), name), StringEntry(keyUserDesc(caller), description), StringEntry(keyUserSocial(caller), social), StringEntry(keyUserThumb(caller), thumb), StringEntry(((status + "_") + caller), json)] |
---|
215 | | - | } |
---|
216 | | - | } |
---|
217 | | - | |
---|
218 | | - | |
---|
219 | | - | |
---|
220 | | - | @Callable(invoke) |
---|
221 | | - | func changeUserStatus (address,status,note) = { |
---|
222 | | - | let caller = toString(invoke.caller) |
---|
223 | | - | let id = toBase58String(invoke.transactionId) |
---|
224 | | - | let currentStatus = getStringByKey(keyUserStatus(address)) |
---|
225 | | - | let statusToSet = validateNewStatus(status, address, currentStatus) |
---|
226 | | - | let name = toBase64String(toBytes(getStringByKey(keyUserName(address)))) |
---|
227 | | - | let thumb = toBase64String(toBytes(getStringByKey(keyUserThumb(address)))) |
---|
228 | | - | let date = getIntegerByKey(keyUserDate(address)) |
---|
229 | | - | let json = makeJSON(name, thumb, toString(date)) |
---|
230 | | - | if (containsElement([chris, joep, toString(this)], caller)) |
---|
231 | | - | then [StringEntry(keyUserStatus(address), statusToSet), DeleteEntry(((currentStatus + "_") + address)), StringEntry(((statusToSet + "_") + address), json), StringEntry(("user_note_" + address), note)] |
---|
232 | | - | else throw("Not allowed to change user status") |
---|
233 | | - | } |
---|
234 | | - | |
---|
235 | | - | |
---|
236 | | - | |
---|
237 | | - | @Callable(invoke) |
---|
238 | | - | func deleteUser (address) = { |
---|
239 | | - | let caller = toString(invoke.caller) |
---|
240 | | - | let id = toBase58String(invoke.transactionId) |
---|
241 | | - | let currentStatus = getStringByKey(keyUserStatus(address)) |
---|
242 | | - | if (containsElement([chris, toString(this)], caller)) |
---|
243 | | - | then [DeleteEntry(keyUserDate(address)), DeleteEntry(keyUserAddr(address)), DeleteEntry(keyUserName(address)), DeleteEntry(keyUserDesc(address)), DeleteEntry(keyUserSocial(address)), DeleteEntry(keyUserThumb(address)), DeleteEntry(("user_note_" + address)), DeleteEntry(((currentStatus + "_") + address)), StringEntry(keyUserStatus(address), userRemoved)] |
---|
244 | | - | else throw("Not allowed") |
---|
245 | | - | } |
---|
246 | | - | |
---|
247 | | - | |
---|
248 | | - | |
---|
249 | | - | @Callable(i) |
---|
250 | | - | func setAgent (artistAddr,agentAddr,primaryShare,secondaryShare) = if (!(dappRunning)) |
---|
251 | | - | then throw(maintenanceMSG) |
---|
252 | | - | else { |
---|
253 | | - | let caller = toString(i.caller) |
---|
254 | | - | if (containsElement([chris, toString(this)], caller)) |
---|
255 | | - | then if (if ((size(artistAddr) != 35)) |
---|
256 | | - | then true |
---|
257 | | - | else (size(agentAddr) != 35)) |
---|
258 | | - | then throw("Wrong address") |
---|
259 | | - | else [StringEntry(keyArtistAgentAddr(artistAddr), agentAddr), StringEntry(keyAgentArtistAddr(agentAddr, artistAddr), artistAddr), IntegerEntry(keyPrimaryShare(artistAddr), primaryShare), IntegerEntry(keySecondaryShare(artistAddr), secondaryShare)] |
---|
260 | | - | else throw("You are not allowed") |
---|
261 | | - | } |
---|
262 | | - | |
---|
263 | | - | |
---|
264 | | - | |
---|
265 | | - | @Callable(i) |
---|
266 | | - | func unsetAgent (artistAddr,agentAddr) = if (!(dappRunning)) |
---|
267 | | - | then throw(maintenanceMSG) |
---|
268 | | - | else { |
---|
269 | | - | let caller = toString(i.caller) |
---|
270 | | - | if (containsElement([chris, toString(this)], caller)) |
---|
271 | | - | then if (if ((size(artistAddr) != 35)) |
---|
272 | | - | then true |
---|
273 | | - | else (size(agentAddr) != 35)) |
---|
274 | | - | then throw("Wrong address") |
---|
275 | | - | else [DeleteEntry(keyArtistAgentAddr(artistAddr)), DeleteEntry(keyAgentArtistAddr(agentAddr, artistAddr)), DeleteEntry(keyPrimaryShare(artistAddr)), DeleteEntry(keySecondaryShare(artistAddr))] |
---|
276 | | - | else throw("You are not allowed") |
---|
277 | | - | } |
---|
278 | | - | |
---|
279 | | - | |
---|
280 | | - | |
---|
281 | | - | @Callable(i) |
---|
282 | | - | func deleteEntry (entry) = { |
---|
283 | | - | let caller = toString(i.caller) |
---|
284 | | - | if ((caller == chris)) |
---|
285 | | - | then [DeleteEntry(entry)] |
---|
286 | | - | else throw("no") |
---|
287 | | - | } |
---|
288 | | - | |
---|
| 15 | + | @Verifier(tx) |
---|
| 16 | + | func verify () = match tx { |
---|
| 17 | + | case tx: InvokeScriptTransaction => |
---|
| 18 | + | true |
---|
| 19 | + | case _ => |
---|
| 20 | + | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
| 21 | + | } |
---|