8 | | - | let nftAssetId = base58'' |
---|
9 | | - | |
---|
10 | | - | let kGlobalCounter = "GLOBAL_COUNTER" |
---|
11 | | - | |
---|
12 | | - | let feePercent = 5 |
---|
13 | | - | |
---|
14 | | - | let artefactsFeePercent = 20 |
---|
15 | | - | |
---|
16 | | - | func tryGetInteger (key) = { |
---|
17 | | - | let val = match getInteger(this, key) { |
---|
18 | | - | case b: Int => |
---|
19 | | - | b |
---|
20 | | - | case _ => |
---|
21 | | - | 0 |
---|
22 | | - | } |
---|
23 | | - | val |
---|
| 6 | + | @Callable(i) |
---|
| 7 | + | func sellart (artId,Price,maxMint,assetId,BlockEnd) = { |
---|
| 8 | + | let nftId = toBase58String(i.transactionId) |
---|
| 9 | + | WriteSet([DataEntry((nftId + "_organizer"), toBase58String(i.caller.bytes)), DataEntry((nftId + "_startPrice"), Price), DataEntry((nftId + "_priceAssetId"), assetId), DataEntry((nftId + "_maxMintnft"), maxMint), DataEntry((nftId + "_BlockEnd"), BlockEnd)]) |
---|
27 | | - | func tryGetString (key) = { |
---|
28 | | - | let val = match getString(this, key) { |
---|
29 | | - | case b: String => |
---|
30 | | - | b |
---|
31 | | - | case _ => |
---|
32 | | - | "" |
---|
33 | | - | } |
---|
34 | | - | val |
---|
35 | | - | } |
---|
36 | | - | |
---|
37 | | - | |
---|
38 | | - | func tryGetBoolean (key) = match getBoolean(this, key) { |
---|
39 | | - | case b: Boolean => |
---|
40 | | - | b |
---|
41 | | - | case _ => |
---|
42 | | - | false |
---|
43 | | - | } |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func getGlobalCounter () = tryGetInteger(kGlobalCounter) |
---|
47 | | - | |
---|
48 | | - | |
---|
49 | | - | func getAssetGenotype (assetId) = if ((value(assetInfo(assetId)).issuer == Address(ownerAddress))) |
---|
50 | | - | then "ART" |
---|
51 | | - | else { |
---|
52 | | - | let asset1 = match getString(Address(ownerAddress), toBase58String(assetId)) { |
---|
53 | | - | case b: String => |
---|
54 | | - | b |
---|
55 | | - | case _ => |
---|
56 | | - | "" |
---|
57 | | - | } |
---|
58 | | - | if ((asset1 != "")) |
---|
59 | | - | then asset1 |
---|
60 | | - | else { |
---|
61 | | - | let asset2 = match getString(Address(nftAddress), toBase58String(assetId)) { |
---|
62 | | - | case c: String => |
---|
63 | | - | c |
---|
64 | | - | case _ => |
---|
65 | | - | "" |
---|
66 | | - | } |
---|
67 | | - | if ((asset2 != "")) |
---|
68 | | - | then asset2 |
---|
69 | | - | else "" |
---|
70 | | - | } |
---|
71 | | - | } |
---|
72 | | - | |
---|
73 | | - | |
---|
74 | | - | @Callable(i) |
---|
75 | | - | func nftBuy (nftId) = { |
---|
76 | | - | let isnftart = tryGetBoolean((("nft_" + nftId) + "_nftart")) |
---|
77 | | - | let paymentAssetId = if ((isnftart == true)) |
---|
78 | | - | then nftAssetId |
---|
79 | | - | else unit |
---|
80 | | - | let paymentAssetName = if ((isnftart == true)) |
---|
81 | | - | then "nftart" |
---|
82 | | - | else "WAVES" |
---|
83 | | - | let pmt = value(i.payments[0]) |
---|
84 | | - | let amount = pmt.amount |
---|
85 | | - | let assetId = tryGetString((("nft_" + nftId) + "_assetId")) |
---|
86 | | - | let bidId = toBase58String(i.transactionId) |
---|
87 | | - | let nftStatus = tryGetString((("nft_" + nftId) + "_status")) |
---|
88 | | - | let finalFee = if ((tryGetBoolean((("nft_" + nftId) + "_isArtefact")) == true)) |
---|
89 | | - | then artefactsFeePercent |
---|
90 | | - | else feePercent |
---|
91 | | - | if ((pmt.assetId != paymentAssetId)) |
---|
92 | | - | then throw((("nft does only support " + paymentAssetName) + " payments.")) |
---|
93 | | - | else if ((nftStatus != "open")) |
---|
94 | | - | then throw("nft is closed. You cannot place a bid.") |
---|
95 | | - | else { |
---|
96 | | - | let instantPrice = tryGetInteger((("nft_" + nftId) + "_instantPrice")) |
---|
97 | | - | if ((instantPrice > amount)) |
---|
98 | | - | then throw(("For instant purchase you need to pay at least " + toString(instantPrice))) |
---|
99 | | - | else { |
---|
100 | | - | let nftOwner = tryGetString((("nft_" + nftId) + "_owner")) |
---|
101 | | - | let recordPrice = tryGetInteger((assetId + "_recordPrice")) |
---|
102 | | - | let newRecordPrice = max([recordPrice, amount]) |
---|
103 | | - | [StringEntry((("nft_" + nftId) + "_status"), "finished"), IntegerEntry((("nft_" + nftId) + "_finalPrice"), amount), IntegerEntry((assetId + "_recordPrice"), newRecordPrice), StringEntry((((("assetId_" + assetId) + "_bid_") + bidId) + "_data"), (((((("{\"nftId\": \"" + nftId) + "\", \"author\": \"") + toString(i.originCaller)) + "\", \"amount\": \"") + toString(amount)) + "\", \"status\": \"finished\"}")), DeleteEntry((((("address_" + nftOwner) + "_nft_") + nftId) + "_lockedNFT")), ScriptTransfer(i.originCaller, 1, fromBase58String(getStringValue(this, (("nft_" + nftId) + "_assetId")))), ScriptTransfer(addressFromStringValue(nftOwner), fraction(amount, (100 - finalFee), 100), paymentAssetId), ScriptTransfer(Address(ownerAddress), fraction(amount, finalFee, 100), paymentAssetId)] |
---|
104 | | - | } |
---|
105 | | - | } |
---|
106 | | - | } |
---|
107 | | - | |
---|
| 13 | + | @Verifier(tx) |
---|
| 14 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|