tx · DsLcwqCtckvqSCfr4BeG9ntsTXWq4ZvTQDSTT18qcXJ5 3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H: -0.01000000 Waves 2022.11.04 18:13 [2302531] smart account 3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H > SELF 0.00000000 Waves
{ "type": 13, "id": "DsLcwqCtckvqSCfr4BeG9ntsTXWq4ZvTQDSTT18qcXJ5", "fee": 1000000, "feeAssetId": null, "timestamp": 1667574837043, "version": 2, "chainId": 84, "sender": "3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H", "senderPublicKey": "BDeCphaaC4MZvfmbJqQZ78EvuEBZTJ1VEW7fbxue8BUu", "proofs": [ "5oi1LhSR6WBsj5ejYfUThFzUZ8shcSB4gf5BzfTyV9qM1Y2BFeqSH7ZoEnnNxizFSw99cBNHB4ierBSiCuviQ2YH" ], "script": "base64:BgIRCAISBQoDCAgBEgQKAggBEgAFAAlzZXBhcmF0b3ICAV8ABGtCdXkCA2J1eQAFa1NlbGwCBHNlbGwABmtQcmljZQIFcHJpY2UBBWlzTmZ0AQdhc3NldElkBAckbWF0Y2gwCQDsBwEFB2Fzc2V0SWQDCQABAgUHJG1hdGNoMAIFQXNzZXQEBXRva2VuBQckbWF0Y2gwAwMJAAACCAUFdG9rZW4IZGVjaW1hbHMAAAkAAAIIBQV0b2tlbghxdWFudGl0eQABBwkAAAIIBQV0b2tlbgpyZWlzc3VhYmxlBwcHAwFpAQhpc3N1ZU5mdAMEbmFtZQRtZXRhBXByaWNlBAhuZXdUb2tlbgkAwggFBQRuYW1lBQRtZXRhAAEAAAcEB2lzc3VlSWQJALgIAQUIbmV3VG9rZW4JAMwIAgUIbmV3VG9rZW4JAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyCAUIbmV3VG9rZW4IcXVhbnRpdHkFB2lzc3VlSWQJAMwIAgkBC1N0cmluZ0VudHJ5AgkArAICCQCsAgIFBmtQcmljZQUJc2VwYXJhd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EwNTgpAQkArAICCQCsAgIFBmtQcmljZQUJc2VwYXJhdG9yCQETdmFsdWVPckVycm9yTWVzc2FnZQIJANgEAQUGdG9rZW4wAh5UaGVyZSBpcyBubyBwcmljZSBmb3IgdGhpcyBORlQDCQEBIQEJAQVpc05mdAEFBnRva2VuMAkAAgECEFRva2VuIGlzIG5vdCBORlQJAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwgFAWkGY2FsbGVyCQBoAgkBDXBhcnNlSW50VmFsdWUBBQVwcmljZQUHYW1vdW50MAUEdW5pdAkAzAgCCQELU3RyaW5nRW50cnkCCQCsAgIJAKwCAgkApQgBCAUBaQZjYWxsZXIFCXNlcGFyYXRvcgUFa1NlbGwJAKwCAgkArAICCQDYBAEFBnRva2VuMAUJc2VwYXJhdG9yCQCkAwEFB2Ftb3VudDAFA25pbAALmbSL", "height": 2302531, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DsMjkGrzCzAT6gPs1qEqLYfAQJccqP8TeLQQkR9eXAPv Next: D76brpebbXP8T8kPFPHhFE1jCZMUPUnsWRc3kAR74LGH Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "_" | |
5 | 5 | ||
6 | - | let | |
6 | + | let kBuy = "buy" | |
7 | 7 | ||
8 | - | let | |
8 | + | let kSell = "sell" | |
9 | 9 | ||
10 | - | let | |
10 | + | let kPrice = "price" | |
11 | 11 | ||
12 | - | let NFT_LIMIT = 500 | |
13 | - | ||
14 | - | func getCollectionKey (collectionId) = makeString([kCollection, toBase58String(collectionId)], separator) | |
15 | - | ||
16 | - | ||
17 | - | func getCollectionValue (collections,collectionId) = makeString([collections, toBase58String(collectionId)], separator) | |
18 | - | ||
19 | - | ||
20 | - | func getNftKey (nftId) = makeString([kNft, toBase58String(nftId)], separator) | |
21 | - | ||
22 | - | ||
23 | - | func getNftValue (nfts,nftId) = makeString([nfts, toBase58String(nftId)], separator) | |
24 | - | ||
25 | - | ||
26 | - | func getOwnerCollections (owner) = split(valueOrElse(getString(this, toString(owner)), ""), separator) | |
27 | - | ||
28 | - | ||
29 | - | func getNftsFromCollection (collectionId) = split(valueOrElse(getString(this, getCollectionKey(collectionId)), ""), separator) | |
30 | - | ||
31 | - | ||
32 | - | func getOwnerCollectionsForUpdate (owner) = valueOrElse(getString(this, toString(owner)), "") | |
33 | - | ||
34 | - | ||
35 | - | func getNftsFromCollectionForUpdate (collectionId) = valueOrElse(getString(this, getCollectionKey(collectionId)), "") | |
36 | - | ||
37 | - | ||
38 | - | func setOwnerCollection (owner,collections,collectionId) = if ((collections == "")) | |
39 | - | then StringEntry(toString(owner), toBase58String(collectionId)) | |
40 | - | else StringEntry(toString(owner), getCollectionValue(collections, collectionId)) | |
41 | - | ||
42 | - | ||
43 | - | func setNftsFromCollection (collectionId,nfts,nftId) = if ((nfts == "")) | |
44 | - | then StringEntry(getCollectionKey(collectionId), toBase58String(nftId)) | |
45 | - | else StringEntry(getCollectionKey(collectionId), getNftValue(nfts, nftId)) | |
46 | - | ||
47 | - | ||
48 | - | func isCollectionsLimitReached (caller) = (size(getOwnerCollections(caller)) > COLLECTIONS_LIMIT) | |
49 | - | ||
50 | - | ||
51 | - | func isNftsLimitReached (collectionId) = (size(getNftsFromCollection(collectionId)) > NFT_LIMIT) | |
52 | - | ||
53 | - | ||
54 | - | func isOwner (nftId,caller) = (assetBalance(caller, nftId) == 1) | |
55 | - | ||
56 | - | ||
57 | - | func isAlreadySetted (nftId) = isDefined(getString(this, getNftKey(nftId))) | |
58 | - | ||
59 | - | ||
60 | - | func isCollectionExist (owner,collectionId) = { | |
61 | - | let collectionsArray = getOwnerCollections(owner) | |
62 | - | containsElement(collectionsArray, toBase58String(collectionId)) | |
63 | - | } | |
64 | - | ||
65 | - | ||
66 | - | func isCorrectCaller (nftId,caller) = if (!(isOwner(nftId, caller))) | |
67 | - | then throw("Caller is not owner of nft") | |
68 | - | else if (isAlreadySetted(nftId)) | |
69 | - | then throw("Content already setted for this nft") | |
70 | - | else unit | |
12 | + | func isNft (assetId) = match assetInfo(assetId) { | |
13 | + | case token: Asset => | |
14 | + | if (if ((token.decimals == 0)) | |
15 | + | then (token.quantity == 1) | |
16 | + | else false) | |
17 | + | then (token.reissuable == false) | |
18 | + | else false | |
19 | + | case _ => | |
20 | + | false | |
21 | + | } | |
71 | 22 | ||
72 | 23 | ||
73 | 24 | @Callable(i) | |
74 | - | func addCollection () = if (isCollectionsLimitReached(i.caller)) | |
75 | - | then throw("You reached collections limit") | |
76 | - | else [setOwnerCollection(i.caller, getOwnerCollectionsForUpdate(i.caller), i.transactionId)] | |
25 | + | func issueNft (name,meta,price) = { | |
26 | + | let newToken = Issue(name, meta, 1, 0, false) | |
27 | + | let issueId = calculateAssetId(newToken) | |
28 | + | [newToken, ScriptTransfer(i.caller, newToken.quantity, issueId), StringEntry(((kPrice + separator) + toBase58String(issueId)), toString(price))] | |
29 | + | } | |
77 | 30 | ||
78 | 31 | ||
79 | 32 | ||
80 | 33 | @Callable(i) | |
81 | - | func mint (collectionId,name,meta) = if (!(isCollectionExist(i.caller, collectionId))) | |
82 | - | then throw("Wrong collection or caller ID") | |
83 | - | else if (isNftsLimitReached(collectionId)) | |
84 | - | then throw("You reached nfts limit in this collection") | |
85 | - | else { | |
86 | - | let newToken = Issue(name, meta, 1, 0, false) | |
87 | - | let issueId = calculateAssetId(newToken) | |
88 | - | [newToken, ScriptTransfer(i.caller, newToken.quantity, issueId), setNftsFromCollection(collectionId, getNftsFromCollectionForUpdate(collectionId), issueId)] | |
89 | - | } | |
34 | + | func buyNFT (nftID,amount) = { | |
35 | + | let $t0777862 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) | |
36 | + | let token0 = $t0777862._1 | |
37 | + | let amount0 = $t0777862._2 | |
38 | + | let price = valueOrErrorMessage(getStringValue(((kPrice + separator) + nftID)), "There is no price for this NFT") | |
39 | + | if ((i.payments[0].assetId != unit)) | |
40 | + | then throw("Pay in waves") | |
41 | + | else if ((parseIntValue(price) > (amount0 * amount))) | |
42 | + | then throw("Invalid payment attached") | |
43 | + | else [ScriptTransfer(i.caller, amount, fromBase58String(nftID)), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))] | |
44 | + | } | |
90 | 45 | ||
91 | 46 | ||
92 | 47 | ||
93 | 48 | @Callable(i) | |
94 | - | func setContent (nftId,content) = valueOrElse(isCorrectCaller(nftId, i.caller), [StringEntry(getNftKey(nftId), content)]) | |
49 | + | func sellNFT () = { | |
50 | + | let $t013591444 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) | |
51 | + | let token0 = $t013591444._1 | |
52 | + | let amount0 = $t013591444._2 | |
53 | + | let price = getStringValue(((kPrice + separator) + valueOrErrorMessage(toBase58String(token0), "There is no price for this NFT"))) | |
54 | + | if (!(isNft(token0))) | |
55 | + | then throw("Token is not NFT") | |
56 | + | else [ScriptTransfer(i.caller, (parseIntValue(price) * amount0), unit), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))] | |
57 | + | } | |
95 | 58 | ||
96 | 59 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "_" | |
5 | 5 | ||
6 | - | let | |
6 | + | let kBuy = "buy" | |
7 | 7 | ||
8 | - | let | |
8 | + | let kSell = "sell" | |
9 | 9 | ||
10 | - | let | |
10 | + | let kPrice = "price" | |
11 | 11 | ||
12 | - | let NFT_LIMIT = 500 | |
13 | - | ||
14 | - | func getCollectionKey (collectionId) = makeString([kCollection, toBase58String(collectionId)], separator) | |
15 | - | ||
16 | - | ||
17 | - | func getCollectionValue (collections,collectionId) = makeString([collections, toBase58String(collectionId)], separator) | |
18 | - | ||
19 | - | ||
20 | - | func getNftKey (nftId) = makeString([kNft, toBase58String(nftId)], separator) | |
21 | - | ||
22 | - | ||
23 | - | func getNftValue (nfts,nftId) = makeString([nfts, toBase58String(nftId)], separator) | |
24 | - | ||
25 | - | ||
26 | - | func getOwnerCollections (owner) = split(valueOrElse(getString(this, toString(owner)), ""), separator) | |
27 | - | ||
28 | - | ||
29 | - | func getNftsFromCollection (collectionId) = split(valueOrElse(getString(this, getCollectionKey(collectionId)), ""), separator) | |
30 | - | ||
31 | - | ||
32 | - | func getOwnerCollectionsForUpdate (owner) = valueOrElse(getString(this, toString(owner)), "") | |
33 | - | ||
34 | - | ||
35 | - | func getNftsFromCollectionForUpdate (collectionId) = valueOrElse(getString(this, getCollectionKey(collectionId)), "") | |
36 | - | ||
37 | - | ||
38 | - | func setOwnerCollection (owner,collections,collectionId) = if ((collections == "")) | |
39 | - | then StringEntry(toString(owner), toBase58String(collectionId)) | |
40 | - | else StringEntry(toString(owner), getCollectionValue(collections, collectionId)) | |
41 | - | ||
42 | - | ||
43 | - | func setNftsFromCollection (collectionId,nfts,nftId) = if ((nfts == "")) | |
44 | - | then StringEntry(getCollectionKey(collectionId), toBase58String(nftId)) | |
45 | - | else StringEntry(getCollectionKey(collectionId), getNftValue(nfts, nftId)) | |
46 | - | ||
47 | - | ||
48 | - | func isCollectionsLimitReached (caller) = (size(getOwnerCollections(caller)) > COLLECTIONS_LIMIT) | |
49 | - | ||
50 | - | ||
51 | - | func isNftsLimitReached (collectionId) = (size(getNftsFromCollection(collectionId)) > NFT_LIMIT) | |
52 | - | ||
53 | - | ||
54 | - | func isOwner (nftId,caller) = (assetBalance(caller, nftId) == 1) | |
55 | - | ||
56 | - | ||
57 | - | func isAlreadySetted (nftId) = isDefined(getString(this, getNftKey(nftId))) | |
58 | - | ||
59 | - | ||
60 | - | func isCollectionExist (owner,collectionId) = { | |
61 | - | let collectionsArray = getOwnerCollections(owner) | |
62 | - | containsElement(collectionsArray, toBase58String(collectionId)) | |
63 | - | } | |
64 | - | ||
65 | - | ||
66 | - | func isCorrectCaller (nftId,caller) = if (!(isOwner(nftId, caller))) | |
67 | - | then throw("Caller is not owner of nft") | |
68 | - | else if (isAlreadySetted(nftId)) | |
69 | - | then throw("Content already setted for this nft") | |
70 | - | else unit | |
12 | + | func isNft (assetId) = match assetInfo(assetId) { | |
13 | + | case token: Asset => | |
14 | + | if (if ((token.decimals == 0)) | |
15 | + | then (token.quantity == 1) | |
16 | + | else false) | |
17 | + | then (token.reissuable == false) | |
18 | + | else false | |
19 | + | case _ => | |
20 | + | false | |
21 | + | } | |
71 | 22 | ||
72 | 23 | ||
73 | 24 | @Callable(i) | |
74 | - | func addCollection () = if (isCollectionsLimitReached(i.caller)) | |
75 | - | then throw("You reached collections limit") | |
76 | - | else [setOwnerCollection(i.caller, getOwnerCollectionsForUpdate(i.caller), i.transactionId)] | |
25 | + | func issueNft (name,meta,price) = { | |
26 | + | let newToken = Issue(name, meta, 1, 0, false) | |
27 | + | let issueId = calculateAssetId(newToken) | |
28 | + | [newToken, ScriptTransfer(i.caller, newToken.quantity, issueId), StringEntry(((kPrice + separator) + toBase58String(issueId)), toString(price))] | |
29 | + | } | |
77 | 30 | ||
78 | 31 | ||
79 | 32 | ||
80 | 33 | @Callable(i) | |
81 | - | func mint (collectionId,name,meta) = if (!(isCollectionExist(i.caller, collectionId))) | |
82 | - | then throw("Wrong collection or caller ID") | |
83 | - | else if (isNftsLimitReached(collectionId)) | |
84 | - | then throw("You reached nfts limit in this collection") | |
85 | - | else { | |
86 | - | let newToken = Issue(name, meta, 1, 0, false) | |
87 | - | let issueId = calculateAssetId(newToken) | |
88 | - | [newToken, ScriptTransfer(i.caller, newToken.quantity, issueId), setNftsFromCollection(collectionId, getNftsFromCollectionForUpdate(collectionId), issueId)] | |
89 | - | } | |
34 | + | func buyNFT (nftID,amount) = { | |
35 | + | let $t0777862 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) | |
36 | + | let token0 = $t0777862._1 | |
37 | + | let amount0 = $t0777862._2 | |
38 | + | let price = valueOrErrorMessage(getStringValue(((kPrice + separator) + nftID)), "There is no price for this NFT") | |
39 | + | if ((i.payments[0].assetId != unit)) | |
40 | + | then throw("Pay in waves") | |
41 | + | else if ((parseIntValue(price) > (amount0 * amount))) | |
42 | + | then throw("Invalid payment attached") | |
43 | + | else [ScriptTransfer(i.caller, amount, fromBase58String(nftID)), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))] | |
44 | + | } | |
90 | 45 | ||
91 | 46 | ||
92 | 47 | ||
93 | 48 | @Callable(i) | |
94 | - | func setContent (nftId,content) = valueOrElse(isCorrectCaller(nftId, i.caller), [StringEntry(getNftKey(nftId), content)]) | |
49 | + | func sellNFT () = { | |
50 | + | let $t013591444 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) | |
51 | + | let token0 = $t013591444._1 | |
52 | + | let amount0 = $t013591444._2 | |
53 | + | let price = getStringValue(((kPrice + separator) + valueOrErrorMessage(toBase58String(token0), "There is no price for this NFT"))) | |
54 | + | if (!(isNft(token0))) | |
55 | + | then throw("Token is not NFT") | |
56 | + | else [ScriptTransfer(i.caller, (parseIntValue(price) * amount0), unit), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))] | |
57 | + | } | |
95 | 58 | ||
96 | 59 |
github/deemru/w8io/026f985 49.42 ms ◑