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") |
---|
112 | | - | } |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | func parseAsAuction (details) = { |
---|
116 | | - | let res = split(details, separator) |
---|
117 | | - | $Tuple5(addressFromStringValue(res[0]), parseIntValue(res[1]), parseIntValue(res[2]), parseIntValue(res[3]), parseIntValue(res[4])) |
---|
118 | | - | } |
---|
119 | | - | |
---|
120 | | - | |
---|
121 | | - | func parseAsSell (details) = { |
---|
122 | | - | let res = split(details, separator) |
---|
123 | | - | $Tuple2(addressFromStringValue(res[0]), parseIntValue(res[1])) |
---|
124 | | - | } |
---|
125 | | - | |
---|
126 | | - | |
---|
127 | | - | func joinStruct (params) = match params { |
---|
128 | | - | case auction: (Address, Int, Int, Int, Int) => |
---|
129 | | - | joinString([toString(auction._1), toString(auction._2), toString(auction._3), toString(auction._4), toString(auction._5)]) |
---|
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,endPrice,start,end) = StringEntry(getAuctionKey(nftId), joinStruct($Tuple5(seller, startPrice, endPrice, 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 $t028172921 = parseAsAuction(details) |
---|
152 | | - | let seller = $t028172921._1 |
---|
153 | | - | let startPriceValue = $t028172921._2 |
---|
154 | | - | let endPriceValue = $t028172921._3 |
---|
155 | | - | let startPeriodValue = $t028172921._4 |
---|
156 | | - | let endPeriodValue = $t028172921._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 isCorrectAuctionPeriod (start,end) = (end > start) |
---|
196 | | - | |
---|
197 | | - | |
---|
198 | | - | func isCorrectAuctionPrices (startPrice,endPrice) = (startPrice > endPrice) |
---|
199 | | - | |
---|
200 | | - | |
---|
201 | | - | func isAdmin (caller) = (caller == this) |
---|
202 | | - | |
---|
203 | | - | |
---|
204 | | - | func isValidCaller (caller,seller) = if ((caller == this)) |
---|
205 | | - | then true |
---|
206 | | - | else (caller == seller) |
---|
207 | | - | |
---|
208 | | - | |
---|
209 | | - | func isAuctionEnded (now,end) = (now > end) |
---|
210 | | - | |
---|
211 | | - | |
---|
212 | | - | func isEnoughFunds (payment,currentMomentPrice) = (payment >= currentMomentPrice) |
---|
213 | | - | |
---|
214 | | - | |
---|
215 | | - | func isWawes (assetId) = (assetId == unit) |
---|
216 | | - | |
---|
217 | | - | |
---|
218 | | - | func isCorrectNft (nftId) = if (!(isNft(nftId))) |
---|
219 | | - | then throw("Token is not Nft") |
---|
220 | | - | else if (isSellExist(nftId)) |
---|
221 | | - | then throw("Sell already exists") |
---|
222 | | - | else if (isAuctionExist(nftId)) |
---|
223 | | - | then throw("Auction already exists") |
---|
224 | | - | else unit |
---|
225 | | - | |
---|
226 | | - | |
---|
227 | | - | func isCorrectPayments (paymentAsset,paymentAmount,price) = if (!(isWawes(paymentAsset))) |
---|
228 | | - | then throw("Payment must be at WAVES") |
---|
229 | | - | else if (!(isEnoughFunds(paymentAmount, price))) |
---|
230 | | - | then throw("Not enough funds") |
---|
231 | | - | else unit |
---|
232 | | - | |
---|
233 | | - | |
---|
234 | | - | func calcFee () = 0 |
---|
235 | | - | |
---|
236 | | - | |
---|
237 | | - | func calcTrustedFee () = 0 |
---|
238 | | - | |
---|
239 | | - | |
---|
240 | | - | func resultFundsAmounts (isTrusted,paymentAmount,actualPrice) = if (isTrusted) |
---|
241 | | - | then $Tuple2((actualPrice - calcTrustedFee()), (paymentAmount - actualPrice)) |
---|
242 | | - | else $Tuple2((actualPrice - calcFee()), (paymentAmount - actualPrice)) |
---|
243 | | - | |
---|
244 | | - | |
---|
245 | | - | func getSlot (nftId) = if (isSellExist(nftId)) |
---|
246 | | - | then $Tuple2(kSell, getSell(nftId)) |
---|
247 | | - | else if (isAuctionExist(nftId)) |
---|
248 | | - | then $Tuple2(kAuction, getAuction(nftId)) |
---|
249 | | - | else throw("Slot doesn`t exist") |
---|
| 48 | + | func getExecutorRaitingKey (incomingAddress) = makeString([toString(incomingAddress), kExecutor, kRating], separator) |
---|
263 | | - | func addAuction (startPrice,endPrice,start,end,nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = { |
---|
264 | | - | let nftId = value(i.payments[0].assetId) |
---|
265 | | - | valueOrElse(isCorrectNft(nftId), if (!(isCorrectAuctionPeriod(start, end))) |
---|
266 | | - | then throw("Period is not correct") |
---|
267 | | - | else if (!(isCorrectAuctionPrices(startPrice, endPrice))) |
---|
268 | | - | then throw("Start price must be > endPrice") |
---|
269 | | - | else [setAuction(i.caller, nftId, startPrice, endPrice, start, end), StringEntry(((toBase58String(nftId) + separator) + "nft_owner"), toString(i.caller)), StringEntry(((toBase58String(nftId) + separator) + "nft_type"), nft_type), StringEntry(((toBase58String(nftId) + separator) + "nft_tags"), nft_tags), StringEntry(((toBase58String(nftId) + separator) + "nft_dAppAddress"), nft_dAppAddress), IntegerEntry(((toBase58String(nftId) + separator) + "nft_selling_price"), nft_selling_price), StringEntry(((toBase58String(nftId) + separator) + "nft_onSell"), nft_onSell), StringEntry(((toBase58String(nftId) + separator) + "nft_data"), nft_data)]) |
---|
| 70 | + | func cancelOrder (name) = [DeleteEntry(getDescKey(i.caller, name)), DeleteEntry(getPriceKey(i.caller, name)), DeleteEntry(getStatusKey(i.caller, name, kCustomer)), DeleteEntry(getOwnerKey(i.caller, name))] |
---|
| 71 | + | |
---|
| 72 | + | |
---|
| 73 | + | |
---|
| 74 | + | @Callable(i) |
---|
| 75 | + | func confirmOffer (name,address,desc) = { |
---|
| 76 | + | let isExist = getString(this, getExecutorAddressKey(i.caller, name)) |
---|
| 77 | + | let owner = valueOrErrorMessage(getStringValue(this, getOwnerKey(i.caller, name)), "This order does not exist") |
---|
| 78 | + | if ((owner != toString(i.caller))) |
---|
| 79 | + | then throw("You are not the order owner") |
---|
| 80 | + | else if (isDefined(isExist)) |
---|
| 81 | + | then [StringEntry(getStatusKey(i.caller, name, kCustomer), IN_WORK), StringEntry(getStatusKey(value(addressFromString(address)), name, kExecutor), IN_WORK)] |
---|
| 82 | + | else throw("This offer does not exist") |
---|
275 | | - | func buyFromSlot (nftId) = { |
---|
276 | | - | let $t067826871 = $Tuple2(i.payments[0].assetId, value(i.payments[0].amount)) |
---|
277 | | - | let paymentAsset = $t067826871._1 |
---|
278 | | - | let paymentAmount = $t067826871._2 |
---|
279 | | - | let assetId = fromBase58String(nftId) |
---|
280 | | - | let $t069156953 = getSlot(assetId) |
---|
281 | | - | let type = $t069156953._1 |
---|
282 | | - | let details = $t069156953._2 |
---|
283 | | - | let baseRes = [ScriptTransfer(i.caller, 1, assetId), DeleteEntry(getSlotKey(type, assetId))] |
---|
284 | | - | if ((type == kSell)) |
---|
285 | | - | then { |
---|
286 | | - | let $t070957142 = parseAsSell(details) |
---|
287 | | - | let seller = $t070957142._1 |
---|
288 | | - | let priceValue = $t070957142._2 |
---|
289 | | - | valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, priceValue), { |
---|
290 | | - | let $t072277329 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, priceValue) |
---|
291 | | - | let sellerAmount = $t072277329._1 |
---|
292 | | - | let buyerAmount = $t072277329._2 |
---|
293 | | - | let updatedRes = (baseRes ++ [ScriptTransfer(seller, sellerAmount, unit)]) |
---|
294 | | - | if ((buyerAmount > 0)) |
---|
295 | | - | then (updatedRes ++ [ScriptTransfer(i.caller, buyerAmount, unit)]) |
---|
296 | | - | else updatedRes |
---|
297 | | - | }) |
---|
298 | | - | } |
---|
299 | | - | else { |
---|
300 | | - | let $t075467615 = calcPriceAtCurrentMoment(assetId, height) |
---|
301 | | - | let seller = $t075467615._1 |
---|
302 | | - | let actualPrice = $t075467615._2 |
---|
303 | | - | valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, actualPrice), { |
---|
304 | | - | let $t077017804 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, actualPrice) |
---|
305 | | - | let sellerAmount = $t077017804._1 |
---|
306 | | - | let buyerAmount = $t077017804._2 |
---|
307 | | - | let updatedRes = (baseRes ++ [ScriptTransfer(seller, sellerAmount, unit)]) |
---|
308 | | - | if ((buyerAmount > 0)) |
---|
309 | | - | then (updatedRes ++ [ScriptTransfer(i.caller, buyerAmount, unit)]) |
---|
310 | | - | else updatedRes |
---|
311 | | - | }) |
---|
312 | | - | } |
---|
| 88 | + | func taskDoneCustomer (name,address) = { |
---|
| 89 | + | let customerRating = valueOrElse(getInteger(this, getCustomerRaitingKey(i.caller)), 0) |
---|
| 90 | + | let executorRating = valueOrElse(getInteger(this, getExecutorRaitingKey(value(addressFromString(address)))), 0) |
---|
| 91 | + | let amount = valueOrErrorMessage(getIntegerValue(this, getPriceKey(i.caller, name)), "No order price") |
---|
| 92 | + | let owner = valueOrErrorMessage(getStringValue(this, getOwnerKey(i.caller, name)), "This order does not exist") |
---|
| 93 | + | if ((owner != toString(i.caller))) |
---|
| 94 | + | then throw("You are not the order owner") |
---|
| 95 | + | else [StringEntry(getStatusKey(value(addressFromString(address)), name, kExecutor), COMPLETED_STATUS), StringEntry(getStatusKey(i.caller, name, kCustomer), COMPLETED_STATUS), ScriptTransfer(value(addressFromString(address)), amount, unit), IntegerEntry(getCustomerRaitingKey(i.caller), (customerRating + 1)), IntegerEntry(getExecutorRaitingKey(value(addressFromString(address))), (executorRating + 1))] |
---|
318 | | - | func declineSlot (nftId) = { |
---|
319 | | - | let assetId = fromBase58String(nftId) |
---|
320 | | - | let $t081058143 = getSlot(assetId) |
---|
321 | | - | let type = $t081058143._1 |
---|
322 | | - | let details = $t081058143._2 |
---|
323 | | - | let baseRes = [DeleteEntry(getSlotKey(type, assetId))] |
---|
324 | | - | if ((type == kSell)) |
---|
325 | | - | then { |
---|
326 | | - | let $t082358282 = parseAsSell(details) |
---|
327 | | - | let seller = $t082358282._1 |
---|
328 | | - | let priceValue = $t082358282._2 |
---|
329 | | - | if (!(isValidCaller(i.caller, seller))) |
---|
330 | | - | then throw("Invalid caller") |
---|
331 | | - | else (baseRes ++ [ScriptTransfer(seller, 1, assetId)]) |
---|
332 | | - | } |
---|
333 | | - | else { |
---|
334 | | - | let $t084278531 = parseAsAuction(details) |
---|
335 | | - | let seller = $t084278531._1 |
---|
336 | | - | let startPriceValue = $t084278531._2 |
---|
337 | | - | let endPriceValue = $t084278531._3 |
---|
338 | | - | let startPeriodValue = $t084278531._4 |
---|
339 | | - | let endPeriodValue = $t084278531._5 |
---|
340 | | - | if (!(isValidCaller(i.caller, seller))) |
---|
341 | | - | then throw("Invalid caller") |
---|
342 | | - | else if (!(isAuctionEnded(height, endPeriodValue))) |
---|
343 | | - | then throw("Wait for end of auction") |
---|
344 | | - | else (baseRes ++ [ScriptTransfer(seller, 1, assetId)]) |
---|
345 | | - | } |
---|
| 101 | + | func offer (name,address,desc) = { |
---|
| 102 | + | let isExist = valueOrErrorMessage(getString(this, getDescKey(value(addressFromString(address)), name)), "This order does not exist") |
---|
| 103 | + | if ((isExist == isExist)) |
---|
| 104 | + | then [StringEntry(getExecutorAddressKey(value(addressFromString(address)), name), toString(i.caller)), StringEntry(getDescKey(i.caller, name), desc), StringEntry(getStatusKey(value(addressFromString(address)), name, kCustomer), ANYS_SUGGESTION_STATUS), StringEntry(getStatusKey(i.caller, name, kExecutor), CREATE_STATUS)] |
---|
| 105 | + | else throw("Strict value is not equal to itself.") |
---|