1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | func tryGetInteger (key) = match getInteger(this, key) { |
---|
5 | | - | case b: Int => |
---|
6 | | - | b |
---|
7 | | - | case _ => |
---|
8 | | - | 0 |
---|
9 | | - | } |
---|
10 | | - | |
---|
11 | | - | |
---|
12 | | - | func tryGetString (key) = match getString(this, key) { |
---|
13 | | - | case b: String => |
---|
14 | | - | b |
---|
15 | | - | case _ => |
---|
16 | | - | "" |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func checkNFT (asset) = if (if (if ((asset.issuer.bytes == this.bytes)) |
---|
21 | | - | then (asset.decimals == 0) |
---|
22 | | - | else false) |
---|
23 | | - | then (asset.reissuable == false) |
---|
24 | | - | else false) |
---|
25 | | - | then (asset.quantity == 1) |
---|
26 | | - | else false |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | func keyCollectionName (collectionId) = (("collection_" + collectionId) + "_name") |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | func keyURITemplate (collectionId) = (("collection_" + collectionId) + "_URI") |
---|
33 | | - | |
---|
34 | | - | |
---|
35 | | - | func keyCollectionSize (collectionId) = (("collection_" + collectionId) + "_size") |
---|
36 | | - | |
---|
37 | | - | |
---|
38 | | - | func keyCollectionOwner (collectionId) = (("collection_" + collectionId) + "_owner") |
---|
39 | | - | |
---|
40 | | - | |
---|
41 | | - | @Callable(i) |
---|
42 | | - | func createCollection (name,URITemplate) = if ((indexOf(URITemplate, "https://") != 0)) |
---|
43 | | - | then throw("URI Template is required") |
---|
44 | | - | else if ((1 > value(indexOf(URITemplate, "{{ID}}")))) |
---|
45 | | - | then throw("ID parameter in URI Template is required") |
---|
46 | | - | else { |
---|
47 | | - | let collectionId = toBase58String(i.transactionId) |
---|
48 | | - | [StringEntry(keyCollectionName(collectionId), name), StringEntry(keyURITemplate(collectionId), URITemplate), IntegerEntry(keyCollectionSize(collectionId), 0), StringEntry(keyCollectionOwner(collectionId), toBase58String(i.originCallerPublicKey))] |
---|
49 | | - | } |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | |
---|
53 | | - | @Callable(i) |
---|
54 | | - | func createNFT (name,desc,image,collectionId,editable) = if ((indexOf(image, "https://") != 0)) |
---|
55 | | - | then throw("https link to image is required") |
---|
56 | | - | else { |
---|
57 | | - | let asset = Issue(name, desc, 1, 0, false, unit, 0) |
---|
58 | | - | let assetId = calculateAssetId(asset) |
---|
59 | | - | let assetIdStr = toBase58String(assetId) |
---|
60 | | - | let collectionIdChecked = ((toString(i.caller) + "_") + (if ((size(collectionId) > 0)) |
---|
61 | | - | then collectionId |
---|
62 | | - | else "basic")) |
---|
63 | | - | let nftNum = (tryGetInteger(keyCollectionSize(collectionIdChecked)) + 1) |
---|
64 | | - | $Tuple2([StringEntry((("nft_" + assetIdStr) + "_data"), (((("{'collection': '" + collectionId) + "', 'num': ") + toString(nftNum)) + "}")), StringEntry((("nft_" + assetIdStr) + "_image"), image), StringEntry((("nft_" + assetIdStr) + "_issuer"), toString(i.caller)), BooleanEntry((("nft_" + assetIdStr) + "_isEditable"), editable), IntegerEntry((("collection_" + collectionId) + "_size"), nftNum), StringEntry(((("collection_" + collectionId) + "_assetId_") + assetIdStr), assetIdStr), asset, ScriptTransfer(i.caller, 1, assetId)], assetIdStr) |
---|
65 | | - | } |
---|
66 | | - | |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | @Callable(i) |
---|
70 | | - | func updateNFT (image) = { |
---|
71 | | - | let assetId = value(value(i.payments[0]).assetId) |
---|
72 | | - | let assetIdStr = toBase58String(assetId) |
---|
73 | | - | let asset = value(assetInfo(assetId)) |
---|
74 | | - | let isEditable = match getBoolean(this, (("nft_" + assetIdStr) + "_isEditable")) { |
---|
75 | | - | case x: Boolean => |
---|
76 | | - | x |
---|
77 | | - | case _ => |
---|
78 | | - | false |
---|
79 | | - | } |
---|
80 | | - | let issuerStr = tryGetString((("nft_" + assetIdStr) + "_issuer")) |
---|
81 | | - | if (!(isEditable)) |
---|
82 | | - | then throw("this NFT can't be updated") |
---|
83 | | - | else if ((toString(i.caller) != issuerStr)) |
---|
84 | | - | then throw("this NFT can be updated only by the owner") |
---|
85 | | - | else if ((indexOf(image, "https://") != 0)) |
---|
86 | | - | then throw("https link to image required") |
---|
87 | | - | else if (!(if ((value(i.payments[0]).amount == 1)) |
---|
88 | | - | then checkNFT(asset) |
---|
89 | | - | else false)) |
---|
90 | | - | then throw("invalid NFT attached") |
---|
91 | | - | else [StringEntry((("nft_" + assetIdStr) + "_image"), image)] |
---|
92 | | - | } |
---|
93 | | - | |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | @Callable(i) |
---|
97 | | - | func burnNFT () = { |
---|
98 | | - | let assetId = value(value(i.payments[0]).assetId) |
---|
99 | | - | let asset = value(assetInfo(assetId)) |
---|
100 | | - | if (if ((value(i.payments[0]).amount == 1)) |
---|
101 | | - | then checkNFT(asset) |
---|
102 | | - | else false) |
---|
103 | | - | then { |
---|
104 | | - | let assetIdStr = toBase58String(assetId) |
---|
105 | | - | let issuer = tryGetString((("nft_" + assetIdStr) + "_issuer")) |
---|
106 | | - | let data = tryGetString((("nft_" + assetIdStr) + "_data")) |
---|
107 | | - | let partsData = split(data, " ,") |
---|
108 | | - | let partsCollection = split(partsData[0], ": ") |
---|
109 | | - | let collectionDomain = dropRight(drop(partsCollection[1], 1), 1) |
---|
110 | | - | let nftNum = tryGetInteger((("collection_" + collectionDomain) + "_size")) |
---|
111 | | - | if ((nftNum > 0)) |
---|
112 | | - | then { |
---|
113 | | - | let updateCollection = if ((nftNum == 1)) |
---|
114 | | - | then DeleteEntry((("collection_" + collectionDomain) + "_size")) |
---|
115 | | - | else IntegerEntry((("collection_" + collectionDomain) + "_size"), (nftNum - 1)) |
---|
116 | | - | [updateCollection, Burn(assetId, 1), DeleteEntry((("nft_" + assetIdStr) + "_data")), DeleteEntry((("nft_" + assetIdStr) + "_image")), DeleteEntry((("nft_" + assetIdStr) + "_issuer")), DeleteEntry(((("collection_" + collectionDomain) + "_assetId_") + assetIdStr))] |
---|
117 | | - | } |
---|
118 | | - | else throw("invalid collection name") |
---|
119 | | - | } |
---|
120 | | - | else throw("invalid NFT attached") |
---|
121 | | - | } |
---|
122 | | - | |
---|
123 | | - | |
---|
124 | | - | @Verifier(tx) |
---|
125 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
126 | | - | |
---|
| 1 | + | # no script |
---|