37 | | - | func createNft (nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = { |
---|
38 | | - | let newToken = Issue(nft_name, nft_description, 1, 0, false) |
---|
39 | | - | let issueId = calculateAssetId(newToken) |
---|
40 | | - | let txId = i.transactionId |
---|
41 | | - | [newToken, ScriptTransfer(i.caller, 1, issueId), StringEntry(((toBase58String(issueId) + separator) + "Owner"), toString(i.caller)), StringEntry(((toBase58String(issueId) + separator) + "nft_type"), nft_type), StringEntry(((toBase58String(issueId) + separator) + "nft_tags"), nft_tags), StringEntry(((toBase58String(issueId) + separator) + "nft_dAppAddress"), nft_dAppAddress), IntegerEntry(((toBase58String(issueId) + separator) + "nft_selling_price"), nft_selling_price), StringEntry(((toBase58String(issueId) + separator) + "nft_onSell"), nft_onSell), StringEntry(((toBase58String(issueId) + separator) + "nft_data"), nft_data), StringEntry(((toBase58String(txId) + separator) + "issue_nft"), toBase58String(issueId))] |
---|
42 | | - | } |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | @Callable(i) |
---|
47 | | - | func sellNFT (price) = { |
---|
48 | | - | let txId = i.transactionId |
---|
49 | | - | let seller = i.caller.bytes |
---|
50 | | - | let $t018801965 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) |
---|
51 | | - | let token0 = $t018801965._1 |
---|
52 | | - | let amount0 = $t018801965._2 |
---|
53 | | - | if (!(isNft(token0))) |
---|
54 | | - | then throw("Token is not NFT") |
---|
55 | | - | else [StringEntry(((kPrice + separator) + toBase58String(value(i.payments[0].assetId))), price), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))] |
---|
56 | | - | } |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | @Callable(i) |
---|
61 | | - | func buyNFT (nftID,current_nft_owner) = { |
---|
62 | | - | let assetId = fromBase58String(nftID) |
---|
63 | | - | let amount = value(i.payments[0].amount) |
---|
64 | | - | let checkOwnerIsSame = match getString(this, (("nft_" + current_nft_owner) + "_owner")) { |
---|
65 | | - | case a: String => |
---|
66 | | - | a |
---|
67 | | - | case _ => |
---|
68 | | - | false |
---|
69 | | - | } |
---|
70 | | - | let price = getStringValue(((((kPrice + separator) + nftID) + "_") + current_nft_owner)) |
---|
71 | | - | if ((current_nft_owner == toString(i.caller))) |
---|
72 | | - | then throw("current Owner of NFT not able to purchase") |
---|
73 | | - | else if ((i.payments[0].assetId == teams)) |
---|
74 | | - | then [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(Address(fromBase58String(current_nft_owner)), amount, teams), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount))), DeleteEntry((("nft_" + current_nft_owner) + "_owner")), StringEntry((("nft_" + current_nft_owner) + "_owner"), toString(i.caller)), StringEntry(((nftID + separator) + "_owner"), toString(i.caller))] |
---|
75 | | - | else [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(Address(fromBase58String(current_nft_owner)), amount, unit), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount))), DeleteEntry((("nft_" + current_nft_owner) + "_owner")), StringEntry((("nft_" + current_nft_owner) + "_owner"), toString(i.caller)), StringEntry(((nftID + separator) + "_owner"), toString(i.caller))] |
---|
76 | | - | } |
---|
77 | | - | |
---|
78 | | - | |
---|
79 | | - | |
---|
80 | | - | @Callable(i) |
---|
81 | | - | func cancelSell (nftId) = { |
---|
82 | | - | let txId = toBase58String(i.transactionId) |
---|
83 | | - | let seller = i.caller.bytes |
---|
84 | | - | [StringEntry(((txId + nftId) + "_nft_status"), "CANCELED"), ScriptTransfer(Address(seller), 1, fromBase58String(nftId))] |
---|
| 7 | + | func createNft (ipfsImageHash) = { |
---|
| 8 | + | let recipient = i.caller |
---|
| 9 | + | let asset = Issue(("donkey-" + toString(0)), "first Nft", 1, 0, false) |
---|
| 10 | + | let assetId = calculateAssetId(asset) |
---|
| 11 | + | [asset, ScriptTransfer(recipient, 2, assetId), StringEntry((toBase58String(assetId) + "_ipfs"), ipfsImageHash)] |
---|