33 | | - | func createNft (nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = { |
---|
34 | | - | let newToken = Issue(nft_name, nft_description, 1, 0, false) |
---|
35 | | - | let issueId = calculateAssetId(newToken) |
---|
36 | | - | let txId = i.transactionId |
---|
37 | | - | [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))] |
---|
| 7 | + | func token () = { |
---|
| 8 | + | let asset = Issue("shub", "This is an ordinary token", 1000000, 2, true) |
---|
| 9 | + | let assetId = calculateAssetId(asset) |
---|
| 10 | + | [asset] |
---|
41 | | - | |
---|
42 | | - | @Callable(i) |
---|
43 | | - | func sellNFT (price) = { |
---|
44 | | - | let txId = i.transactionId |
---|
45 | | - | let seller = i.caller.bytes |
---|
46 | | - | let $t017891874 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) |
---|
47 | | - | let token0 = $t017891874._1 |
---|
48 | | - | let amount0 = $t017891874._2 |
---|
49 | | - | if (!(isNft(token0))) |
---|
50 | | - | then throw("Token is not NFT") |
---|
51 | | - | else [StringEntry(((kPrice + separator) + toBase58String(value(i.payments[0].assetId))), toString(price)), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))] |
---|
52 | | - | } |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | @Callable(i) |
---|
57 | | - | func buyNFT (nftID,current_nft_owner) = { |
---|
58 | | - | let assetId = fromBase58String(nftID) |
---|
59 | | - | let amount = value(i.payments[0].amount) |
---|
60 | | - | let checkOwnerIsSame = match getString(this, (("nft_" + current_nft_owner) + "_owner")) { |
---|
61 | | - | case a: String => |
---|
62 | | - | a |
---|
63 | | - | case _ => |
---|
64 | | - | false |
---|
65 | | - | } |
---|
66 | | - | let price = getStringValue(((((kPrice + separator) + nftID) + "_") + current_nft_owner)) |
---|
67 | | - | if ((i.payments[0].assetId != unit)) |
---|
68 | | - | then throw("Pay in waves") |
---|
69 | | - | else if ((current_nft_owner == toString(i.caller))) |
---|
70 | | - | then throw("current Owner of NFT not able to purchase") |
---|
71 | | - | 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))] |
---|
72 | | - | } |
---|
73 | | - | |
---|
| 14 | + | @Verifier(tx) |
---|
| 15 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|