1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | func getStringByKey (key) = valueOrElse(getString(this, key), "") |
---|
5 | 5 | | |
---|
6 | 6 | | |
---|
7 | 7 | | let unitTest = false |
---|
8 | 8 | | |
---|
9 | 9 | | let oracleFee = value(addressFromString(getStringByKey("conf_oracle_fee"))) |
---|
10 | 10 | | |
---|
11 | 11 | | let signDapp = value(addressFromString(getStringByKey("conf_signweb_dapp"))) |
---|
12 | 12 | | |
---|
13 | 13 | | let feeReceiver = getStringByKey("conf_fee_receiver") |
---|
14 | 14 | | |
---|
15 | 15 | | let userDapp = if (unitTest) |
---|
16 | 16 | | then value(addressFromString("3Mt4RGMEyjSWYAocTPqd55wdHQQB3PU2UCm")) |
---|
17 | 17 | | else value(addressFromString(getStringByKey("conf_users_dapp"))) |
---|
18 | 18 | | |
---|
19 | 19 | | let whitelistDapp = value(addressFromString(getStringByKey("conf_whitelist_dapp"))) |
---|
20 | 20 | | |
---|
21 | 21 | | let signAssetId = fromBase58String(getStringByKey("conf_accepted_asset_SIGN")) |
---|
22 | 22 | | |
---|
23 | 23 | | let usdnAssetId = fromBase58String(getStringByKey("conf_accepted_asset_USDN")) |
---|
24 | 24 | | |
---|
25 | 25 | | let usdtAssetId = fromBase58String(getStringByKey("conf_accepted_asset_USDT")) |
---|
26 | 26 | | |
---|
27 | 27 | | let wavesAssetId = base58'' |
---|
28 | 28 | | |
---|
29 | 29 | | let chris = getStringByKey("conf_admin_1") |
---|
30 | 30 | | |
---|
31 | 31 | | func getIntegerByKeyFromOracle (key) = valueOrErrorMessage(getInteger(oracleFee, key), "Integer undefine or 0 in oracle") |
---|
32 | 32 | | |
---|
33 | 33 | | |
---|
34 | 34 | | func getIntegerByKey (key) = valueOrElse(getInteger(this, key), 0) |
---|
35 | 35 | | |
---|
36 | 36 | | |
---|
37 | 37 | | func checkWhitelist (key) = valueOrElse(getInteger(whitelistDapp, key), 0) |
---|
38 | 38 | | |
---|
39 | 39 | | |
---|
40 | 40 | | func getBooleanByKey (key) = valueOrElse(getBoolean(this, key), false) |
---|
41 | 41 | | |
---|
42 | 42 | | |
---|
43 | 43 | | let signCut = 7 |
---|
44 | 44 | | |
---|
45 | 45 | | let usdnWaveCut = 10 |
---|
46 | 46 | | |
---|
47 | 47 | | let defaultLicence = getStringByKey("conf_default_licence") |
---|
48 | 48 | | |
---|
49 | 49 | | let defaultHashLicence = getStringByKey("conf_default_licence_hash") |
---|
50 | 50 | | |
---|
51 | 51 | | let dappRunning = valueOrElse(getBoolean(userDapp, "conf_dapp_is_running"), true) |
---|
52 | 52 | | |
---|
53 | 53 | | let maintenanceMSG = valueOrElse(getString(userDapp, "conf_maintenance_msg"), "") |
---|
54 | 54 | | |
---|
55 | 55 | | let userSuspended = "SUSPENDED" |
---|
56 | 56 | | |
---|
57 | 57 | | let userRemoved = "REMOVED" |
---|
58 | 58 | | |
---|
59 | 59 | | let userUnregistered = "UNREGISTERED" |
---|
60 | 60 | | |
---|
61 | 61 | | let userAllowed = "ALLOWED" |
---|
62 | 62 | | |
---|
63 | 63 | | let currentCertificationPrice = getIntegerByKeyFromOracle(("certification_fee_" + toBase58String(signAssetId))) |
---|
64 | 64 | | |
---|
65 | 65 | | func checkSignCertificate (signID,Owner,sha256Hash) = match getString(signDapp, ((("data_fc_" + signID) + "_") + Owner)) { |
---|
66 | 66 | | case a: String => |
---|
67 | 67 | | if (contains(a, sha256Hash)) |
---|
68 | 68 | | then true |
---|
69 | 69 | | else false |
---|
70 | 70 | | case _ => |
---|
71 | 71 | | false |
---|
72 | 72 | | } |
---|
73 | 73 | | |
---|
74 | 74 | | |
---|
75 | 75 | | func validateCID (cid) = if (contains(cid, "/")) |
---|
76 | 76 | | then if (if ((76 > size(cid))) |
---|
77 | 77 | | then (size(split(cid, "/")[0]) == 59) |
---|
78 | 78 | | else false) |
---|
79 | 79 | | then (16 > size(split(cid, "/")[1])) |
---|
80 | 80 | | else false |
---|
81 | 81 | | else false |
---|
82 | 82 | | |
---|
83 | 83 | | |
---|
84 | 84 | | func validateHash (hash) = (size(hash) == 64) |
---|
85 | 85 | | |
---|
86 | 86 | | |
---|
87 | 87 | | func keyUserStatus (caller) = ("user_status_" + caller) |
---|
88 | 88 | | |
---|
89 | 89 | | |
---|
90 | 90 | | func keyDate (caller,artId) = ((("art_date_" + artId) + "_") + caller) |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func keyName (caller,artId) = ((("art_name_" + artId) + "_") + caller) |
---|
94 | 94 | | |
---|
95 | 95 | | |
---|
96 | 96 | | func keyDesc (caller,artId) = ((("art_desc_" + artId) + "_") + caller) |
---|
97 | 97 | | |
---|
98 | 98 | | |
---|
99 | 99 | | func keyDisplayCid (caller,artId) = ((("art_display_cid_" + artId) + "_") + caller) |
---|
100 | 100 | | |
---|
101 | 101 | | |
---|
102 | 102 | | func keyExportHash (caller,artId) = ((("art_export_hash_" + artId) + "_") + caller) |
---|
103 | 103 | | |
---|
104 | 104 | | |
---|
105 | 105 | | func keyExportCid (caller,artId) = ((("art_export_cid_" + artId) + "_") + caller) |
---|
106 | 106 | | |
---|
107 | 107 | | |
---|
108 | 108 | | func keyMaxMint (caller,artId) = ((("art_maxmint_" + artId) + "_") + caller) |
---|
109 | 109 | | |
---|
110 | 110 | | |
---|
111 | 111 | | func keySignID (caller,artId) = ((("art_signid_" + artId) + "_") + caller) |
---|
112 | 112 | | |
---|
113 | 113 | | |
---|
114 | 114 | | func keyIssued (caller,artId) = ((("art_issued_" + artId) + "_") + caller) |
---|
115 | 115 | | |
---|
116 | 116 | | |
---|
117 | 117 | | func keyOnSale (caller,artId) = ((("art_onsale_" + artId) + "_") + caller) |
---|
118 | 118 | | |
---|
119 | 119 | | |
---|
120 | 120 | | func keyLicenceHash (caller,artId) = ((("art_licence_hash_" + artId) + "_") + caller) |
---|
121 | 121 | | |
---|
122 | 122 | | |
---|
123 | 123 | | func keyLicenceCid (caller,artId) = ((("art_licence_cid_" + artId) + "_") + caller) |
---|
124 | 124 | | |
---|
125 | 125 | | |
---|
126 | 126 | | func keyTags (caller,artId) = ((("art_tags_" + artId) + "_") + caller) |
---|
127 | 127 | | |
---|
128 | 128 | | |
---|
129 | 129 | | func keyType (caller,artId) = ((("art_type_" + artId) + "_") + caller) |
---|
130 | 130 | | |
---|
131 | 131 | | |
---|
132 | 132 | | func keyNote (caller,artId) = ((("art_note_" + artId) + "_") + caller) |
---|
133 | 133 | | |
---|
134 | 134 | | |
---|
135 | 135 | | func keyCrawler (caller,artId) = ((("art_crawler_cid_" + artId) + "_") + caller) |
---|
136 | 136 | | |
---|
137 | 137 | | |
---|
138 | 138 | | func keyRoyalties (caller,artId) = ((("art_royalties_" + artId) + "_") + caller) |
---|
139 | 139 | | |
---|
140 | 140 | | |
---|
141 | 141 | | func keyPrice (caller,artId) = ((("art_price_" + artId) + "_") + caller) |
---|
142 | 142 | | |
---|
143 | 143 | | |
---|
144 | 144 | | func keyEndSale (caller,artId) = ((("art_endsale_" + artId) + "_") + caller) |
---|
145 | 145 | | |
---|
146 | 146 | | |
---|
147 | 147 | | func keyAssetIdAccepted (caller,artId) = ((("art_assetAccepted_" + artId) + "_") + caller) |
---|
148 | 148 | | |
---|
149 | 149 | | |
---|
150 | 150 | | func keyFlag (caller,artId) = ((("art_flag_" + artId) + "_") + caller) |
---|
151 | 151 | | |
---|
152 | 152 | | |
---|
153 | 153 | | func keyArtistAgentAddr (artistAddr) = ("artist_agent_" + artistAddr) |
---|
154 | 154 | | |
---|
155 | 155 | | |
---|
156 | 156 | | func keyPrimaryShareAgent (artistAddr) = ("artist_agent_primary_" + artistAddr) |
---|
157 | 157 | | |
---|
158 | 158 | | |
---|
159 | 159 | | func keyArtistPublicAgentAddr (artistAddr) = ("artist_public_agent_" + artistAddr) |
---|
160 | 160 | | |
---|
161 | 161 | | |
---|
162 | 162 | | func keyPrimarySharePublicAgent (artistAddr) = ("artist_public_agent_primary_" + artistAddr) |
---|
163 | 163 | | |
---|
164 | 164 | | |
---|
165 | 165 | | func keyHashByTxidAddr (caller,txid) = ((("get_hashbytxidaddr_" + txid) + "_") + caller) |
---|
166 | 166 | | |
---|
167 | 167 | | |
---|
168 | 168 | | func keyOwnerByHash (sha256Hash) = ("get_owner_by_hash_" + sha256Hash) |
---|
169 | 169 | | |
---|
170 | 170 | | |
---|
171 | 171 | | func keyidBySignid (caller,signId) = ((("get_artidbysignid_" + signId) + "_") + caller) |
---|
172 | 172 | | |
---|
173 | 173 | | |
---|
174 | 174 | | func keyTxidByHashOwner (sha256Hash,caller) = ("get_txid_by_hash_owner_" + toBase58String(sha256_16Kb(toBytes((sha256Hash + caller))))) |
---|
175 | 175 | | |
---|
176 | 176 | | |
---|
177 | 177 | | func validateAllCID (cidDisplay,cidExport,cidLicence) = if (!(validateCID(cidDisplay))) |
---|
178 | 178 | | then throw("Wrong Display CID") |
---|
179 | 179 | | else if (!(validateCID(cidExport))) |
---|
180 | 180 | | then throw("Wrong Export CID") |
---|
181 | 181 | | else if (if ((cidLicence != "")) |
---|
182 | 182 | | then !(validateCID(cidLicence)) |
---|
183 | 183 | | else false) |
---|
184 | 184 | | then throw("Wrong Licence CID") |
---|
185 | 185 | | else true |
---|
186 | 186 | | |
---|
187 | 187 | | |
---|
188 | 188 | | func validateAllHash (sha256Export,sha256Licence) = if (!(validateHash(sha256Export))) |
---|
189 | 189 | | then throw("Export Hash 64 char. max") |
---|
190 | 190 | | else if (!(validateHash(sha256Licence))) |
---|
191 | 191 | | then throw("Licence Hash 64 char. max") |
---|
192 | 192 | | else true |
---|
193 | 193 | | |
---|
194 | 194 | | |
---|
195 | 195 | | func validateString (str,max) = if ((size(str) == 0)) |
---|
196 | 196 | | then throw("Field cannot be is empty") |
---|
197 | 197 | | else if ((size(str) > max)) |
---|
198 | 198 | | then throw((str + " is too long")) |
---|
199 | 199 | | else true |
---|
200 | 200 | | |
---|
201 | 201 | | |
---|
202 | 202 | | func validateUser (caller) = { |
---|
203 | 203 | | let userStatus = valueOrElse(getString(userDapp, keyUserStatus(caller)), userUnregistered) |
---|
204 | 204 | | if (if ((userStatus == userUnregistered)) |
---|
205 | 205 | | then true |
---|
206 | 206 | | else (userStatus == userAllowed)) |
---|
207 | 207 | | then "Register this account first with \"Account\" tab" |
---|
208 | 208 | | else if ((userStatus == userSuspended)) |
---|
209 | 209 | | then "Account suspended" |
---|
210 | 210 | | else if ((userStatus == userRemoved)) |
---|
211 | 211 | | then "Account removed" |
---|
212 | 212 | | else "" |
---|
213 | 213 | | } |
---|
214 | 214 | | |
---|
215 | 215 | | |
---|
216 | 216 | | func setLIcence (cidLicence,sha256Licence) = { |
---|
217 | 217 | | let cid = if ((size(cidLicence) == 0)) |
---|
218 | 218 | | then defaultLicence |
---|
219 | 219 | | else cidLicence |
---|
220 | 220 | | let hash = if ((size(sha256Licence) == 0)) |
---|
221 | 221 | | then defaultHashLicence |
---|
222 | 222 | | else sha256Licence |
---|
223 | 223 | | $Tuple2(cid, hash) |
---|
224 | 224 | | } |
---|
225 | 225 | | |
---|
226 | 226 | | |
---|
227 | 227 | | func validateArtworkData (caller,cidDisplay,cidExport,licenceCID,sha256Export,licenceHash,name,description,tags,royalties) = { |
---|
228 | 228 | | let checkUser = validateUser(caller) |
---|
229 | 229 | | if ((checkUser != "")) |
---|
230 | 230 | | then throw(checkUser) |
---|
231 | 231 | | else if ((size(cidDisplay) == 0)) |
---|
232 | 232 | | then throw("Display CID cannot be empty") |
---|
233 | 233 | | else if (!(validateAllCID(cidDisplay, cidExport, licenceCID))) |
---|
234 | 234 | | then throw("Problem with CID") |
---|
235 | 235 | | else if (!(validateAllHash(sha256Export, licenceHash))) |
---|
236 | 236 | | then throw("Problem with Hashes") |
---|
237 | 237 | | else if (!(validateString(name, 100))) |
---|
238 | 238 | | then throw("100 Char. max name") |
---|
239 | 239 | | else if (!(validateString(description, 1000))) |
---|
240 | 240 | | then throw("1000 Char. max description") |
---|
241 | 241 | | else if (if ((0 > royalties)) |
---|
242 | 242 | | then true |
---|
243 | 243 | | else (royalties > 1000)) |
---|
244 | 244 | | then throw("Royalties cannot be less than 0% or higher than 10%") |
---|
245 | 245 | | else if ((size(split(tags, ",")) > 5)) |
---|
246 | 246 | | then throw("5 tags max.") |
---|
247 | 247 | | else "" |
---|
248 | 248 | | } |
---|
249 | 249 | | |
---|
250 | 250 | | |
---|
251 | 251 | | func isPayment (i) = if ((size(i.payments) == 0)) |
---|
252 | 252 | | then throw("No payment attached") |
---|
253 | 253 | | else { |
---|
254 | 254 | | let payment = value(i.payments[0]) |
---|
255 | 255 | | let amount = value(payment.amount) |
---|
256 | 256 | | $Tuple2(payment, amount) |
---|
257 | 257 | | } |
---|
258 | 258 | | |
---|
259 | 259 | | |
---|
260 | 260 | | func validatePayment (i) = { |
---|
261 | 261 | | let $t091809216 = isPayment(i) |
---|
262 | 262 | | let payment = $t091809216._1 |
---|
263 | 263 | | let amount = $t091809216._2 |
---|
264 | 264 | | let assetId = if (if (isDefined(payment.assetId)) |
---|
265 | 265 | | then (payment.assetId == signAssetId) |
---|
266 | 266 | | else false) |
---|
267 | 267 | | then payment.assetId |
---|
268 | 268 | | else throw("Only SIGN token accepted as transaction fee") |
---|
269 | 269 | | if ((amount != currentCertificationPrice)) |
---|
270 | 270 | | then throw(("Payment amount should be " + toString(currentCertificationPrice))) |
---|
271 | 271 | | else $Tuple2(amount, assetId) |
---|
272 | 272 | | } |
---|
273 | 273 | | |
---|
274 | 274 | | |
---|
275 | 275 | | func isArtMinted (addrToUse,artId) = match getInteger(this, keyIssued(addrToUse, artId)) { |
---|
276 | 276 | | case b: Int => |
---|
277 | 277 | | if ((b != 0)) |
---|
278 | 278 | | then true |
---|
279 | 279 | | else false |
---|
280 | 280 | | case _ => |
---|
281 | 281 | | false |
---|
282 | 282 | | } |
---|
283 | 283 | | |
---|
284 | 284 | | |
---|
285 | 285 | | func validatePriceAssetId (i,priceAssetId,artworkPrice) = { |
---|
286 | 286 | | let $t098049840 = isPayment(i) |
---|
287 | 287 | | let payment = $t098049840._1 |
---|
288 | 288 | | let amount = $t098049840._2 |
---|
289 | 289 | | let assetId = if (!(isDefined(payment.assetId))) |
---|
290 | 290 | | then unit |
---|
291 | 291 | | else if (if ((size(priceAssetId) > 0)) |
---|
292 | 292 | | then (toBase58String(value(payment.assetId)) == priceAssetId) |
---|
293 | 293 | | else false) |
---|
294 | 294 | | then payment.assetId |
---|
295 | 295 | | else throw("Wrong asset id") |
---|
296 | 296 | | if (if ((assetId == unit)) |
---|
297 | 297 | | then (priceAssetId != "") |
---|
298 | 298 | | else false) |
---|
299 | 299 | | then throw("Wrong asset id") |
---|
300 | 300 | | else if ((artworkPrice != amount)) |
---|
301 | 301 | | then throw("Payment don't match") |
---|
302 | 302 | | else $Tuple2(amount, assetId) |
---|
303 | 303 | | } |
---|
304 | 304 | | |
---|
305 | 305 | | |
---|
306 | 306 | | func acceptedAssetIds (assetId) = if (if (if (if (if ((assetId != toBase58String(signAssetId))) |
---|
307 | 307 | | then (assetId != toBase58String(wavesAssetId)) |
---|
308 | 308 | | else false) |
---|
309 | 309 | | then (assetId != "WAVES") |
---|
310 | 310 | | else false) |
---|
311 | 311 | | then (assetId != toBase58String(usdnAssetId)) |
---|
312 | 312 | | else false) |
---|
313 | 313 | | then (assetId != toBase58String(usdtAssetId)) |
---|
314 | 314 | | else false) |
---|
315 | 315 | | then throw("Only SIGN, USDN,USDT or WAVES accepted") |
---|
316 | 316 | | else true |
---|
317 | 317 | | |
---|
318 | 318 | | |
---|
319 | 319 | | func validateMinSell (assetId,price) = { |
---|
320 | 320 | | let minSellWaves = if (unitTest) |
---|
321 | 321 | | then 10 |
---|
322 | 322 | | else getIntegerByKeyFromOracle("waves_min_sell") |
---|
323 | 323 | | let minSellUsdn = 1000000 |
---|
324 | 324 | | let minSellSign = if (unitTest) |
---|
325 | 325 | | then 1 |
---|
326 | 326 | | else (currentCertificationPrice * 2) |
---|
327 | 327 | | if (if (if (if (if (if ((assetId == toBase58String(usdnAssetId))) |
---|
328 | 328 | | then (minSellUsdn > price) |
---|
329 | 329 | | else false) |
---|
330 | 330 | | then (price != 0) |
---|
331 | 331 | | else false) |
---|
332 | 332 | | then true |
---|
333 | 333 | | else if (if ((assetId == toBase58String(usdtAssetId))) |
---|
334 | 334 | | then (minSellUsdn > price) |
---|
335 | 335 | | else false) |
---|
336 | 336 | | then (price != 0) |
---|
337 | 337 | | else false) |
---|
338 | 338 | | then true |
---|
339 | 339 | | else if (if ((assetId == toBase58String(signAssetId))) |
---|
340 | 340 | | then (minSellSign > price) |
---|
341 | 341 | | else false) |
---|
342 | 342 | | then (price != 0) |
---|
343 | 343 | | else false) |
---|
344 | 344 | | then true |
---|
345 | 345 | | else if (if (if ((assetId == toBase58String(wavesAssetId))) |
---|
346 | 346 | | then true |
---|
347 | 347 | | else (assetId == "WAVES")) |
---|
348 | 348 | | then (minSellWaves > price) |
---|
349 | 349 | | else false) |
---|
350 | 350 | | then (price != 0) |
---|
351 | 351 | | else false) |
---|
352 | 352 | | then throw("Wrong minimum sell price") |
---|
353 | 353 | | else true |
---|
354 | 354 | | } |
---|
355 | 355 | | |
---|
356 | 356 | | |
---|
357 | 357 | | func getBidAssetId (assetId) = if ((assetId == "WAVES")) |
---|
358 | 358 | | then unit |
---|
359 | 359 | | else fromBase58String(assetId) |
---|
360 | 360 | | |
---|
361 | 361 | | |
---|
362 | 362 | | func getPriceAssetIdFromBid (bidDataKey) = { |
---|
363 | 363 | | let bidData = getStringByKey((bidDataKey + "_OPEN")) |
---|
364 | 364 | | if ((bidData == "")) |
---|
365 | 365 | | then throw("Bid not found") |
---|
366 | 366 | | else { |
---|
367 | 367 | | let bidDataArr = split(bidData, "_") |
---|
368 | 368 | | let bidAmount = parseIntValue(bidDataArr[1]) |
---|
369 | 369 | | let bidAssetId = getBidAssetId(bidDataArr[0]) |
---|
370 | 370 | | if ((0 >= bidAmount)) |
---|
371 | 371 | | then throw("Wrong amount") |
---|
372 | 372 | | else $Tuple2(bidAmount, bidAssetId) |
---|
373 | 373 | | } |
---|
374 | 374 | | } |
---|
375 | 375 | | |
---|
376 | 376 | | |
---|
377 | 377 | | func idCallerDateSponsored (i,pubKey) = if (!(dappRunning)) |
---|
378 | 378 | | then throw(maintenanceMSG) |
---|
379 | 379 | | else { |
---|
380 | 380 | | let isSponsored = if ((pubKey != "")) |
---|
381 | 381 | | then valueOrElse(checkWhitelist((toString(addressFromPublicKey(fromBase58String(pubKey))) + "_free_txs")), 0) |
---|
382 | 382 | | else 0 |
---|
383 | 383 | | let caller = if (if ((toBase58String(i.caller.bytes) == toString(this))) |
---|
384 | 384 | | then (isSponsored > 0) |
---|
385 | 385 | | else false) |
---|
386 | 386 | | then toString(addressFromPublicKey(fromBase58String(pubKey))) |
---|
387 | 387 | | else toBase58String(i.caller.bytes) |
---|
388 | 388 | | let get_sponsored_waves = if (if ((pubKey != "")) |
---|
389 | 389 | | then (isSponsored > 0) |
---|
390 | 390 | | else false) |
---|
391 | 391 | | then invoke(whitelistDapp, "useFreeTx", [toString(addressFromPublicKey(fromBase58String(pubKey)))], nil) |
---|
392 | 392 | | else unit |
---|
393 | 393 | | if ((get_sponsored_waves == get_sponsored_waves)) |
---|
394 | 394 | | then $Tuple4(toBase58String(i.transactionId), caller, lastBlock.timestamp, (isSponsored > 0)) |
---|
395 | 395 | | else throw("Strict value is not equal to itself.") |
---|
396 | 396 | | } |
---|
397 | 397 | | |
---|
398 | 398 | | |
---|
399 | 399 | | func idCallerDate (i) = if (!(dappRunning)) |
---|
400 | 400 | | then throw(maintenanceMSG) |
---|
401 | 401 | | else $Tuple3(toBase58String(i.transactionId), toBase58String(i.caller.bytes), lastBlock.timestamp) |
---|
402 | 402 | | |
---|
403 | 403 | | |
---|
404 | 404 | | func buyMint (i,artId,issuer,bidId,bidOwner,pubKey) = { |
---|
405 | 405 | | let $t01304113130 = idCallerDateSponsored(i, pubKey) |
---|
406 | 406 | | let id = $t01304113130._1 |
---|
407 | 407 | | let caller = $t01304113130._2 |
---|
408 | 408 | | let date = $t01304113130._3 |
---|
409 | 409 | | let isSponsored = $t01304113130._4 |
---|
410 | 410 | | let isBid = if (if (if ((caller == issuer)) |
---|
411 | 411 | | then (bidOwner != "") |
---|
412 | 412 | | else false) |
---|
413 | 413 | | then (bidId != "") |
---|
414 | 414 | | else false) |
---|
415 | 415 | | then true |
---|
416 | 416 | | else false |
---|
417 | 417 | | let blockEnd = getIntegerByKey(keyEndSale(caller, artId)) |
---|
418 | 418 | | if (if (if ((blockEnd != 0)) |
---|
419 | 419 | | then (height >= blockEnd) |
---|
420 | 420 | | else false) |
---|
421 | 421 | | then !(isBid) |
---|
422 | 422 | | else false) |
---|
423 | 423 | | then throw("Sale ended.") |
---|
424 | 424 | | else { |
---|
425 | 425 | | let callerIsIssuer = (caller == issuer) |
---|
426 | 426 | | let totalNFT = getIntegerByKey("total_nft_issued") |
---|
427 | 427 | | let signID = getStringByKey(keySignID(issuer, artId)) |
---|
428 | 428 | | let artworkName = getStringByKey(keyName(issuer, artId)) |
---|
429 | 429 | | if ((artworkName == "")) |
---|
430 | 430 | | then throw("Art doesn't exist") |
---|
431 | 431 | | else { |
---|
432 | 432 | | let isOnSale = getBooleanByKey(keyOnSale(issuer, artId)) |
---|
433 | 433 | | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
434 | 434 | | let artworkPrice = if (callerIsIssuer) |
---|
435 | 435 | | then (currentCertificationPrice * 2) |
---|
436 | 436 | | else getIntegerByKey(keyPrice(issuer, artId)) |
---|
437 | 437 | | let priceAssetId = if (callerIsIssuer) |
---|
438 | 438 | | then toBase58String(signAssetId) |
---|
439 | 439 | | else getStringByKey(keyAssetIdAccepted(issuer, artId)) |
---|
440 | 440 | | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
441 | 441 | | if (if (if (!(isBid)) |
---|
442 | 442 | | then !(callerIsIssuer) |
---|
443 | 443 | | else false) |
---|
444 | 444 | | then if (if ((0 >= artworkPrice)) |
---|
445 | 445 | | then true |
---|
446 | 446 | | else !(isOnSale)) |
---|
447 | 447 | | then true |
---|
448 | 448 | | else (0 >= maxCanSell) |
---|
449 | 449 | | else false) |
---|
450 | 450 | | then throw("Art not for sale") |
---|
451 | 451 | | else if (if (if (!(isBid)) |
---|
452 | 452 | | then callerIsIssuer |
---|
453 | 453 | | else false) |
---|
454 | 454 | | then (0 >= maxCanSell) |
---|
455 | 455 | | else false) |
---|
456 | 456 | | then throw("Max issuable not set") |
---|
457 | 457 | | else { |
---|
458 | 458 | | let checkUser = validateUser(issuer) |
---|
459 | 459 | | if (if (isBid) |
---|
460 | 460 | | then (checkUser != "") |
---|
461 | 461 | | else false) |
---|
462 | 462 | | then throw(checkUser) |
---|
463 | 463 | | else { |
---|
464 | 464 | | let bidDataKey = ((((((("bid_" + artId) + "_") + issuer) + "_") + bidOwner) + "_") + bidId) |
---|
465 | 465 | | let $t01464914841 = if (isBid) |
---|
466 | 466 | | then getPriceAssetIdFromBid(bidDataKey) |
---|
467 | 467 | | else validatePriceAssetId(i, priceAssetId, artworkPrice) |
---|
468 | 468 | | let amount = $t01464914841._1 |
---|
469 | 469 | | let assetId = $t01464914841._2 |
---|
470 | 470 | | let agent = valueOrElse(getString(userDapp, keyArtistAgentAddr(issuer)), feeReceiver) |
---|
471 | 471 | | let agentShare = valueOrElse(getInteger(userDapp, keyPrimaryShareAgent(issuer)), 0) |
---|
472 | 472 | | let publicAgent = valueOrElse(getString(userDapp, keyArtistPublicAgentAddr(issuer)), feeReceiver) |
---|
473 | 473 | | let publicAgentShare = valueOrElse(getInteger(userDapp, keyPrimarySharePublicAgent(issuer)), 0) |
---|
474 | 474 | | let isWhitelisted = checkWhitelist(issuer) |
---|
475 | 475 | | let cut = if ((isWhitelisted > height)) |
---|
476 | 476 | | then 0 |
---|
477 | 477 | | else if ((assetId == signAssetId)) |
---|
478 | 478 | | then signCut |
---|
479 | 479 | | else usdnWaveCut |
---|
480 | 480 | | let amountForSign = fraction(amount, cut, 100) |
---|
481 | 481 | | let amountForAgent = if (if (if ((agent != feeReceiver)) |
---|
482 | 482 | | then (agentShare > 0) |
---|
483 | 483 | | else false) |
---|
484 | 484 | | then (height > isWhitelisted) |
---|
485 | 485 | | else false) |
---|
486 | 486 | | then fraction(amount, agentShare, 10000) |
---|
487 | 487 | | else 0 |
---|
488 | 488 | | let amountForPublicAgent = if (if (if ((publicAgent != feeReceiver)) |
---|
489 | 489 | | then (publicAgentShare > 0) |
---|
490 | 490 | | else false) |
---|
491 | 491 | | then (height > isWhitelisted) |
---|
492 | 492 | | else false) |
---|
493 | 493 | | then fraction(amount, publicAgentShare, 10000) |
---|
494 | 494 | | else 0 |
---|
495 | 495 | | let amountForCreator = (amount - amountForSign) |
---|
496 | 496 | | if ((amountSold == maxCanSell)) |
---|
497 | 497 | | then throw("Art sold out") |
---|
498 | 498 | | else { |
---|
499 | 499 | | let newAmountSold = (amountSold + 1) |
---|
500 | 500 | | let issueMeta = ((((((((((("Creator: " + issuer) + ", |
---|
501 | 501 | | ArtID: ") + artId) + ", |
---|
502 | 502 | | SignID: ") + signID) + ", |
---|
503 | 503 | | Artwork name: ") + artworkName) + ", |
---|
504 | 504 | | Issue: ") + toString(newAmountSold)) + "/") + toString(maxCanSell)) |
---|
505 | 505 | | let issueNFT = Issue(("SA_" + toString((totalNFT + 1))), issueMeta, 1, 0, false) |
---|
506 | 506 | | let idNFT = calculateAssetId(issueNFT) |
---|
507 | 507 | | let sellStatus = if (if ((newAmountSold == maxCanSell)) |
---|
508 | 508 | | then true |
---|
509 | 509 | | else !(isOnSale)) |
---|
510 | 510 | | then false |
---|
511 | 511 | | else true |
---|
512 | 512 | | let receiveNFT = if (if (if ((caller == issuer)) |
---|
513 | 513 | | then (bidOwner != "") |
---|
514 | 514 | | else false) |
---|
515 | 515 | | then (bidId != "") |
---|
516 | 516 | | else false) |
---|
517 | 517 | | then addressFromStringValue(bidOwner) |
---|
518 | 518 | | else i.caller |
---|
519 | 519 | | let assetIdBid = if (!(isDefined(assetId))) |
---|
520 | 520 | | then "WAVES" |
---|
521 | 521 | | else toBase58String(value(assetId)) |
---|
522 | 522 | | let bidData = getStringByKey((bidDataKey + "_OPEN")) |
---|
523 | 523 | | let bidDelOld = DeleteEntry((bidDataKey + "_OPEN")) |
---|
524 | 524 | | let bidUpdate = StringEntry((bidDataKey + "_CLOSED"), ((bidData + "_") + toString(date))) |
---|
525 | 525 | | let soldKey = ((((((("art_sold_" + toString(newAmountSold)) + "_of_") + toString(maxCanSell)) + "_") + artId) + "_") + issuer) |
---|
526 | 526 | | let soldValue = if (!(isBid)) |
---|
527 | 527 | | then ((((((((((caller + "_") + toString(date)) + "_") + id) + "_") + toString(artworkPrice)) + "_") + priceAssetId) + "_") + toBase58String(idNFT)) |
---|
528 | 528 | | else ((((((((((toString(receiveNFT) + "_") + toString(date)) + "_") + id) + "_") + toString(amount)) + "_") + assetIdBid) + "_") + toBase58String(idNFT)) |
---|
529 | 529 | | let soldData = StringEntry(soldKey, soldValue) |
---|
530 | 530 | | let commissionsWithAgent = if ((amountForAgent != 0)) |
---|
531 | 531 | | then [ScriptTransfer(Address(fromBase58String(feeReceiver)), (amountForSign - amountForAgent), assetId), ScriptTransfer(Address(fromBase58String(agent)), amountForAgent, assetId)] |
---|
532 | 532 | | else [ScriptTransfer(Address(fromBase58String(feeReceiver)), amountForSign, assetId)] |
---|
533 | 533 | | let commissionsWithPublicAgent = if ((amountForPublicAgent != 0)) |
---|
534 | 534 | | then [ScriptTransfer(Address(fromBase58String(publicAgent)), amountForPublicAgent, assetId), ScriptTransfer(Address(fromBase58String(issuer)), (amountForCreator - amountForPublicAgent), assetId)] |
---|
535 | 535 | | else [ScriptTransfer(Address(fromBase58String(issuer)), amountForCreator, assetId)] |
---|
536 | 536 | | let txToCaller = if (isSponsored) |
---|
537 | 537 | | then [ScriptTransfer(Address(fromBase58String(caller)), 0, unit)] |
---|
538 | 538 | | else nil |
---|
539 | 539 | | let buyRes = ((([IntegerEntry(keyIssued(issuer, artId), newAmountSold), StringEntry(("nft_" + toBase58String(idNFT)), soldKey), IntegerEntry("total_nft_issued", (totalNFT + 1)), IntegerEntry(keyEndSale(issuer, artId), 0), BooleanEntry(keyOnSale(issuer, artId), sellStatus), issueNFT, ScriptTransfer(receiveNFT, 1, idNFT)] ++ commissionsWithAgent) ++ commissionsWithPublicAgent) ++ txToCaller) |
---|
540 | 540 | | if (isBid) |
---|
541 | 541 | | then [soldData, bidUpdate, bidDelOld] :: buyRes |
---|
542 | 542 | | else soldData :: buyRes |
---|
543 | 543 | | } |
---|
544 | 544 | | } |
---|
545 | 545 | | } |
---|
546 | 546 | | } |
---|
547 | 547 | | } |
---|
548 | 548 | | } |
---|
549 | 549 | | |
---|
550 | 550 | | |
---|
551 | 551 | | func asString (bv) = match bv { |
---|
552 | 552 | | case bv0: String => |
---|
553 | 553 | | bv0 |
---|
554 | 554 | | case _ => |
---|
555 | 555 | | throw("Sponsored Public Key String expected") |
---|
556 | 556 | | } |
---|
557 | 557 | | |
---|
558 | 558 | | |
---|
559 | 559 | | @Callable(invoke) |
---|
560 | 560 | | func setConf (key,val) = { |
---|
561 | 561 | | let caller = toString(invoke.caller) |
---|
562 | 562 | | if (containsElement([chris, toString(this)], caller)) |
---|
563 | 563 | | then if (contains(key, "conf_")) |
---|
564 | 564 | | then [StringEntry(key, val)] |
---|
565 | 565 | | else throw("Entries starting with conf_ only") |
---|
566 | 566 | | else throw("You are not allowed to change this") |
---|
567 | 567 | | } |
---|
568 | 568 | | |
---|
569 | 569 | | |
---|
570 | 570 | | |
---|
571 | 571 | | @Callable(i) |
---|
572 | 572 | | func addArtwork (sha256Hash,signID,name,description,tags,type,cidDisplay,sha256Export,cidExport,sha256Licence,cidLicence,crawler,royalties,pubKey) = { |
---|
573 | 573 | | let $t02001720090 = idCallerDateSponsored(i, pubKey) |
---|
574 | 574 | | let artId = $t02001720090._1 |
---|
575 | 575 | | let caller = $t02001720090._2 |
---|
576 | 576 | | let date = $t02001720090._3 |
---|
577 | 577 | | let isSponsored = $t02001720090._4 |
---|
578 | 578 | | if (!(validateHash(sha256Hash))) |
---|
579 | 579 | | then throw("Hash should be 64 characters maximum") |
---|
580 | 580 | | else { |
---|
581 | 581 | | let $t02019120260 = setLIcence(cidLicence, sha256Licence) |
---|
582 | 582 | | let licenceCID = $t02019120260._1 |
---|
583 | 583 | | let licenceHash = $t02019120260._2 |
---|
584 | 584 | | let validateArtwork = validateArtworkData(caller, cidDisplay, cidExport, licenceCID, sha256Export, licenceHash, name, description, tags, royalties) |
---|
585 | 585 | | if ((validateArtwork != "")) |
---|
586 | 586 | | then throw("Something went wrong!") |
---|
587 | 587 | | else { |
---|
588 | 588 | | let whitelisted_drop = (checkWhitelist((caller + "_free_drops")) > 0) |
---|
589 | 589 | | let $t02055920643 = if (whitelisted_drop) |
---|
590 | 590 | | then $Tuple2(0, signID) |
---|
591 | 591 | | else validatePayment(i) |
---|
592 | 592 | | let amount = $t02055920643._1 |
---|
593 | 593 | | let assetId = $t02055920643._2 |
---|
594 | 594 | | if (!(isDefined(amount))) |
---|
595 | 595 | | then throw("Something went wrong") |
---|
596 | 596 | | else { |
---|
597 | 597 | | let entryExist = getStringByKey(keyTxidByHashOwner(sha256Hash, caller)) |
---|
598 | 598 | | if ((entryExist != "")) |
---|
599 | 599 | | then throw("You already added it") |
---|
600 | 600 | | else { |
---|
601 | 601 | | let hashExist = getStringByKey(keyOwnerByHash(sha256Hash)) |
---|
602 | 602 | | if ((hashExist != "")) |
---|
603 | 603 | | then throw("Hash already registered") |
---|
604 | 604 | | else { |
---|
605 | 605 | | let isSignCertified = checkSignCertificate(signID, caller, sha256Hash) |
---|
606 | 606 | | if (!(isSignCertified)) |
---|
607 | 607 | | then throw("Sign Certificate not found for this address.") |
---|
608 | 608 | | else { |
---|
609 | 609 | | let decrease_whitelist_drop = if (whitelisted_drop) |
---|
610 | 610 | | then invoke(whitelistDapp, "useFreeDrop", [caller], nil) |
---|
611 | 611 | | else unit |
---|
612 | 612 | | if ((decrease_whitelist_drop == decrease_whitelist_drop)) |
---|
613 | 613 | | then { |
---|
614 | 614 | | let txToCaller = if (isSponsored) |
---|
615 | 615 | | then [ScriptTransfer(Address(fromBase58String(caller)), 0, unit)] |
---|
616 | 616 | | else nil |
---|
617 | 617 | | ([StringEntry(keyOwnerByHash(sha256Hash), caller), StringEntry(keyTxidByHashOwner(sha256Hash, caller), artId), IntegerEntry(keyDate(caller, artId), date), StringEntry(keyName(caller, artId), name), StringEntry(keyDesc(caller, artId), description), StringEntry(keyDisplayCid(caller, artId), cidDisplay), StringEntry(keyExportCid(caller, artId), cidExport), StringEntry(keyExportHash(caller, artId), sha256Export), StringEntry(keyLicenceHash(caller, artId), licenceHash), StringEntry(keyLicenceCid(caller, artId), licenceCID), StringEntry(keyType(caller, artId), type), StringEntry(keyTags(caller, artId), tags), IntegerEntry(keyMaxMint(caller, artId), 0), StringEntry(keySignID(caller, artId), signID), IntegerEntry(keyIssued(caller, artId), 0), BooleanEntry(keyOnSale(caller, artId), false), StringEntry(keyidBySignid(caller, signID), artId), StringEntry(keyHashByTxidAddr(caller, artId), sha256Hash), StringEntry(keyCrawler(caller, artId), crawler), IntegerEntry(keyRoyalties(caller, artId), royalties), ScriptTransfer(Address(fromBase58String(feeReceiver)), amount, signAssetId)] ++ txToCaller) |
---|
618 | 618 | | } |
---|
619 | 619 | | else throw("Strict value is not equal to itself.") |
---|
620 | 620 | | } |
---|
621 | 621 | | } |
---|
622 | 622 | | } |
---|
623 | 623 | | } |
---|
624 | 624 | | } |
---|
625 | 625 | | } |
---|
626 | 626 | | } |
---|
627 | 627 | | |
---|
628 | 628 | | |
---|
629 | 629 | | |
---|
630 | 630 | | @Callable(i) |
---|
631 | 631 | | func updateArtwork (txid,name,description,tags,type,cidDisplay,sha256Export,cidExport,sha256Licence,cidLicence,crawler,royalties,pubKey) = if (!(dappRunning)) |
---|
632 | 632 | | then throw(maintenanceMSG) |
---|
633 | 633 | | else { |
---|
634 | 634 | | let $t02367723747 = idCallerDateSponsored(i, pubKey) |
---|
635 | 635 | | let id = $t02367723747._1 |
---|
636 | 636 | | let caller = $t02367723747._2 |
---|
637 | 637 | | let date = $t02367723747._3 |
---|
638 | 638 | | let isSponsored = $t02367723747._4 |
---|
639 | 639 | | let $t02375723826 = setLIcence(cidLicence, sha256Licence) |
---|
640 | 640 | | let licenceCID = $t02375723826._1 |
---|
641 | 641 | | let licenceHash = $t02375723826._2 |
---|
642 | 642 | | let validateArtwork = validateArtworkData(caller, cidDisplay, cidExport, licenceCID, sha256Export, licenceHash, name, description, tags, royalties) |
---|
643 | 643 | | if ((validateArtwork != "")) |
---|
644 | 644 | | then throw("Something went wrong!") |
---|
645 | 645 | | else { |
---|
646 | 646 | | let entryExist = getStringByKey(keyName(caller, txid)) |
---|
647 | 647 | | if ((entryExist == "")) |
---|
648 | 648 | | then throw("Entry not found") |
---|
649 | 649 | | else { |
---|
650 | 650 | | let flag = getStringByKey(keyFlag(caller, txid)) |
---|
651 | 651 | | if ((flag == "ILLEGAL")) |
---|
652 | 652 | | then throw("Cannot update ILLEGAL artwork") |
---|
653 | 653 | | else if (!(isArtMinted(caller, txid))) |
---|
654 | 654 | | then { |
---|
655 | 655 | | let txToCaller = if (isSponsored) |
---|
656 | 656 | | then [ScriptTransfer(Address(fromBase58String(caller)), 0, unit)] |
---|
657 | 657 | | else nil |
---|
658 | 658 | | ([StringEntry(keyName(caller, txid), name), StringEntry(keyDesc(caller, txid), description), StringEntry(keyDisplayCid(caller, txid), cidDisplay), StringEntry(keyExportCid(caller, txid), cidExport), StringEntry(keyExportHash(caller, txid), sha256Export), StringEntry(keyLicenceCid(caller, txid), licenceCID), StringEntry(keyLicenceHash(caller, txid), licenceHash), StringEntry(keyTags(caller, txid), tags), StringEntry(keyType(caller, txid), type), StringEntry(keyCrawler(caller, txid), crawler), IntegerEntry(keyRoyalties(caller, txid), royalties)] ++ txToCaller) |
---|
659 | 659 | | } |
---|
660 | 660 | | else throw("Already minted") |
---|
661 | 661 | | } |
---|
662 | 662 | | } |
---|
663 | 663 | | } |
---|
664 | 664 | | |
---|
665 | 665 | | |
---|
666 | 666 | | |
---|
667 | 667 | | @Callable(i) |
---|
668 | 668 | | func flagArtwork (artId,addr,flag,note) = { |
---|
669 | 669 | | let $t02545325487 = idCallerDate(i) |
---|
670 | 670 | | let id = $t02545325487._1 |
---|
671 | 671 | | let caller = $t02545325487._2 |
---|
672 | 672 | | if (containsElement([chris, toString(this)], caller)) |
---|
673 | 673 | | then if (containsElement(["CONSENT", "", "CHANGE_REQUIRED", "FLAGGED", "ILLEGAL"], flag)) |
---|
674 | 674 | | then [StringEntry(keyFlag(addr, artId), flag), StringEntry(keyNote(addr, artId), note)] |
---|
675 | 675 | | else throw(("Unknow status " + flag)) |
---|
676 | 676 | | else throw("You are not allowed") |
---|
677 | 677 | | } |
---|
678 | 678 | | |
---|
679 | 679 | | |
---|
680 | 680 | | |
---|
681 | 681 | | @Callable(i) |
---|
682 | 682 | | func deleteArtwork (artId,addr) = { |
---|
683 | 683 | | let $t02592325957 = idCallerDate(i) |
---|
684 | 684 | | let id = $t02592325957._1 |
---|
685 | 685 | | let caller = $t02592325957._2 |
---|
686 | 686 | | let addrToUse = if (containsElement([chris, toString(this)], caller)) |
---|
687 | 687 | | then addr |
---|
688 | 688 | | else caller |
---|
689 | 689 | | let entryExist = valueOrErrorMessage(getStringByKey(keyName(addrToUse, artId)), "No art matching for this address") |
---|
690 | 690 | | if ((entryExist == "")) |
---|
691 | 691 | | then throw("No art matching for this address") |
---|
692 | 692 | | else { |
---|
693 | 693 | | let sha256Hash = getStringByKey(keyHashByTxidAddr(addrToUse, artId)) |
---|
694 | 694 | | if ((sha256Hash == "")) |
---|
695 | 695 | | then throw("No art hash matching for this address") |
---|
696 | 696 | | else { |
---|
697 | 697 | | let signID = getStringByKey(keySignID(addrToUse, artId)) |
---|
698 | 698 | | if ((signID == "")) |
---|
699 | 699 | | then throw("No SIGN ID matching") |
---|
700 | 700 | | else { |
---|
701 | 701 | | let dataToDelete = [DeleteEntry(keyDate(addrToUse, artId)), DeleteEntry(keyName(addrToUse, artId)), DeleteEntry(keyDesc(addrToUse, artId)), DeleteEntry(keyDisplayCid(addrToUse, artId)), DeleteEntry(keyExportCid(addrToUse, artId)), DeleteEntry(keyExportHash(addrToUse, artId)), DeleteEntry(keyLicenceHash(addrToUse, artId)), DeleteEntry(keyLicenceCid(addrToUse, artId)), DeleteEntry(keyType(addrToUse, artId)), DeleteEntry(keyTags(addrToUse, artId)), DeleteEntry(keyMaxMint(addrToUse, artId)), DeleteEntry(keySignID(addrToUse, artId)), DeleteEntry(keyIssued(addrToUse, artId)), DeleteEntry(keyOnSale(addrToUse, artId)), DeleteEntry(keyFlag(addrToUse, artId)), DeleteEntry(keyPrice(addrToUse, artId)), DeleteEntry(keyAssetIdAccepted(addrToUse, artId)), DeleteEntry(keyOwnerByHash(sha256Hash)), DeleteEntry(keyidBySignid(addrToUse, signID)), DeleteEntry(keyTxidByHashOwner(sha256Hash, addrToUse)), DeleteEntry(keyEndSale(addrToUse, artId)), DeleteEntry(keyNote(addrToUse, artId)), DeleteEntry(keyCrawler(addrToUse, artId)), DeleteEntry(keyRoyalties(addrToUse, artId))] |
---|
702 | 702 | | if (!(isArtMinted(addrToUse, artId))) |
---|
703 | 703 | | then if (!(dappRunning)) |
---|
704 | 704 | | then throw(maintenanceMSG) |
---|
705 | 705 | | else dataToDelete |
---|
706 | 706 | | else if (containsElement([chris, toString(this)], caller)) |
---|
707 | 707 | | then dataToDelete |
---|
708 | 708 | | else throw("Art already minted, you cannot delete it") |
---|
709 | 709 | | } |
---|
710 | 710 | | } |
---|
711 | 711 | | } |
---|
712 | 712 | | } |
---|
713 | 713 | | |
---|
714 | 714 | | |
---|
715 | 715 | | |
---|
716 | 716 | | @Callable(i) |
---|
717 | 717 | | func sellArtwork (artId,price,maxMint,assetId,blockEnd,pubKey) = { |
---|
718 | 718 | | let $t02879328863 = idCallerDateSponsored(i, pubKey) |
---|
719 | 719 | | let id = $t02879328863._1 |
---|
720 | 720 | | let caller = $t02879328863._2 |
---|
721 | 721 | | let date = $t02879328863._3 |
---|
722 | 722 | | let isSponsored = $t02879328863._4 |
---|
723 | 723 | | let artworkName = getStringByKey(keyName(caller, artId)) |
---|
724 | 724 | | if ((artworkName == "")) |
---|
725 | 725 | | then throw("This art doesn't match your account") |
---|
726 | 726 | | else { |
---|
727 | 727 | | let flag = getStringByKey(keyFlag(caller, artId)) |
---|
728 | 728 | | if (containsElement(["CHANGE_REQUIRED", "FLAGGED", "ILLEGAL"], flag)) |
---|
729 | 729 | | then throw("Flagged artwork") |
---|
730 | 730 | | else { |
---|
731 | 731 | | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
732 | 732 | | if ((0 > blockEnd)) |
---|
733 | 733 | | then throw("Negative end") |
---|
734 | 734 | | else if (if ((blockEnd > 0)) |
---|
735 | 735 | | then if ((maxMint != 1)) |
---|
736 | 736 | | then true |
---|
737 | 737 | | else (price != 0) |
---|
738 | 738 | | else false) |
---|
739 | 739 | | then throw("Timed offer only allowed for unique edition and offer only") |
---|
740 | 740 | | else { |
---|
741 | 741 | | let baseHeight = if ((blockEnd == 0)) |
---|
742 | 742 | | then 0 |
---|
743 | 743 | | else height |
---|
744 | 744 | | if (!(acceptedAssetIds(assetId))) |
---|
745 | 745 | | then throw("Something went wrong!") |
---|
746 | 746 | | else if (!(validateMinSell(assetId, price))) |
---|
747 | 747 | | then throw("Something went wrong!") |
---|
748 | 748 | | else { |
---|
749 | 749 | | let checkUser = validateUser(caller) |
---|
750 | 750 | | if ((checkUser != "")) |
---|
751 | 751 | | then throw(checkUser) |
---|
752 | 752 | | else { |
---|
753 | 753 | | let amountSold = getIntegerByKey(keyIssued(caller, artId)) |
---|
754 | 754 | | let maxCanSell = getIntegerByKey(keyMaxMint(caller, artId)) |
---|
755 | 755 | | if ((maxMint > 100)) |
---|
756 | 756 | | then throw("100 editions max per artwork") |
---|
757 | 757 | | else if (if ((amountSold != 0)) |
---|
758 | 758 | | then (amountSold == maxCanSell) |
---|
759 | 759 | | else false) |
---|
760 | 760 | | then throw("Max edition reached.") |
---|
761 | 761 | | else if (if ((amountSold > 0)) |
---|
762 | 762 | | then (maxCanSell != maxMint) |
---|
763 | 763 | | else false) |
---|
764 | 764 | | then throw("Cannot change maximum issuable anymore") |
---|
765 | 765 | | else if (if ((bidNbr > 0)) |
---|
766 | 766 | | then (maxCanSell != maxMint) |
---|
767 | 767 | | else false) |
---|
768 | 768 | | then throw("Cannot change maximum issuable with active orders") |
---|
769 | 769 | | else { |
---|
770 | 770 | | let sellStatus = if (if ((price > 0)) |
---|
771 | 771 | | then (maxMint > 0) |
---|
772 | 772 | | else false) |
---|
773 | 773 | | then true |
---|
774 | 774 | | else false |
---|
775 | 775 | | let txToCaller = if (isSponsored) |
---|
776 | 776 | | then [ScriptTransfer(Address(fromBase58String(caller)), 0, unit)] |
---|
777 | 777 | | else nil |
---|
778 | 778 | | ([BooleanEntry(keyOnSale(caller, artId), sellStatus), IntegerEntry(keyPrice(caller, artId), price), IntegerEntry(keyMaxMint(caller, artId), maxMint), StringEntry(keyAssetIdAccepted(caller, artId), assetId), IntegerEntry(keyEndSale(caller, artId), (baseHeight + blockEnd))] ++ txToCaller) |
---|
779 | 779 | | } |
---|
780 | 780 | | } |
---|
781 | 781 | | } |
---|
782 | 782 | | } |
---|
783 | 783 | | } |
---|
784 | 784 | | } |
---|
785 | 785 | | } |
---|
786 | 786 | | |
---|
787 | 787 | | |
---|
788 | 788 | | |
---|
789 | 789 | | @Callable(i) |
---|
790 | 790 | | func buyArtwork (artId,issuer) = buyMint(i, artId, issuer, "", "", "") |
---|
791 | 791 | | |
---|
792 | 792 | | |
---|
793 | 793 | | |
---|
794 | 794 | | @Callable(i) |
---|
795 | 795 | | func setBid (artId,issuer) = { |
---|
796 | 796 | | let $t03124531285 = idCallerDate(i) |
---|
797 | 797 | | let id = $t03124531285._1 |
---|
798 | 798 | | let caller = $t03124531285._2 |
---|
799 | 799 | | let date = $t03124531285._3 |
---|
800 | 800 | | let $t03129031326 = isPayment(i) |
---|
801 | 801 | | let payment = $t03129031326._1 |
---|
802 | 802 | | let amount = $t03129031326._2 |
---|
803 | 803 | | let assetId = if (!(isDefined(payment.assetId))) |
---|
804 | 804 | | then "WAVES" |
---|
805 | 805 | | else toBase58String(value(payment.assetId)) |
---|
806 | 806 | | let blockEnd = getIntegerByKey(keyEndSale(issuer, artId)) |
---|
807 | 807 | | if (if ((blockEnd != 0)) |
---|
808 | 808 | | then (height >= blockEnd) |
---|
809 | 809 | | else false) |
---|
810 | 810 | | then throw("Sale ended.") |
---|
811 | 811 | | else { |
---|
812 | 812 | | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
813 | 813 | | if (!(acceptedAssetIds(assetId))) |
---|
814 | 814 | | then throw("asset not accepted") |
---|
815 | 815 | | else if (!(validateMinSell(assetId, amount))) |
---|
816 | 816 | | then throw("Wrong min sell") |
---|
817 | 817 | | else { |
---|
818 | 818 | | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
819 | 819 | | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
820 | 820 | | if ((0 >= maxCanSell)) |
---|
821 | 821 | | then throw("No max edition set for this artwork") |
---|
822 | 822 | | else if ((amountSold >= maxCanSell)) |
---|
823 | 823 | | then throw("Sold out, you cannot bid") |
---|
824 | 824 | | else [StringEntry((((((((("bid_" + artId) + "_") + issuer) + "_") + caller) + "_") + id) + "_OPEN"), ((((assetId + "_") + toString(amount)) + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr + 1))] |
---|
825 | 825 | | } |
---|
826 | 826 | | } |
---|
827 | 827 | | } |
---|
828 | 828 | | |
---|
829 | 829 | | |
---|
830 | 830 | | |
---|
831 | 831 | | @Callable(i) |
---|
832 | 832 | | func acceptBid (artId,issuer,bidId,bidOwner,pubKey) = { |
---|
833 | 833 | | let $t03250032623 = idCallerDate(i) |
---|
834 | 834 | | let id = $t03250032623._1 |
---|
835 | 835 | | let caller = $t03250032623._2 |
---|
836 | 836 | | let date = $t03250032623._3 |
---|
837 | 837 | | if ((caller != issuer)) |
---|
838 | 838 | | then throw("You cannot do this action") |
---|
839 | 839 | | else buyMint(i, artId, issuer, bidId, bidOwner, pubKey) |
---|
840 | 840 | | } |
---|
841 | 841 | | |
---|
842 | 842 | | |
---|
843 | 843 | | |
---|
844 | 844 | | @Callable(i) |
---|
845 | 845 | | func cancelBid (artId,issuer,bidId,bidOwner) = { |
---|
846 | 846 | | let $t03285732918 = idCallerDate(i) |
---|
847 | 847 | | let id = $t03285732918._1 |
---|
848 | 848 | | let caller = $t03285732918._2 |
---|
849 | 849 | | let date = $t03285732918._3 |
---|
850 | 850 | | if (if ((caller != bidOwner)) |
---|
851 | 851 | | then (caller != issuer) |
---|
852 | 852 | | else false) |
---|
853 | 853 | | then throw("You cannot do this action") |
---|
854 | 854 | | else { |
---|
855 | 855 | | let returnMoneyTo = if ((caller == issuer)) |
---|
856 | 856 | | then bidOwner |
---|
857 | 857 | | else caller |
---|
858 | 858 | | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
859 | 859 | | let bidDataKey = ((((((("bid_" + artId) + "_") + issuer) + "_") + bidOwner) + "_") + bidId) |
---|
860 | 860 | | let bidData = getStringByKey((bidDataKey + "_OPEN")) |
---|
861 | 861 | | if ((bidData == "")) |
---|
862 | 862 | | then throw("Bid not found") |
---|
863 | 863 | | else { |
---|
864 | 864 | | let bidDataArr = split(bidData, "_") |
---|
865 | 865 | | let assetId = getBidAssetId(bidDataArr[0]) |
---|
866 | 866 | | let bidStatus = "CANCELED" |
---|
867 | 867 | | [DeleteEntry((bidDataKey + "_OPEN")), StringEntry(((bidDataKey + "_") + bidStatus), ((bidData + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr - 1)), ScriptTransfer(Address(fromBase58String(returnMoneyTo)), parseIntValue(bidDataArr[1]), assetId)] |
---|
868 | 868 | | } |
---|
869 | 869 | | } |
---|
870 | 870 | | } |
---|
871 | 871 | | |
---|
872 | 872 | | |
---|
873 | 873 | | @Verifier(tx) |
---|
874 | 874 | | func verifier () = match tx { |
---|
875 | 875 | | case inv: InvokeScriptTransaction => |
---|
876 | 876 | | if (if (if (if ((inv.function == "addArtwork")) |
---|
877 | 877 | | then (inv.dApp == this) |
---|
878 | 878 | | else false) |
---|
879 | 879 | | then (inv.fee == 500000) |
---|
880 | 880 | | else false) |
---|
881 | 881 | | then (inv.feeAssetId == unit) |
---|
882 | 882 | | else false) |
---|
883 | 883 | | then sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(asString(inv.args[13]))) |
---|
884 | 884 | | else if (if (if (if ((inv.function == "updateArtwork")) |
---|
885 | 885 | | then (inv.dApp == this) |
---|
886 | 886 | | else false) |
---|
887 | 887 | | then (inv.fee == 500000) |
---|
888 | 888 | | else false) |
---|
889 | 889 | | then (inv.feeAssetId == unit) |
---|
890 | 890 | | else false) |
---|
891 | 891 | | then sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(asString(inv.args[12]))) |
---|
892 | 892 | | else if (if (if (if ((inv.function == "sellArtwork")) |
---|
893 | 893 | | then (inv.dApp == this) |
---|
894 | 894 | | else false) |
---|
895 | 895 | | then (inv.fee == 500000) |
---|
896 | 896 | | else false) |
---|
897 | 897 | | then (inv.feeAssetId == unit) |
---|
898 | 898 | | else false) |
---|
899 | 899 | | then sigVerify(tx.bodyBytes, tx.proofs[0], fromBase58String(asString(inv.args[5]))) |
---|
900 | 900 | | else if (if (if (if ((inv.function == "acceptBid")) |
---|
901 | 901 | | then (inv.dApp == this) |
---|
902 | 902 | | else false) |
---|
903 | 903 | | then (inv.fee == 500000) |
---|
904 | 904 | | else false) |
---|
905 | 905 | | then (inv.feeAssetId == unit) |
---|
906 | 906 | | else false) |
---|
907 | 907 | | then sigVerify_128Kb(tx.bodyBytes, tx.proofs[0], fromBase58String(asString(inv.args[4]))) |
---|
908 | 908 | | else sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
909 | 909 | | case _ => |
---|
910 | 910 | | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
911 | 911 | | } |
---|
912 | 912 | | |
---|