8 | | - | func hashString (data) = { |
---|
9 | | - | let result = toBase64String(sha256(toBytes(data))) |
---|
10 | | - | result |
---|
| 8 | + | let kSell = "sell" |
---|
| 9 | + | |
---|
| 10 | + | let kTrusted = "trusted" |
---|
| 11 | + | |
---|
| 12 | + | let kPrice = "price" |
---|
| 13 | + | |
---|
| 14 | + | func getSlotKey (prefix,nftId) = ((prefix + separator) + toBase58String(nftId)) |
---|
| 15 | + | |
---|
| 16 | + | |
---|
| 17 | + | func getPriceKey (nftId) = ((kPrice + separator) + toBase58String(nftId)) |
---|
| 18 | + | |
---|
| 19 | + | |
---|
| 20 | + | func getSellKey (nftId) = ((kSell + separator) + toBase58String(nftId)) |
---|
| 21 | + | |
---|
| 22 | + | |
---|
| 23 | + | func getAuctionKey (nftId) = ((kAuction + separator) + toBase58String(nftId)) |
---|
| 24 | + | |
---|
| 25 | + | |
---|
| 26 | + | func getTrustedKey (issuer) = ((kTrusted + separator) + toString(issuer)) |
---|
| 27 | + | |
---|
| 28 | + | |
---|
| 29 | + | func addToList (accum,nextValue) = (accum ++ [nextValue]) |
---|
| 30 | + | |
---|
| 31 | + | |
---|
| 32 | + | func joinString (params) = { |
---|
| 33 | + | let length = size(params) |
---|
| 34 | + | if ((length == 0)) |
---|
| 35 | + | then throw("Empty params") |
---|
| 36 | + | else if ((length == 1)) |
---|
| 37 | + | then makeString({ |
---|
| 38 | + | let $l = params |
---|
| 39 | + | let $s = size($l) |
---|
| 40 | + | let $acc0 = nil |
---|
| 41 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 42 | + | then $a |
---|
| 43 | + | else addToList($a, $l[$i]) |
---|
| 44 | + | |
---|
| 45 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 46 | + | then $a |
---|
| 47 | + | else throw("List size exceeds 1") |
---|
| 48 | + | |
---|
| 49 | + | $f0_2($f0_1($acc0, 0), 1) |
---|
| 50 | + | }, separator) |
---|
| 51 | + | else if ((length == 2)) |
---|
| 52 | + | then makeString({ |
---|
| 53 | + | let $l = params |
---|
| 54 | + | let $s = size($l) |
---|
| 55 | + | let $acc0 = nil |
---|
| 56 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 57 | + | then $a |
---|
| 58 | + | else addToList($a, $l[$i]) |
---|
| 59 | + | |
---|
| 60 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 61 | + | then $a |
---|
| 62 | + | else throw("List size exceeds 2") |
---|
| 63 | + | |
---|
| 64 | + | $f0_2($f0_1($f0_1($acc0, 0), 1), 2) |
---|
| 65 | + | }, separator) |
---|
| 66 | + | else if ((length == 3)) |
---|
| 67 | + | then makeString({ |
---|
| 68 | + | let $l = params |
---|
| 69 | + | let $s = size($l) |
---|
| 70 | + | let $acc0 = nil |
---|
| 71 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 72 | + | then $a |
---|
| 73 | + | else addToList($a, $l[$i]) |
---|
| 74 | + | |
---|
| 75 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 76 | + | then $a |
---|
| 77 | + | else throw("List size exceeds 3") |
---|
| 78 | + | |
---|
| 79 | + | $f0_2($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3) |
---|
| 80 | + | }, separator) |
---|
| 81 | + | else if ((length == 4)) |
---|
| 82 | + | then makeString({ |
---|
| 83 | + | let $l = params |
---|
| 84 | + | let $s = size($l) |
---|
| 85 | + | let $acc0 = nil |
---|
| 86 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 87 | + | then $a |
---|
| 88 | + | else addToList($a, $l[$i]) |
---|
| 89 | + | |
---|
| 90 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 91 | + | then $a |
---|
| 92 | + | else throw("List size exceeds 4") |
---|
| 93 | + | |
---|
| 94 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4) |
---|
| 95 | + | }, separator) |
---|
| 96 | + | else if ((length == 5)) |
---|
| 97 | + | then makeString({ |
---|
| 98 | + | let $l = params |
---|
| 99 | + | let $s = size($l) |
---|
| 100 | + | let $acc0 = nil |
---|
| 101 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 102 | + | then $a |
---|
| 103 | + | else addToList($a, $l[$i]) |
---|
| 104 | + | |
---|
| 105 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 106 | + | then $a |
---|
| 107 | + | else throw("List size exceeds 5") |
---|
| 108 | + | |
---|
| 109 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) |
---|
| 110 | + | }, separator) |
---|
| 111 | + | else throw("Max number of parameters exceeded") |
---|
| 127 | + | func joinStruct (params) = match params { |
---|
| 128 | + | case auction: (Address, Int, String, String) => |
---|
| 129 | + | joinString([toString(auction._1), toString(auction._2), auction._3, auction._4]) |
---|
| 130 | + | case sell: (Address, Int) => |
---|
| 131 | + | joinString([toString(sell._1), toString(sell._2)]) |
---|
| 132 | + | case _ => |
---|
| 133 | + | throw("Wrong params tupple") |
---|
| 134 | + | } |
---|
| 135 | + | |
---|
| 136 | + | |
---|
| 137 | + | func setAuction (seller,nftId,startPrice,start,end) = StringEntry(getAuctionKey(nftId), joinStruct($Tuple4(seller, startPrice, start, end))) |
---|
| 138 | + | |
---|
| 139 | + | |
---|
| 140 | + | func setSell (nftId,celler,price) = StringEntry(getSellKey(nftId), joinStruct($Tuple2(celler, price))) |
---|
| 141 | + | |
---|
| 142 | + | |
---|
| 143 | + | func getAuction (nftId) = value(getString(this, getAuctionKey(nftId))) |
---|
| 144 | + | |
---|
| 145 | + | |
---|
| 146 | + | func getSell (nftId) = value(getString(this, getSellKey(nftId))) |
---|
| 147 | + | |
---|
| 148 | + | |
---|
| 149 | + | func calcPriceAtCurrentMoment (assetId,moment) = { |
---|
| 150 | + | let details = getAuction(assetId) |
---|
| 151 | + | let $t027552859 = parseAsAuction(details) |
---|
| 152 | + | let seller = $t027552859._1 |
---|
| 153 | + | let startPriceValue = $t027552859._2 |
---|
| 154 | + | let endPriceValue = $t027552859._3 |
---|
| 155 | + | let startPeriodValue = $t027552859._4 |
---|
| 156 | + | let endPeriodValue = $t027552859._5 |
---|
| 157 | + | if ((moment >= endPeriodValue)) |
---|
| 158 | + | then $Tuple2(seller, endPriceValue) |
---|
| 159 | + | else { |
---|
| 160 | + | let deltaPrice = (startPriceValue - endPriceValue) |
---|
| 161 | + | let period = (endPeriodValue - startPeriodValue) |
---|
| 162 | + | let spended = (moment - startPeriodValue) |
---|
| 163 | + | $Tuple2(seller, (startPriceValue - fraction(spended, deltaPrice, period))) |
---|
| 164 | + | } |
---|
| 165 | + | } |
---|
| 166 | + | |
---|
| 167 | + | |
---|
| 168 | + | func isNft (assetId) = match assetInfo(assetId) { |
---|
| 169 | + | case token: Asset => |
---|
| 170 | + | if (if ((token.decimals == 0)) |
---|
| 171 | + | then (token.quantity == 1) |
---|
| 172 | + | else false) |
---|
| 173 | + | then (token.reissuable == false) |
---|
| 174 | + | else false |
---|
| 175 | + | case _ => |
---|
| 176 | + | false |
---|
| 177 | + | } |
---|
| 178 | + | |
---|
| 179 | + | |
---|
| 180 | + | func isTrustedNft (assetId) = { |
---|
| 181 | + | let issuer = value(assetInfo(assetId)).issuer |
---|
| 182 | + | valueOrElse(getBoolean(this, getTrustedKey(issuer)), false) |
---|
| 183 | + | } |
---|
| 184 | + | |
---|
| 185 | + | |
---|
| 186 | + | func isSellExist (assetId) = isDefined(getString(this, getSellKey(assetId))) |
---|
| 187 | + | |
---|
| 188 | + | |
---|
| 189 | + | func isAuctionExist (assetId) = isDefined(getString(this, getAuctionKey(assetId))) |
---|
| 190 | + | |
---|
| 191 | + | |
---|
| 192 | + | func isCorrectSellPrice (price) = (price > 0) |
---|
| 193 | + | |
---|
| 194 | + | |
---|
| 195 | + | func isCorrectAuctionPrices (startPrice,endPrice) = (startPrice > endPrice) |
---|
| 196 | + | |
---|
| 197 | + | |
---|
| 198 | + | func isAdmin (caller) = (caller == this) |
---|
| 199 | + | |
---|
| 200 | + | |
---|
| 201 | + | func isValidCaller (caller,seller) = if ((caller == this)) |
---|
| 202 | + | then true |
---|
| 203 | + | else (caller == seller) |
---|
| 204 | + | |
---|
| 205 | + | |
---|
| 206 | + | func isAuctionEnded (now,end) = (now > end) |
---|
| 207 | + | |
---|
| 208 | + | |
---|
| 209 | + | func isEnoughFunds (payment,currentMomentPrice) = (payment >= currentMomentPrice) |
---|
| 210 | + | |
---|
| 211 | + | |
---|
| 212 | + | func isWawes (assetId) = (assetId == unit) |
---|
| 213 | + | |
---|
| 214 | + | |
---|
| 215 | + | func isCorrectNft (nftId) = if (!(isNft(nftId))) |
---|
| 216 | + | then throw("Token is not Nft") |
---|
| 217 | + | else if (isSellExist(nftId)) |
---|
| 218 | + | then throw("Sell already exists") |
---|
| 219 | + | else if (isAuctionExist(nftId)) |
---|
| 220 | + | then throw("Auction already exists") |
---|
| 221 | + | else unit |
---|
| 222 | + | |
---|
| 223 | + | |
---|
| 224 | + | func isCorrectPayments (paymentAsset,paymentAmount,price) = if (!(isWawes(paymentAsset))) |
---|
| 225 | + | then throw("Payment must be at WAVES") |
---|
| 226 | + | else if (!(isEnoughFunds(paymentAmount, price))) |
---|
| 227 | + | then throw("Not enough funds") |
---|
| 228 | + | else unit |
---|
| 229 | + | |
---|
| 230 | + | |
---|
| 231 | + | func calcFee () = 0 |
---|
| 232 | + | |
---|
| 233 | + | |
---|
| 234 | + | func calcTrustedFee () = 0 |
---|
| 235 | + | |
---|
| 236 | + | |
---|
| 237 | + | func resultFundsAmounts (isTrusted,paymentAmount,actualPrice) = if (isTrusted) |
---|
| 238 | + | then $Tuple2((actualPrice - calcTrustedFee()), (paymentAmount - actualPrice)) |
---|
| 239 | + | else $Tuple2((actualPrice - calcFee()), (paymentAmount - actualPrice)) |
---|
| 240 | + | |
---|
| 241 | + | |
---|
| 242 | + | func getSlot (nftId) = if (isSellExist(nftId)) |
---|
| 243 | + | then $Tuple2(kSell, getSell(nftId)) |
---|
| 244 | + | else if (isAuctionExist(nftId)) |
---|
| 245 | + | then $Tuple2(kAuction, getAuction(nftId)) |
---|
| 246 | + | else throw("Slot doesn`t exist") |
---|
| 247 | + | |
---|
| 248 | + | |
---|
| 249 | + | let kBuy = "buy" |
---|
| 250 | + | |
---|
| 251 | + | let kBid = "bid" |
---|
| 252 | + | |
---|
| 253 | + | let statusForNFT = $Tuple4("OPEN", "CLOSED", "REWARDED", "CANCELED") |
---|
| 254 | + | |
---|
| 255 | + | let dAppAddress = base58'3MvjAaDYHpS4A5K4CV3kZMMEH9m9JdBSvbq' |
---|
| 256 | + | |
---|
30 | | - | func startAuction (duration,startPrice,priceAssetId,deposit) = { |
---|
31 | | - | let auctionId = toBase58String(i.transactionId) |
---|
32 | | - | let revealStart = (lastBlock.height + duration) |
---|
33 | | - | let closingStart = (revealStart + revealDuration) |
---|
34 | | - | let organizer = toBase58String(i.caller.bytes) |
---|
35 | | - | let organizerKey = (organizer + "_organizer") |
---|
36 | | - | let maybeOrganizerList = getString(this, organizerKey) |
---|
37 | | - | let organizerList = if (isDefined(maybeOrganizerList)) |
---|
38 | | - | then value(maybeOrganizerList) |
---|
39 | | - | else "" |
---|
40 | | - | let newOrganizerList = ((organizerList + " ") + auctionId) |
---|
41 | | - | let pmt = extract(i.payment) |
---|
42 | | - | if ((duration > maxAuctionDuration)) |
---|
43 | | - | then throw(("Duration is too long. Must be less than " + toString(maxAuctionDuration))) |
---|
44 | | - | else if (!(isDefined(pmt.assetId))) |
---|
45 | | - | then throw("Payment currency should not be in WAVES") |
---|
46 | | - | else if ((pmt.amount != 1)) |
---|
47 | | - | then throw("Payment amount should be only one NFT") |
---|
48 | | - | else if ((0 >= startPrice)) |
---|
49 | | - | then throw("Start price should be > 0") |
---|
50 | | - | else if ((startPrice >= deposit)) |
---|
51 | | - | then throw((("Start price should be < deposit (" + toString(deposit)) + ")")) |
---|
52 | | - | else if ((0 >= duration)) |
---|
53 | | - | then throw("Duration should be > 0") |
---|
54 | | - | else WriteSet([DataEntry((auctionId + "_reveal_start"), revealStart), DataEntry((auctionId + "_closing_start"), closingStart), DataEntry((auctionId + "_deposit"), deposit), DataEntry((auctionId + "_unrevealed_count"), 0), DataEntry((auctionId + "_top_price"), 0), DataEntry((auctionId + "_second_price"), 0), DataEntry((auctionId + "_settle"), false), DataEntry((auctionId + "_organizer"), organizer), DataEntry((auctionId + "_lot_assetId"), if (isDefined(pmt.assetId)) |
---|
55 | | - | then toBase58String(value(pmt.assetId)) |
---|
56 | | - | else "WAVES"), DataEntry((auctionId + "_lot_amount"), pmt.amount), DataEntry((auctionId + "_startPrice"), startPrice), DataEntry((auctionId + "_priceAssetId"), priceAssetId), DataEntry(organizerKey, newOrganizerList), DataEntry("test", hashString(("123" + toString(startPrice))))]) |
---|
| 258 | + | func createNft (nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = { |
---|
| 259 | + | let newToken = Issue(nft_name, nft_description, 1, 0, false) |
---|
| 260 | + | let issueId = calculateAssetId(newToken) |
---|
| 261 | + | let txId = i.transactionId |
---|
| 262 | + | [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))] |
---|
62 | | - | func bid (auctionId,hashBidAmount) = { |
---|
63 | | - | let pmt = extract(i.payment) |
---|
64 | | - | let pmtAssetIdStr = if (isDefined(pmt.assetId)) |
---|
65 | | - | then toBase58String(value(pmt.assetId)) |
---|
66 | | - | else "WAVES" |
---|
67 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
68 | | - | let endHeight = getIntegerValue(this, (auctionId + "_reveal_start")) |
---|
69 | | - | let startPrice = getIntegerValue(this, (auctionId + "_startPrice")) |
---|
70 | | - | let priceAssetId = getStringValue(this, (auctionId + "_priceAssetId")) |
---|
71 | | - | let organizer = getStringValue(this, (auctionId + "_organizer")) |
---|
72 | | - | let deposit = getIntegerValue(this, (auctionId + "_deposit")) |
---|
73 | | - | let unrevealedCount = getIntegerValue(this, (auctionId + "_unrevealed_count")) |
---|
74 | | - | let bidder = getString(this, (callerAddressStr + "_bidder")) |
---|
75 | | - | let bidFromTheSameUser = isDefined(getString(this, ((auctionId + callerAddressStr) + "bid_hash"))) |
---|
76 | | - | if ((lastBlock.height >= endHeight)) |
---|
77 | | - | then throw("Auction already finished") |
---|
78 | | - | else if (if (!(bidFromTheSameUser)) |
---|
79 | | - | then (priceAssetId != pmtAssetIdStr) |
---|
80 | | - | else false) |
---|
81 | | - | then throw((("Bid must be in asset '" + priceAssetId) + "'")) |
---|
82 | | - | else if (!(isDefined(organizer))) |
---|
83 | | - | then throw("Organizer should be defined") |
---|
84 | | - | else if (if (!(bidFromTheSameUser)) |
---|
85 | | - | then (pmt.amount != deposit) |
---|
86 | | - | else false) |
---|
87 | | - | then throw("Payment should be equel to deposit") |
---|
88 | | - | else { |
---|
89 | | - | let inc = if (bidFromTheSameUser) |
---|
90 | | - | then 0 |
---|
91 | | - | else 1 |
---|
92 | | - | WriteSet([DataEntry(((auctionId + callerAddressStr) + "_revealed"), false), DataEntry(((auctionId + callerAddressStr) + "_bid_hash"), hashBidAmount), DataEntry(((auctionId + callerAddressStr) + "_settle"), false), DataEntry((auctionId + "_unrevealed_cont"), (unrevealedCount + inc)), DataEntry((callerAddressStr + "_bidder"), (((if (isDefined(bidder)) |
---|
93 | | - | then value(bidder) |
---|
94 | | - | else "") + " ") + auctionId))]) |
---|
95 | | - | } |
---|
| 268 | + | func sellNFT (price) = { |
---|
| 269 | + | let txId = i.transactionId |
---|
| 270 | + | let seller = i.caller.bytes |
---|
| 271 | + | let $t065196604 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) |
---|
| 272 | + | let token0 = $t065196604._1 |
---|
| 273 | + | let amount0 = $t065196604._2 |
---|
| 274 | + | if (!(isNft(token0))) |
---|
| 275 | + | then throw("Token is not NFT") |
---|
| 276 | + | else [StringEntry((("nft_" + toBase58String(seller)) + "_owner"), toBase58String(seller)), StringEntry(((((kPrice + separator) + toBase58String(value(i.payments[0].assetId))) + "_") + toString(i.caller)), price), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))] |
---|
101 | | - | func reveal (auctionId,bidAmount,salt) = { |
---|
102 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
103 | | - | let organizer = getStringValue(this, (auctionId + "_organizer")) |
---|
104 | | - | let bidHash = getStringValue(this, ((auctionId + callerAddressStr) + "_bid_hash")) |
---|
105 | | - | let revealed = getBooleanValue(this, ((auctionId + callerAddressStr) + "_revealed")) |
---|
106 | | - | let revealStart = getIntegerValue(this, (auctionId + "_reveal_start")) |
---|
107 | | - | let closingStart = getIntegerValue(this, (auctionId + "_closing_start")) |
---|
108 | | - | let topPrice = getIntegerValue(this, (auctionId + "_top_price")) |
---|
109 | | - | let secondPrice = getIntegerValue(this, (auctionId + "_second_price")) |
---|
110 | | - | let winner = getString(this, (auctionId + "_winner")) |
---|
111 | | - | let unrevealedCount = getIntegerValue(this, (auctionId + "_unrevealed_count")) |
---|
112 | | - | let bidAmountAsStr = toString(bidAmount) |
---|
113 | | - | let stringToHash = (salt + bidAmountAsStr) |
---|
114 | | - | let hash = hashString(stringToHash) |
---|
115 | | - | if (!(isDefined(organizer))) |
---|
116 | | - | then throw("Organizer is not defined") |
---|
117 | | - | else if (!(isDefined(bidHash))) |
---|
118 | | - | then throw("Bid is not defined") |
---|
119 | | - | else if (if ((revealStart > lastBlock.height)) |
---|
120 | | - | then true |
---|
121 | | - | else (lastBlock.height > closingStart)) |
---|
122 | | - | then throw(((((("Auction should be revealed between reveal (" + toString(revealStart)) + ") and closing (") + toString(closingStart)) + ") time, now is ") + toString(lastBlock.height))) |
---|
123 | | - | else if (isDefined(i.payment)) |
---|
124 | | - | then throw("Payment shoud not exist") |
---|
125 | | - | else if ((hash != bidHash)) |
---|
126 | | - | then throw("Bid hash from bidMount and sault is not equel with hash from the caller bid") |
---|
127 | | - | else if ((revealed == true)) |
---|
128 | | - | then throw("The bid has been already revealed") |
---|
129 | | - | else { |
---|
130 | | - | let topPrice2 = if ((bidAmount > topPrice)) |
---|
131 | | - | then bidAmount |
---|
132 | | - | else topPrice |
---|
133 | | - | let secondPrice2 = if ((bidAmount > topPrice)) |
---|
134 | | - | then topPrice |
---|
135 | | - | else if ((bidAmount > secondPrice)) |
---|
136 | | - | then bidAmount |
---|
137 | | - | else secondPrice |
---|
138 | | - | let winner2 = if ((bidAmount > topPrice)) |
---|
139 | | - | then callerAddressStr |
---|
140 | | - | else value(winner) |
---|
141 | | - | WriteSet([DataEntry((auctionId + "_top_price"), topPrice2), DataEntry((auctionId + "_second_price"), secondPrice2), DataEntry((auctionId + "_winner"), winner2), DataEntry(((auctionId + callerAddressStr) + "_revealed"), true), DataEntry((auctionId + "_unrevealed_cont"), (unrevealedCount - 1))]) |
---|
142 | | - | } |
---|
| 282 | + | func buyNFT (nftID,current_nft_owner) = { |
---|
| 283 | + | let assetId = fromBase58String(nftID) |
---|
| 284 | + | let amount = value(i.payments[0].amount) |
---|
| 285 | + | let checkOwnerIsSame = match getString(this, (("nft_" + current_nft_owner) + "_owner")) { |
---|
| 286 | + | case a: String => |
---|
| 287 | + | a |
---|
| 288 | + | case _ => |
---|
| 289 | + | false |
---|
| 290 | + | } |
---|
| 291 | + | let price = getStringValue(((((kPrice + separator) + nftID) + "_") + current_nft_owner)) |
---|
| 292 | + | let owner = valueOrErrorMessage(getStringValue(((nftID + separator) + "Owner")), "No owner") |
---|
| 293 | + | if ((i.payments[0].assetId != unit)) |
---|
| 294 | + | then throw("Pay in waves") |
---|
| 295 | + | else if ((checkOwnerIsSame == toString(i.caller))) |
---|
| 296 | + | then throw("Owner of NFT not able to purchase") |
---|
| 297 | + | else [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(Address(fromBase58String(owner)), amount, unit), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount))), DeleteEntry((("nft_" + current_nft_owner) + "_owner"))] |
---|
148 | | - | func withdraw (auctionId) = { |
---|
149 | | - | let pmt = i.payment |
---|
150 | | - | let callerAddressStr = toBase58String(i.caller.bytes) |
---|
151 | | - | let closingStart = getIntegerValue(this, (auctionId + "_closing_start")) |
---|
152 | | - | let unrevealedCount = getIntegerValue(this, (auctionId + "_unrevealed_count")) |
---|
153 | | - | let organizer = getStringValue(this, (auctionId + "_organizer")) |
---|
154 | | - | let revealTime = getIntegerValue(this, (auctionId + "_reveal_start")) |
---|
155 | | - | let winner = getString(this, (auctionId + "_winner")) |
---|
156 | | - | let lotAssetId = getStringValue(this, (auctionId + "_lot_assetId")) |
---|
157 | | - | let lotAmount = getIntegerValue(this, (auctionId + "_lot_amount")) |
---|
158 | | - | let priceAssetId = getStringValue(this, (auctionId + "_priceAssetId")) |
---|
159 | | - | let settle = getBooleanValue(this, (auctionId + "_settle")) |
---|
160 | | - | let secondPrice = getIntegerValue(this, (auctionId + "_second_price")) |
---|
161 | | - | let deposit = getIntegerValue(this, (auctionId + "_deposit")) |
---|
162 | | - | let lotAsset = if ((lotAssetId == "WAVES")) |
---|
163 | | - | then unit |
---|
164 | | - | else fromBase58String(lotAssetId) |
---|
165 | | - | let priceAsset = if (if ((priceAssetId == "WAVES")) |
---|
166 | | - | then true |
---|
167 | | - | else (priceAssetId == "")) |
---|
168 | | - | then unit |
---|
169 | | - | else fromBase58String(priceAssetId) |
---|
170 | | - | if (isDefined(pmt)) |
---|
171 | | - | then throw("Payment shoud not exist") |
---|
172 | | - | else if (!(isDefined(organizer))) |
---|
173 | | - | then throw("Organizer shoud exist") |
---|
174 | | - | else if (if ((closingStart > (revealTime - lastBlock.height))) |
---|
175 | | - | then (unrevealedCount != 0) |
---|
176 | | - | else false) |
---|
177 | | - | then throw("Its too early to withdraw") |
---|
178 | | - | else if (if ((callerAddressStr == organizer)) |
---|
179 | | - | then true |
---|
180 | | - | else (callerAddressStr == winner)) |
---|
181 | | - | then if ((settle == true)) |
---|
182 | | - | then throw("Illegal state, settle shoould be false") |
---|
183 | | - | else if (!(isDefined(winner))) |
---|
184 | | - | then if (isDefined(getString(this, (auctionId + "_lot_passed")))) |
---|
185 | | - | then throw("Organizer has already got his lot back") |
---|
186 | | - | else { |
---|
187 | | - | let organizerAddr = addressFromStringValue(value(organizer)) |
---|
188 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_settle"), true), DataEntry((organizer + "_organizer"), removeFromList(getStringValue(this, (organizer + "_organizer")), auctionId))]), TransferSet([ScriptTransfer(organizerAddr, lotAmount, lotAsset)])) |
---|
189 | | - | } |
---|
190 | | - | else { |
---|
191 | | - | let winnerAddr = addressFromStringValue(value(winner)) |
---|
192 | | - | let organizerAddr = addressFromStringValue(value(organizer)) |
---|
193 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_settle"), true), DataEntry((value(winner) + "_bidder"), removeFromList(getStringValue(this, (value(winner) + "_bidder")), auctionId)), DataEntry((organizer + "_organizer"), removeFromList(getStringValue(this, (organizer + "_organizer")), auctionId))]), TransferSet([ScriptTransfer(winnerAddr, lotAmount, lotAsset), ScriptTransfer(organizerAddr, secondPrice, priceAsset), ScriptTransfer(winnerAddr, (deposit - secondPrice), priceAsset), ScriptTransfer(winnerAddr, (deposit - secondPrice), priceAsset)])) |
---|
194 | | - | } |
---|
195 | | - | else if ((settle == true)) |
---|
196 | | - | then throw("Illegal state, settle shoould be false") |
---|
197 | | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_settle"), true), DataEntry((callerAddressStr + "_bidder"), removeFromList(getStringValue(this, (callerAddressStr + "_bidder")), auctionId))]), TransferSet([ScriptTransfer(i.caller, deposit, priceAsset)])) |
---|
| 303 | + | func addAuction (start,end,startPrice) = { |
---|
| 304 | + | let txId = i.transactionId |
---|
| 305 | + | let nftId = value(i.payments[0].assetId) |
---|
| 306 | + | let price = value(startPrice) |
---|
| 307 | + | let auction = $Tuple4(i.caller, price, start, end) |
---|
| 308 | + | let caller = i.caller.bytes |
---|
| 309 | + | let checkNftAuctioned = match getString(this, (((toBase58String(nftId) + separator) + "nft_status_") + toBase58String(caller))) { |
---|
| 310 | + | case a: String => |
---|
| 311 | + | a |
---|
| 312 | + | case _ => |
---|
| 313 | + | false |
---|
| 314 | + | } |
---|
| 315 | + | if ((checkNftAuctioned == statusForNFT._1)) |
---|
| 316 | + | then throw("Already in Auction list") |
---|
| 317 | + | else [StringEntry(((toBase58String(txId) + "_nft_start_auction_date_") + toBase58String(caller)), start), StringEntry(((toBase58String(txId) + "_nft_end_auction_date_") + toBase58String(caller)), end), IntegerEntry(((toBase58String(txId) + "_nft_start_price_") + toBase58String(caller)), startPrice), StringEntry((toBase58String(txId) + "_nft_owner"), toString(i.caller)), StringEntry((toBase58String(txId) + "_nft_on_auction"), toBase58String(nftId)), StringEntry(((toBase58String(txId) + "_nft_status_") + toBase58String(caller)), statusForNFT._1)] |
---|
| 318 | + | } |
---|
| 319 | + | |
---|
| 320 | + | |
---|
| 321 | + | |
---|
| 322 | + | @Callable(i) |
---|
| 323 | + | func placeBid (tx_Id,nftId,nft_owner,bid_price) = { |
---|
| 324 | + | let txId = i.transactionId |
---|
| 325 | + | let caller = i.caller |
---|
| 326 | + | let assetId = fromBase58String(nftId) |
---|
| 327 | + | let amount = value(i.payments[0].amount) |
---|
| 328 | + | let checkNftAuctioned = match getString(this, (((nftId + separator) + "nft_status_") + nft_owner)) { |
---|
| 329 | + | case a: String => |
---|
| 330 | + | a |
---|
| 331 | + | case _ => |
---|
| 332 | + | false |
---|
| 333 | + | } |
---|
| 334 | + | if ((i.payments[0].assetId != unit)) |
---|
| 335 | + | then throw("Pay in waves") |
---|
| 336 | + | else if ((checkNftAuctioned != statusForNFT._1)) |
---|
| 337 | + | then throw("Not open in auction list") |
---|
| 338 | + | else [StringEntry(((("nft_id_" + nftId) + "_") + toBase58String(caller.bytes)), nftId), StringEntry(((("nft_owner_" + nftId) + "_") + toBase58String(caller.bytes)), nft_owner), StringEntry(((("bidding_for_" + nftId) + "_by_") + toBase58String(caller.bytes)), toBase58String(caller.bytes)), StringEntry(((("bid_price_for" + nftId) + "_by_") + toBase58String(caller.bytes)), toString(bid_price)), StringEntry(((("transfer_nft_to_dappwith_bid_price_for_" + nftId) + "_by_") + toBase58String(caller.bytes)), toBase58String(dAppAddress))] |
---|
| 339 | + | } |
---|
| 340 | + | |
---|
| 341 | + | |
---|
| 342 | + | |
---|
| 343 | + | @Callable(i) |
---|
| 344 | + | func acceptBidOffer (nftId,accepted_address,bid_amount_from_user) = { |
---|
| 345 | + | let caller = i.caller.bytes |
---|
| 346 | + | let assetId = fromBase58String(nftId) |
---|
| 347 | + | let acceptedAddressOfBidder = fromBase58String(accepted_address) |
---|
| 348 | + | [ScriptTransfer(Address(i.caller.bytes), bid_amount_from_user, unit), ScriptTransfer(Address(acceptedAddressOfBidder), 1, assetId), StringEntry(((nftId + "_rewarded_to_") + accepted_address), accepted_address), StringEntry(("nft_transfer_status_from" + toBase58String(caller)), statusForNFT._3), StringEntry(((("nft_transfer_status_" + nftId) + "_transfer_to_") + accepted_address), accepted_address), DeleteEntry((((nftId + separator) + "nft_status_") + toBase58String(caller)))] |
---|