258 | | - | func validateMinSell (assetId,price) = { |
---|
259 | | - | let minSellSconex = if (unitTest) |
---|
260 | | - | then 1 |
---|
261 | | - | else (currentCertificationPrice * 2) |
---|
262 | | - | if (if (if ((assetId == toBase58String(USDNAssetId))) |
---|
263 | | - | then (minSellSconex > price) |
---|
264 | | - | else false) |
---|
265 | | - | then (price != 0) |
---|
266 | | - | else false) |
---|
267 | | - | then throw(("Wrong minimum sell price " + toString(minSellSconex))) |
---|
268 | | - | else true |
---|
269 | | - | } |
---|
270 | | - | |
---|
271 | | - | |
---|
272 | | - | func getBidAssetId (assetId) = if ((assetId == "WAVES")) |
---|
273 | | - | then throw("Only USDN is accepted!") |
---|
274 | | - | else fromBase58String(assetId) |
---|
275 | | - | |
---|
276 | | - | |
---|
277 | | - | func getPriceAssetIdFromBid (bidDataKey) = { |
---|
278 | | - | let bidData = getStringByKey((bidDataKey + "_OPEN")) |
---|
279 | | - | if ((bidData == "")) |
---|
280 | | - | then throw("Bid not found") |
---|
281 | | - | else { |
---|
282 | | - | let bidDataArr = split(bidData, "_") |
---|
283 | | - | let bidAmount = parseIntValue(bidDataArr[1]) |
---|
284 | | - | let bidAssetId = getBidAssetId(bidDataArr[0]) |
---|
285 | | - | if ((0 >= bidAmount)) |
---|
286 | | - | then throw("Wrong amount") |
---|
287 | | - | else $Tuple2(bidAmount, bidAssetId) |
---|
288 | | - | } |
---|
289 | | - | } |
---|
290 | | - | |
---|
291 | | - | |
---|
292 | | - | func idCallerDate (i) = if (!(dappRunning)) |
---|
293 | | - | then throw(maintenanceMSG) |
---|
294 | | - | else $Tuple3(toBase58String(i.transactionId), toBase58String(i.caller.bytes), lastBlock.timestamp) |
---|
295 | | - | |
---|
296 | | - | |
---|
297 | | - | func getArtData (i,issuer,artId,isBid) = { |
---|
298 | | - | let callerIsIssuer = (toBase58String(i.caller.bytes) == issuer) |
---|
299 | | - | let totalNFT = getIntegerByKey("total_nft_issued") |
---|
300 | | - | let artworkName = getStringByKey(keyName(issuer, artId)) |
---|
301 | | - | if ((artworkName == "")) |
---|
302 | | - | then throw("Art doesn't exist") |
---|
303 | | - | else { |
---|
304 | | - | let isOnSale = getBooleanByKey(keyOnSale(issuer, artId)) |
---|
305 | | - | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
306 | | - | let artworkPrice = valueOrElse(getIntegerByKey(keyPrice(issuer, artId)), (currentCertificationPrice * 2)) |
---|
307 | | - | let priceAssetId = if (callerIsIssuer) |
---|
308 | | - | then toBase58String(USDNAssetId) |
---|
309 | | - | else getStringByKey(keyAssetIdAccepted(issuer, artId)) |
---|
310 | | - | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
311 | | - | if (if (if (!(isBid)) |
---|
312 | | - | then !(callerIsIssuer) |
---|
313 | | - | else false) |
---|
314 | | - | then if (if ((0 >= artworkPrice)) |
---|
315 | | - | then true |
---|
316 | | - | else !(isOnSale)) |
---|
317 | | - | then true |
---|
318 | | - | else (0 >= maxCanSell) |
---|
319 | | - | else false) |
---|
320 | | - | then throw("Art not for sale") |
---|
321 | | - | else if (if (if (!(isBid)) |
---|
322 | | - | then callerIsIssuer |
---|
323 | | - | else false) |
---|
324 | | - | then (0 >= maxCanSell) |
---|
325 | | - | else false) |
---|
326 | | - | then throw("Max issuable not set") |
---|
327 | | - | else $Tuple7(totalNFT, artworkName, amountSold, artworkPrice, priceAssetId, maxCanSell, isOnSale) |
---|
328 | | - | } |
---|
329 | | - | } |
---|
330 | | - | |
---|
331 | | - | |
---|
332 | | - | func getBidData (i,caller,issuer,artId,bidOwner,bidId,priceAssetId,artworkPrice,isBid) = { |
---|
333 | | - | let checkUser = validateUser(issuer) |
---|
334 | | - | if (if (isBid) |
---|
335 | | - | then (checkUser != "") |
---|
336 | | - | else false) |
---|
337 | | - | then throw(checkUser) |
---|
338 | | - | else { |
---|
339 | | - | let bidDataKey = ((((((("bid_" + artId) + "_") + issuer) + "_") + bidOwner) + "_") + bidId) |
---|
340 | | - | let t01351913648 = if (isBid) |
---|
341 | | - | then getPriceAssetIdFromBid(bidDataKey) |
---|
342 | | - | else validatePriceAssetId(i, priceAssetId, artworkPrice) |
---|
343 | | - | let amount = t01351913648._1 |
---|
344 | | - | let assetId = t01351913648._2 |
---|
345 | | - | $Tuple3(bidDataKey, amount, assetId) |
---|
346 | | - | } |
---|
347 | | - | } |
---|
348 | | - | |
---|
349 | | - | |
---|
350 | | - | func getCommissionData (issuer,assetId,amount,amountSold,maxCanSell) = { |
---|
351 | | - | let isWhitelisted = checkWhitelist(issuer) |
---|
352 | | - | let cut = if ((isWhitelisted > height)) |
---|
353 | | - | then 0 |
---|
354 | | - | else if ((assetId == USDNAssetId)) |
---|
355 | | - | then USDNFirstSellCut |
---|
356 | | - | else throw("Only USDN is accepted!") |
---|
357 | | - | let amountForSconex = fraction(amount, cut, 1000) |
---|
358 | | - | let amountForCreator = (amount - amountForSconex) |
---|
359 | | - | if ((amountSold == maxCanSell)) |
---|
360 | | - | then throw("Art sold out") |
---|
361 | | - | else { |
---|
362 | | - | let newAmountSold = (amountSold + 1) |
---|
363 | | - | $Tuple3(amountForSconex, amountForCreator, newAmountSold) |
---|
364 | | - | } |
---|
365 | | - | } |
---|
366 | | - | |
---|
367 | | - | |
---|
368 | | - | func getIssueData (issuer,artId,artworkName,newAmountSold,maxCanSell,totalNFT,caller,bidOwner,bidId,i,isOnSale) = { |
---|
369 | | - | let issueMeta = ((((((((("Creator: " + issuer) + ",ArtID: ") + artId) + ",Artwork name: ") + artworkName) + ",Issue: ") + toString(newAmountSold)) + "/") + toString(maxCanSell)) |
---|
370 | | - | let sellStatus = if (if ((newAmountSold == maxCanSell)) |
---|
371 | | - | then true |
---|
372 | | - | else !(isOnSale)) |
---|
373 | | - | then false |
---|
374 | | - | else true |
---|
375 | | - | let receiveNFT = if ((bidOwner != "")) |
---|
376 | | - | then addressFromStringValue(bidOwner) |
---|
377 | | - | else i.caller |
---|
378 | | - | $Tuple3(sellStatus, receiveNFT, issueMeta) |
---|
379 | | - | } |
---|
380 | | - | |
---|
381 | | - | |
---|
382 | | - | func calculateRarity (mintIndex) = if ((4 > mintIndex)) |
---|
383 | | - | then "SSR" |
---|
384 | | - | else if ((11 > mintIndex)) |
---|
385 | | - | then "SR" |
---|
386 | | - | else if ((101 > mintIndex)) |
---|
387 | | - | then "R" |
---|
388 | | - | else "N" |
---|
389 | | - | |
---|
390 | | - | |
---|
391 | | - | func getBidKeyVal (assetId,bidDataKey,date) = { |
---|
392 | | - | let assetIdBid = if (!(isDefined(assetId))) |
---|
393 | | - | then throw("Only USDN is accepted") |
---|
394 | | - | else toBase58String(value(assetId)) |
---|
395 | | - | let bidData = getStringByKey((bidDataKey + "_OPEN")) |
---|
396 | | - | let bidDelOld = DeleteEntry((bidDataKey + "_OPEN")) |
---|
397 | | - | let bidUpdate = StringEntry((bidDataKey + "_CLOSED"), ((bidData + "_") + toString(date))) |
---|
398 | | - | $Tuple3(assetIdBid, bidDelOld, bidUpdate) |
---|
399 | | - | } |
---|
400 | | - | |
---|
401 | | - | |
---|
402 | | - | func buyMint (i,artId,issuer,bidId,bidOwner,isBid) = { |
---|
403 | | - | let callerData = idCallerDate(i) |
---|
404 | | - | let id = callerData._1 |
---|
405 | | - | let caller = callerData._2 |
---|
406 | | - | let date = callerData._3 |
---|
407 | | - | let artData = getArtData(i, issuer, artId, isBid) |
---|
408 | | - | let totalNFT = artData._1 |
---|
409 | | - | let artworkName = artData._2 |
---|
410 | | - | let amountSold = artData._3 |
---|
411 | | - | let artworkPrice = artData._4 |
---|
412 | | - | let priceAssetId = artData._5 |
---|
413 | | - | let maxCanSell = artData._6 |
---|
414 | | - | let isOnSale = artData._7 |
---|
415 | | - | let bidData = getBidData(i, caller, issuer, artId, bidOwner, bidId, priceAssetId, artworkPrice, isBid) |
---|
416 | | - | let bidDataKey = bidData._1 |
---|
417 | | - | let amount = bidData._2 |
---|
418 | | - | let assetId = bidData._3 |
---|
419 | | - | let commisionData = getCommissionData(issuer, value(assetId), amount, amountSold, maxCanSell) |
---|
420 | | - | let amountForSconex = commisionData._1 |
---|
421 | | - | let amountForCreator = commisionData._2 |
---|
422 | | - | let newAmountSold = commisionData._3 |
---|
423 | | - | let issuerData = getIssueData(issuer, artId, artworkName, newAmountSold, maxCanSell, totalNFT, caller, bidOwner, bidId, i, isOnSale) |
---|
424 | | - | let sellStatus = issuerData._1 |
---|
425 | | - | let receiveNFT = issuerData._2 |
---|
426 | | - | let issueMeta = issuerData._3 |
---|
427 | | - | let idNFTInvoke = invoke(this, "mintNft", [totalNFT, issueMeta, toString(receiveNFT)], nil) |
---|
428 | | - | if ((idNFTInvoke == idNFTInvoke)) |
---|
429 | | - | then { |
---|
430 | | - | let idNFT = match idNFTInvoke { |
---|
431 | | - | case r: String => |
---|
432 | | - | r |
---|
433 | | - | case _ => |
---|
434 | | - | throw("Incorrect invoke result") |
---|
435 | | - | } |
---|
436 | | - | let bidKeyValue = getBidKeyVal(assetId, bidDataKey, date) |
---|
437 | | - | let assetIdBid = bidKeyValue._1 |
---|
438 | | - | let bidDelOld = bidKeyValue._2 |
---|
439 | | - | let bidUpdate = bidKeyValue._3 |
---|
440 | | - | let soldKey = ((((((("art_sold_" + toString(newAmountSold)) + "_of_") + toString(maxCanSell)) + "_") + artId) + "_") + issuer) |
---|
441 | | - | let rarity = calculateRarity(newAmountSold) |
---|
442 | | - | let soldValue = if (!(isBid)) |
---|
443 | | - | then ((((((((((caller + "_") + toString(date)) + "_") + id) + "_") + toString(artworkPrice)) + "_") + priceAssetId) + "_") + idNFT) |
---|
444 | | - | else ((((((((((toString(receiveNFT) + "_") + toString(date)) + "_") + id) + "_") + toString(amount)) + "_") + assetIdBid) + "_") + idNFT) |
---|
445 | | - | let soldData = StringEntry(soldKey, soldValue) |
---|
446 | | - | let buyRes = [IntegerEntry(keyIssued(issuer, artId), newAmountSold), StringEntry(("nft_" + idNFT), soldKey), StringEntry(("nft_rarity_" + idNFT), rarity), IntegerEntry("total_nft_issued", (totalNFT + 1)), BooleanEntry(keyOnSale(issuer, artId), sellStatus), ScriptTransfer(Address(fromBase58String(issuer)), amountForCreator, assetId), ScriptTransfer(Address(fromBase58String(feeReceiver)), amountForSconex, assetId), StringEntry(KeyNftIssuer(idNFT), issuer), StringEntry(KeyNftArtId(idNFT), artId)] |
---|
447 | | - | let res = invoke(addressFromStringValue(certDapp), "createCert", [toString(receiveNFT), idNFT, issuer], nil) |
---|
448 | | - | if ((res == res)) |
---|
449 | | - | then if (isBid) |
---|
450 | | - | then (((buyRes :+ soldData) :+ bidUpdate) :+ bidDelOld) |
---|
451 | | - | else soldData :: buyRes |
---|
452 | | - | else throw("Strict value is not equal to itself.") |
---|
453 | | - | } |
---|
454 | | - | else throw("Strict value is not equal to itself.") |
---|
455 | | - | } |
---|
456 | | - | |
---|
457 | | - | |
---|
458 | | - | func setBidNonTraditional (i,artId,issuer) = { |
---|
459 | | - | let t02770927747 = idCallerDate(i) |
---|
460 | | - | let id = t02770927747._1 |
---|
461 | | - | let caller = t02770927747._2 |
---|
462 | | - | let date = t02770927747._3 |
---|
463 | | - | let t02775227788 = isPayment(i) |
---|
464 | | - | let payment = t02775227788._1 |
---|
465 | | - | let amount = t02775227788._2 |
---|
466 | | - | let assetId = if (!(isDefined(payment.assetId))) |
---|
467 | | - | then throw("Only USDN is accepted!") |
---|
468 | | - | else toBase58String(value(payment.assetId)) |
---|
469 | | - | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
470 | | - | let minArtworkPrice = valueOrElse(getIntegerByKey(keyPrice(issuer, artId)), (currentCertificationPrice * 2)) |
---|
471 | | - | if (!(acceptedAssetIds(assetId))) |
---|
472 | | - | then throw("asset not accepted") |
---|
473 | | - | else { |
---|
474 | | - | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
475 | | - | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
476 | | - | if ((0 >= maxCanSell)) |
---|
477 | | - | then throw("No max edition set for this artwork") |
---|
478 | | - | else if ((amountSold >= maxCanSell)) |
---|
479 | | - | then throw("Sold out, you cannot bid") |
---|
480 | | - | else [StringEntry((((((((("bid_" + artId) + "_") + issuer) + "_") + caller) + "_") + id) + "_OPEN"), ((((assetId + "_") + toString(amount)) + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr + 1))] |
---|
481 | | - | } |
---|
482 | | - | } |
---|
483 | | - | |
---|
484 | | - | |
---|
485 | | - | func setBidTraditional (i,artId,issuer) = { |
---|
486 | | - | let endHeight = getIntegerByKey(keyEndHeight(issuer, artId)) |
---|
487 | | - | let highestBid = getAmountHighestBidByArtId(artId) |
---|
488 | | - | if ((height > endHeight)) |
---|
489 | | - | then throw("This auction is finished already!") |
---|
490 | | - | else { |
---|
491 | | - | let callderData = idCallerDate(i) |
---|
492 | | - | let id = callderData._1 |
---|
493 | | - | let caller = callderData._2 |
---|
494 | | - | let date = callderData._3 |
---|
495 | | - | let isPaymentVar = isPayment(i) |
---|
496 | | - | let payment = isPaymentVar._1 |
---|
497 | | - | let amount = isPaymentVar._2 |
---|
498 | | - | if ((highestBid >= amount)) |
---|
499 | | - | then throw(("Please place a bid higher than: " + toString(highestBid))) |
---|
500 | | - | else { |
---|
501 | | - | let assetId = if (!(isDefined(payment.assetId))) |
---|
502 | | - | then throw("Only USDN is accepted!") |
---|
503 | | - | else toBase58String(value(payment.assetId)) |
---|
504 | | - | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
505 | | - | let minArtworkPrice = valueOrElse(getIntegerByKey(keyPrice(issuer, artId)), (currentCertificationPrice * 2)) |
---|
506 | | - | if (!(acceptedAssetIds(assetId))) |
---|
507 | | - | then throw("asset not accepted") |
---|
508 | | - | else if ((minArtworkPrice > amount)) |
---|
509 | | - | then throw("Bid is below min price!") |
---|
510 | | - | else { |
---|
511 | | - | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
512 | | - | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
513 | | - | if ((0 >= maxCanSell)) |
---|
514 | | - | then throw("No max edition set for this artwork") |
---|
515 | | - | else if ((amountSold >= maxCanSell)) |
---|
516 | | - | then throw("Sold out, you cannot bid") |
---|
517 | | - | else [StringEntry((((((((("bid_" + artId) + "_") + issuer) + "_") + caller) + "_") + id) + "_OPEN"), ((((assetId + "_") + toString(amount)) + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr + 1)), StringEntry(keyHighestBidBidId(artId), toBase58String(i.transactionId)), IntegerEntry(keyBidId(toBase58String(i.transactionId)), amount)] |
---|
518 | | - | } |
---|
519 | | - | } |
---|
520 | | - | } |
---|
521 | | - | } |
---|
522 | | - | |
---|
523 | | - | |
---|
524 | | - | func acceptBidNonTraditional (i,artId,issuer,bidId,bidOwner) = { |
---|
525 | | - | let caller = toBase58String(i.caller.bytes) |
---|
526 | | - | if ((caller != issuer)) |
---|
527 | | - | then throw("You cannot do this action") |
---|
528 | | - | else buyMint(i, artId, issuer, bidId, bidOwner, true) |
---|
529 | | - | } |
---|
530 | | - | |
---|
531 | | - | |
---|
532 | | - | func restartAuction (artId,issuer) = { |
---|
533 | | - | let amountSold = getIntegerByKey(keyIssued(issuer, artId)) |
---|
534 | | - | let maxCanSell = getIntegerByKey(keyMaxMint(issuer, artId)) |
---|
535 | | - | let oldEndHeight = getIntegerByKey(keyEndHeight(issuer, artId)) |
---|
536 | | - | let duration = getIntegerByKey(keyDuration(issuer, artId)) |
---|
537 | | - | let endHeight = (duration + height) |
---|
538 | | - | if ((height > oldEndHeight)) |
---|
539 | | - | then if ((amountSold == maxCanSell)) |
---|
540 | | - | then throw("Can't restart auction, max amount sold") |
---|
541 | | - | else [IntegerEntry(keyEndHeight(issuer, artId), endHeight), DeleteEntry(keyHighestBidBidId(artId))] |
---|
542 | | - | else throw("Previous auction isn't completed yet") |
---|
543 | | - | } |
---|
544 | | - | |
---|
545 | | - | |
---|
546 | | - | func acceptBidTraditional (i,artId,issuer,bidId,bidOwner) = { |
---|
547 | | - | let endHeight = getIntegerByKey(keyEndHeight(issuer, artId)) |
---|
548 | | - | let highestBidId = getStringByKey(keyHighestBidBidId(artId)) |
---|
549 | | - | if ((height > endHeight)) |
---|
550 | | - | then if ((bidId == highestBidId)) |
---|
551 | | - | then { |
---|
552 | | - | let buyMintData = buyMint(i, artId, issuer, bidId, bidOwner, true) |
---|
553 | | - | let restartAuctionData = restartAuction(artId, issuer) |
---|
554 | | - | (restartAuctionData ++ buyMintData) |
---|
555 | | - | } |
---|
556 | | - | else throw("This is not the winning bid!") |
---|
557 | | - | else throw("This auction is not yet finished!") |
---|
558 | | - | } |
---|
559 | | - | |
---|
560 | | - | |
---|
561 | | - | func cancelBidImpl (i,artId,issuer,bidId) = { |
---|
562 | | - | let t02894229094 = idCallerDate(i) |
---|
563 | | - | let id = t02894229094._1 |
---|
564 | | - | let caller = t02894229094._2 |
---|
565 | | - | let date = t02894229094._3 |
---|
566 | | - | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
567 | | - | let bidDataKey = ((((((("bid_" + artId) + "_") + issuer) + "_") + caller) + "_") + bidId) |
---|
568 | | - | let bidData = getStringByKeyOrError((bidDataKey + "_OPEN"), "Bid not found") |
---|
569 | | - | let bidDataArr = split(bidData, "_") |
---|
570 | | - | let assetId = getBidAssetId(bidDataArr[0]) |
---|
571 | | - | let bidStatus = "CANCELED" |
---|
572 | | - | [DeleteEntry((bidDataKey + "_OPEN")), StringEntry(((bidDataKey + "_") + bidStatus), ((bidData + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr - 1)), ScriptTransfer(Address(fromBase58String(caller)), parseIntValue(bidDataArr[1]), assetId)] |
---|
573 | | - | } |
---|
574 | | - | |
---|
575 | | - | |
---|
576 | | - | func cancelBidImplTraditional (i,artId,issuer,bidId) = { |
---|
577 | | - | let t02894229094 = idCallerDate(i) |
---|
578 | | - | let id = t02894229094._1 |
---|
579 | | - | let caller = t02894229094._2 |
---|
580 | | - | let date = t02894229094._3 |
---|
581 | | - | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
582 | | - | let bidDataKey = ((((((("bid_" + artId) + "_") + issuer) + "_") + caller) + "_") + bidId) |
---|
583 | | - | let bidData = getStringByKeyOrError((bidDataKey + "_OPEN"), "Bid not found") |
---|
584 | | - | let bidDataArr = split(bidData, "_") |
---|
585 | | - | let assetId = getBidAssetId(bidDataArr[0]) |
---|
586 | | - | let bidStatus = "CANCELED" |
---|
587 | | - | let bidAmount = parseIntValue(bidDataArr[1]) |
---|
588 | | - | let highestBidId = getStringByKey(keyHighestBidBidId(artId)) |
---|
589 | | - | if ((bidId == highestBidId)) |
---|
590 | | - | then throw("You can't cancel the highest bid!") |
---|
591 | | - | else [DeleteEntry((bidDataKey + "_OPEN")), StringEntry(((bidDataKey + "_") + bidStatus), ((bidData + "_") + toString(date))), IntegerEntry(("current_bidamount_" + artId), (bidNbr - 1)), ScriptTransfer(Address(fromBase58String(caller)), bidAmount, assetId)] |
---|
592 | | - | } |
---|
593 | | - | |
---|
594 | | - | |
---|
595 | | - | @Callable(i) |
---|
596 | | - | func mintNft (totalNFT,issueMeta,receiveNFT) = if ((i.caller == this)) |
---|
597 | | - | then { |
---|
598 | | - | let receiveNFTAddy = Address(fromBase58String(receiveNFT)) |
---|
599 | | - | let issueNFT = Issue(("SCONEX_" + toString((totalNFT + 1))), issueMeta, 1, 0, false) |
---|
600 | | - | let idNFT = calculateAssetId(issueNFT) |
---|
601 | | - | $Tuple2([issueNFT, ScriptTransfer(receiveNFTAddy, 1, idNFT)], toBase58String(idNFT)) |
---|
602 | | - | } |
---|
603 | | - | else throw("Only the dApp can mint NFT's") |
---|
604 | | - | |
---|
605 | | - | |
---|
606 | | - | |
---|
607 | | - | @Callable(i) |
---|
608 | | - | func addArtwork (sha256Hash,name,description,tags,type,cidDisplay,entitlement,preview,collection,subcollection) = { |
---|
609 | | - | let t01774017781 = idCallerDate(i) |
---|
610 | | - | let artId = t01774017781._1 |
---|
611 | | - | let caller = t01774017781._2 |
---|
612 | | - | let date = t01774017781._3 |
---|
613 | | - | if (containsElement(types, type)) |
---|
614 | | - | then { |
---|
615 | | - | let validateArtwork = validateArtworkData(caller, cidDisplay, name, description, tags) |
---|
616 | | - | if ((validateArtwork != "")) |
---|
617 | | - | then throw("Something went wrong!") |
---|
618 | | - | else { |
---|
619 | | - | let t01817018212 = validatePayment(i) |
---|
620 | | - | let amount = t01817018212._1 |
---|
621 | | - | let assetId = t01817018212._2 |
---|
622 | | - | if (!(isDefined(amount))) |
---|
623 | | - | then throw("Something went wrong") |
---|
624 | | - | else { |
---|
625 | | - | let previewData = if (containsElement(Previewtypes, type)) |
---|
626 | | - | then [StringEntry(keyPreviewCid(caller, artId), preview)] |
---|
627 | | - | else nil |
---|
628 | | - | let invokeCollectionCreate = invoke(addressFromStringValue(collectionsDapp), "collectionProcess", [collection, subcollection, caller, artId], nil) |
---|
629 | | - | if ((invokeCollectionCreate == invokeCollectionCreate)) |
---|
630 | | - | then { |
---|
631 | | - | let idCollection = match invokeCollectionCreate { |
---|
632 | | - | case r: String => |
---|
633 | | - | r |
---|
634 | | - | case _ => |
---|
635 | | - | throw("Incorrect invoke result") |
---|
636 | | - | } |
---|
637 | | - | let entryExist = getStringByKey(keyTxidByHashOwner(sha256Hash, caller)) |
---|
638 | | - | if ((entryExist != "")) |
---|
639 | | - | then throw("You already added it") |
---|
640 | | - | else { |
---|
641 | | - | let hashExist = getStringByKey(keyOwnerByHash(sha256Hash)) |
---|
642 | | - | if ((hashExist != "")) |
---|
643 | | - | then throw("This hash is already registered") |
---|
644 | | - | else (previewData ++ [StringEntry(keyCollection(caller, artId), idCollection), 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(keyType(caller, artId), type), StringEntry(keyTags(caller, artId), tags), IntegerEntry(keyMaxMint(caller, artId), 0), IntegerEntry(keyIssued(caller, artId), 0), BooleanEntry(keyOnSale(caller, artId), false), StringEntry(keyHashByTxidAddr(caller, artId), sha256Hash), StringEntry(keyEntitlement(caller, artId), entitlement), ScriptTransfer(Address(fromBase58String(feeReceiver)), amount, assetId)]) |
---|
645 | | - | } |
---|
646 | | - | } |
---|
647 | | - | else throw("Strict value is not equal to itself.") |
---|
648 | | - | } |
---|
649 | | - | } |
---|
650 | | - | } |
---|
651 | | - | else throw("Unknown type") |
---|
652 | | - | } |
---|
653 | | - | |
---|
654 | | - | |
---|
655 | | - | |
---|
656 | | - | @Callable(i) |
---|
657 | | - | func sellArtwork (artId,price,maxMint,assetId,auctionType,duration,royalty) = { |
---|
658 | | - | let t02571425747 = idCallerDate(i) |
---|
659 | | - | let id = t02571425747._1 |
---|
660 | | - | let caller = t02571425747._2 |
---|
661 | | - | let artworkName = getStringByKey(keyName(caller, artId)) |
---|
662 | | - | if ((0 > royalty)) |
---|
663 | | - | then throw("Royalty percentage should be above 0") |
---|
664 | | - | else if ((royalty > 85)) |
---|
665 | | - | then throw("Royalty percentage should be below 85") |
---|
666 | | - | else if (!(containsElement([auctionType1, auctionType2, auctionType3], auctionType))) |
---|
667 | | - | then throw("We don't know this auction type") |
---|
668 | | - | else if ((artworkName == "")) |
---|
669 | | - | then throw("This art doesn't match your account") |
---|
670 | | - | else { |
---|
671 | | - | let bidNbr = getIntegerByKey(("current_bidamount_" + artId)) |
---|
672 | | - | if (!(acceptedAssetIds(assetId))) |
---|
673 | | - | then throw("Something went wrong!") |
---|
674 | | - | else if (!(validateMinSell(assetId, price))) |
---|
675 | | - | then throw("Something went wrong!") |
---|
676 | | - | else { |
---|
677 | | - | let checkUser = validateUser(caller) |
---|
678 | | - | if ((checkUser != "")) |
---|
679 | | - | then throw(checkUser) |
---|
680 | | - | else { |
---|
681 | | - | let amountSold = getIntegerByKey(keyIssued(caller, artId)) |
---|
682 | | - | let maxCanSell = getIntegerByKey(keyMaxMint(caller, artId)) |
---|
683 | | - | if ((maxMint > 10000)) |
---|
684 | | - | then throw("10000 editions max per artwork") |
---|
685 | | - | else if (if ((amountSold != 0)) |
---|
686 | | - | then (amountSold == maxCanSell) |
---|
687 | | - | else false) |
---|
688 | | - | then throw("Max edition reached.") |
---|
689 | | - | else if (if ((amountSold > 0)) |
---|
690 | | - | then (maxCanSell != maxMint) |
---|
691 | | - | else false) |
---|
692 | | - | then throw("Cannot change maximum issuable anymore") |
---|
693 | | - | else if (if ((bidNbr > 0)) |
---|
694 | | - | then (maxCanSell != maxMint) |
---|
695 | | - | else false) |
---|
696 | | - | then throw("Cannot change maximum issuable with active orders") |
---|
697 | | - | else { |
---|
698 | | - | let sellStatus = if (if ((price > 0)) |
---|
699 | | - | then (maxMint > 0) |
---|
700 | | - | else false) |
---|
701 | | - | then true |
---|
702 | | - | else false |
---|
703 | | - | let endHeight = (duration + height) |
---|
704 | | - | [BooleanEntry(keyOnSale(caller, artId), sellStatus), IntegerEntry(keyPrice(caller, artId), price), IntegerEntry(keyMaxMint(caller, artId), maxMint), IntegerEntry(keyDuration(caller, artId), duration), IntegerEntry(keyEndHeight(caller, artId), endHeight), StringEntry(keyAssetIdAccepted(caller, artId), assetId), StringEntry(keyAuctionType(caller, artId), auctionType), IntegerEntry(keyRoyalty(caller, artId), royalty)] |
---|
705 | | - | } |
---|
706 | | - | } |
---|
707 | | - | } |
---|
708 | | - | } |
---|
709 | | - | } |
---|
710 | | - | |
---|
711 | | - | |
---|
712 | | - | |
---|
713 | | - | @Callable(i) |
---|
714 | | - | func buyArtwork (artId,issuer) = { |
---|
715 | | - | let auctionType = getStringByKey(keyAuctionType(issuer, artId)) |
---|
716 | | - | if ((auctionType == auctionType3)) |
---|
717 | | - | then buyMint(i, artId, issuer, "", "", false) |
---|
718 | | - | else throw("Direct buy only allowed when no auction type is set!") |
---|
719 | | - | } |
---|
720 | | - | |
---|
721 | | - | |
---|
722 | | - | |
---|
723 | | - | @Callable(i) |
---|
724 | | - | func updateTags (artist,artId,tags) = { |
---|
725 | | - | let caller = toString(addressFromPublicKey(i.callerPublicKey)) |
---|
726 | | - | if (containsElement(owners, caller)) |
---|
727 | | - | then if ((size(split(tags, ",")) > 5)) |
---|
728 | | - | then throw("5 tags max.") |
---|
729 | | - | else { |
---|
730 | | - | let tagsOld = getStringByKeyOrError(keyTags(artist, artId), "No tags created with this key, so can't update!") |
---|
731 | | - | if ((tags == tagsOld)) |
---|
732 | | - | then throw("Tags are the same as old tags!") |
---|
733 | | - | else [StringEntry(keyTags(artist, artId), tags)] |
---|
734 | | - | } |
---|
735 | | - | else throw("no") |
---|
736 | | - | } |
---|
737 | | - | |
---|
738 | | - | |
---|
739 | | - | |
---|
740 | | - | @Callable(i) |
---|
741 | | - | func deleteEntry (entry) = { |
---|
742 | | - | let caller = toString(addressFromPublicKey(i.callerPublicKey)) |
---|
743 | | - | if (containsElement(owners, caller)) |
---|
744 | | - | then [DeleteEntry(entry)] |
---|
745 | | - | else throw("no") |
---|
746 | | - | } |
---|
747 | | - | |
---|
748 | | - | |
---|
749 | | - | |
---|
750 | | - | @Callable(i) |
---|
751 | | - | func setBid (artId,issuer) = { |
---|
752 | | - | let auctionType = getStringByKey(keyAuctionType(issuer, artId)) |
---|
753 | | - | if ((auctionType == auctionType1)) |
---|
754 | | - | then setBidNonTraditional(i, artId, issuer) |
---|
755 | | - | else if ((auctionType == auctionType2)) |
---|
756 | | - | then setBidTraditional(i, artId, issuer) |
---|
757 | | - | else throw((("Unknown auction type :" + auctionType) + ", please contact the admins")) |
---|
758 | | - | } |
---|
759 | | - | |
---|
760 | | - | |
---|
761 | | - | |
---|
762 | | - | @Callable(i) |
---|
763 | | - | func acceptBid (artId,issuer,bidId,bidOwner) = { |
---|
764 | | - | let auctionType = getStringByKey(keyAuctionType(issuer, artId)) |
---|
765 | | - | if ((auctionType == auctionType1)) |
---|
766 | | - | then acceptBidNonTraditional(i, artId, issuer, bidId, bidOwner) |
---|
767 | | - | else if ((auctionType == auctionType2)) |
---|
768 | | - | then acceptBidTraditional(i, artId, issuer, bidId, bidOwner) |
---|
769 | | - | else throw((("Unknown auction type :" + auctionType) + ", please contact the admins")) |
---|
770 | | - | } |
---|
771 | | - | |
---|
772 | | - | |
---|
773 | | - | |
---|
774 | | - | @Callable(i) |
---|
775 | | - | func cancelBid (artId,issuer,bidId) = { |
---|
776 | | - | let auctionType = getStringByKey(keyAuctionType(issuer, artId)) |
---|
777 | | - | if ((auctionType == auctionType1)) |
---|
778 | | - | then cancelBidImpl(i, artId, issuer, bidId) |
---|
779 | | - | else cancelBidImplTraditional(i, artId, issuer, bidId) |
---|
780 | | - | } |
---|
781 | | - | |
---|
| 36 | + | func collections (i,collection,subcollection,artId,creator) = if (if (invokerIsSconexDapp(i.caller)) |
---|
| 37 | + | then true |
---|
| 38 | + | else (i.caller == this)) |
---|
| 39 | + | then if ((collection == "")) |
---|
| 40 | + | then throw("Collections can not be empty!") |
---|
| 41 | + | else if ((subcollection == "")) |
---|
| 42 | + | then [StringEntry(keyCollection(creator, artId), collection)] |
---|
| 43 | + | else [StringEntry(keyCollection(creator, artId), collection), StringEntry(keySubcollectionCollection(creator, artId, collection), subcollection)] |
---|
| 44 | + | else throw("Wrong invoker") |
---|