tx · 4nz84i567S4c4o9BhYJPo5y9qpTogefVbsrQJ4eZynJX

3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx:  -0.01000000 Waves

2022.11.22 09:03 [2327940] smart account 3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx > SELF 0.00000000 Waves

{ "type": 13, "id": "4nz84i567S4c4o9BhYJPo5y9qpTogefVbsrQJ4eZynJX", "fee": 1000000, "feeAssetId": null, "timestamp": 1669097016000, "version": 2, "chainId": 84, "sender": "3N85YW6NZ9pLYvSdt1ASMQTGxvncnU1vUNx", "senderPublicKey": "EKZmHJ5bK3qKKgRdq8rAamt9qrDbVMLARzRqXoQW258v", "proofs": [ "57UQLDHmP4cML8ukbdnw95TfMhAUQN79hxBYpQ49sHoYvy9hptAhekpd89iu7x7H1VpVScbSZttDdT553Kj6qPDj" ], "script": "base64:BgIfCAISCwoJCAgICAgBCAgIEgQKAggIEgMKAQgSAwoBAQUACXNlcGFyYXRvcgIBXwAEa0J1eQIDYnV5AAVrU2VsbAIEc2VsbAAGa1ByaWNlAgVwcmljZQEFaXNOZnQBB2Fzc2V0SWQEByRtYXRjaDAJAOwHAQUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgVBc3NldAQFdG9rZW4FByRtYXRjaDADAwkAAAIIBQV0b2tlbghkZWNpbWFscwAACQAAAggFBXRva2VuCHF1YW50aXR5AAEHCQAAAggFBXRva2VuCnJlaXNzdWFibGUHBwcEAWkBCWNyZWF0ZU5mdAkIbmZ0X25hbWUJbmZ0X293bmVyD25mdF9kQXBwQWRkcmVzcwhuZnRfdHlwZQhuZnRfdGFncxFuZnRfc2VsbGluZ19wcmljZQ9uZnRfZGVzY3JpcHRpb24KbmZ0X29uU2VsbAhuZnRfZGF0YQQIbmV3VG9rZW4JAMIIBQUIbmZ0X25hbWUFD25mdF9kZXNjcmlwdGlvbgABAAAHBAdpc3N1ZUlkCQC4CAEFCG5ld1Rva2VuCQDMCAIFCG5ld1Rva2VuCQDMC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ZW4wCAULJHQwMjM2OTI0NTQCXzEEB2Ftb3VudDAIBQskdDAyMzY5MjQ1NAJfMgMJAQEhAQkBBWlzTmZ0AQUGdG9rZW4wCQACAQIQVG9rZW4gaXMgbm90IE5GVAkAzAgCCQELU3RyaW5nRW50cnkCCQCsAgIJAKwCAgUGa1ByaWNlBQlzZXBhcmF0b3IJANgEAQkBBXZhbHVlAQgJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkCQCkAwEFBXByaWNlCQDMCAIJAQtTdHJpbmdFbnRyeQIJAKwCAgkArAICCQClCAEIBQFpBmNhbGxlcgUJc2VwYXJhdG9yBQVrU2VsbAkArAICCQCsAgIJANgEAQUGdG9rZW4wBQlzZXBhcmF0b3IJAKQDAQUHYW1vdW50MAUDbmlsACX1Oo8=", "height": 2327940, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: G1bSyyrZspz5LaMzX81oGa9VMKu4XA6UXBfdjFWpqbvq Next: 9BsWZFwxwdHFvNEJsHsi9PzgkUZSBWJVzZxKnNcyL9K1 Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let separator = "_"
55
6-let kAuction = "auction"
6+let kBuy = "buy"
77
88 let kSell = "sell"
99
10-let kTrusted = "trusted"
11-
1210 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")
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-
16711
16812 func isNft (assetId) = match assetInfo(assetId) {
16913 case token: Asset =>
17721 }
17822
17923
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")
250-
251-
25224 @Callable(i)
253-func addSell (price) = {
254- let nftId = value(i.payments[0].assetId)
255- valueOrElse(isCorrectNft(nftId), if (!(isCorrectSellPrice(price)))
256- then throw("Price must be > 0")
257- else [setSell(nftId, i.caller, price)])
25+func createNft (nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = {
26+ let newToken = Issue(nft_name, nft_description, 1, 0, false)
27+ let issueId = calculateAssetId(newToken)
28+[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)]
25829 }
25930
26031
26132
26233 @Callable(i)
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)])
34+func issueNft (name,meta) = {
35+ let newToken = Issue(name, meta, 1, 0, false)
36+ let issueId = calculateAssetId(newToken)
37+[newToken, ScriptTransfer(i.caller, 1, issueId), StringEntry(((toBase58String(issueId) + separator) + "Owner"), toString(i.caller))]
27038 }
27139
27240
27341
27442 @Callable(i)
275-func buyFromSlot (nftId) = {
276- let $t067816870 = $Tuple2(i.payments[0].assetId, value(i.payments[0].amount))
277- let paymentAsset = $t067816870._1
278- let paymentAmount = $t067816870._2
279- let assetId = fromBase58String(nftId)
280- let $t069146952 = getSlot(assetId)
281- let type = $t069146952._1
282- let details = $t069146952._2
283- let baseRes = [ScriptTransfer(i.caller, 1, assetId), DeleteEntry(getSlotKey(type, assetId))]
284- if ((type == kSell))
285- then {
286- let $t070947141 = parseAsSell(details)
287- let seller = $t070947141._1
288- let priceValue = $t070947141._2
289- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, priceValue), {
290- let $t072267328 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, priceValue)
291- let sellerAmount = $t072267328._1
292- let buyerAmount = $t072267328._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 $t075457614 = calcPriceAtCurrentMoment(assetId, height)
301- let seller = $t075457614._1
302- let actualPrice = $t075457614._2
303- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, actualPrice), {
304- let $t077007803 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, actualPrice)
305- let sellerAmount = $t077007803._1
306- let buyerAmount = $t077007803._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- }
43+func buyNFT (nftID) = {
44+ let assetId = fromBase58String(nftID)
45+ let amount = value(i.payments[0].amount)
46+ let price = valueOrErrorMessage(getString(((kPrice + separator) + nftID)), "There is no price for this NFT")
47+ let owner = valueOrErrorMessage(getStringValue(((nftID + separator) + "Owner")), "No owner")
48+ if ((i.payments[0].assetId != unit))
49+ then throw("Pay in waves")
50+ else if ((parseIntValue(price) > amount))
51+ then throw("Invalid payment")
52+ else [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(value(addressFromString(owner)), parseIntValue(price), unit), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))]
31353 }
31454
31555
31656
31757 @Callable(i)
318-func declineSlot (nftId) = {
319- let assetId = fromBase58String(nftId)
320- let $t081048142 = getSlot(assetId)
321- let type = $t081048142._1
322- let details = $t081048142._2
323- let baseRes = [DeleteEntry(getSlotKey(type, assetId))]
324- if ((type == kSell))
325- then {
326- let $t082348281 = parseAsSell(details)
327- let seller = $t082348281._1
328- let priceValue = $t082348281._2
329- if (!(isValidCaller(i.caller, seller)))
330- then throw("Invalid caller")
331- else (baseRes ++ [ScriptTransfer(seller, 1, assetId)])
332- }
333- else {
334- let $t084268530 = parseAsAuction(details)
335- let seller = $t084268530._1
336- let startPriceValue = $t084268530._2
337- let endPriceValue = $t084268530._3
338- let startPeriodValue = $t084268530._4
339- let endPeriodValue = $t084268530._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- }
346- }
347-
348-
349-
350-@Callable(i)
351-func setTrustedIssuer (trustedAddr) = if (!(isAdmin(i.caller)))
352- then throw("Only admin")
353- else [BooleanEntry(getTrustedKey(addressFromStringValue(trustedAddr)), true)]
354-
355-
356-
357-@Callable(i)
358-func getPriceAtCurrentMoment (nftId,moment) = {
359- let assetId = fromBase58String(nftId)
360- let $t090719134 = calcPriceAtCurrentMoment(assetId, moment)
361- let seller = $t090719134._1
362- let price = $t090719134._2
363-[IntegerEntry(getPriceKey(assetId), price)]
58+func sellNFT (price) = {
59+ let $t023692454 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount))
60+ let token0 = $t023692454._1
61+ let amount0 = $t023692454._2
62+ if (!(isNft(token0)))
63+ then throw("Token is not NFT")
64+ else [StringEntry(((kPrice + separator) + toBase58String(value(i.payments[0].assetId))), toString(price)), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))]
36465 }
36566
36667
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let separator = "_"
55
6-let kAuction = "auction"
6+let kBuy = "buy"
77
88 let kSell = "sell"
99
10-let kTrusted = "trusted"
11-
1210 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")
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-
16711
16812 func isNft (assetId) = match assetInfo(assetId) {
16913 case token: Asset =>
17014 if (if ((token.decimals == 0))
17115 then (token.quantity == 1)
17216 else false)
17317 then (token.reissuable == false)
17418 else false
17519 case _ =>
17620 false
17721 }
17822
17923
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")
250-
251-
25224 @Callable(i)
253-func addSell (price) = {
254- let nftId = value(i.payments[0].assetId)
255- valueOrElse(isCorrectNft(nftId), if (!(isCorrectSellPrice(price)))
256- then throw("Price must be > 0")
257- else [setSell(nftId, i.caller, price)])
25+func createNft (nft_name,nft_owner,nft_dAppAddress,nft_type,nft_tags,nft_selling_price,nft_description,nft_onSell,nft_data) = {
26+ let newToken = Issue(nft_name, nft_description, 1, 0, false)
27+ let issueId = calculateAssetId(newToken)
28+[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)]
25829 }
25930
26031
26132
26233 @Callable(i)
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)])
34+func issueNft (name,meta) = {
35+ let newToken = Issue(name, meta, 1, 0, false)
36+ let issueId = calculateAssetId(newToken)
37+[newToken, ScriptTransfer(i.caller, 1, issueId), StringEntry(((toBase58String(issueId) + separator) + "Owner"), toString(i.caller))]
27038 }
27139
27240
27341
27442 @Callable(i)
275-func buyFromSlot (nftId) = {
276- let $t067816870 = $Tuple2(i.payments[0].assetId, value(i.payments[0].amount))
277- let paymentAsset = $t067816870._1
278- let paymentAmount = $t067816870._2
279- let assetId = fromBase58String(nftId)
280- let $t069146952 = getSlot(assetId)
281- let type = $t069146952._1
282- let details = $t069146952._2
283- let baseRes = [ScriptTransfer(i.caller, 1, assetId), DeleteEntry(getSlotKey(type, assetId))]
284- if ((type == kSell))
285- then {
286- let $t070947141 = parseAsSell(details)
287- let seller = $t070947141._1
288- let priceValue = $t070947141._2
289- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, priceValue), {
290- let $t072267328 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, priceValue)
291- let sellerAmount = $t072267328._1
292- let buyerAmount = $t072267328._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 $t075457614 = calcPriceAtCurrentMoment(assetId, height)
301- let seller = $t075457614._1
302- let actualPrice = $t075457614._2
303- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, actualPrice), {
304- let $t077007803 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, actualPrice)
305- let sellerAmount = $t077007803._1
306- let buyerAmount = $t077007803._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- }
43+func buyNFT (nftID) = {
44+ let assetId = fromBase58String(nftID)
45+ let amount = value(i.payments[0].amount)
46+ let price = valueOrErrorMessage(getString(((kPrice + separator) + nftID)), "There is no price for this NFT")
47+ let owner = valueOrErrorMessage(getStringValue(((nftID + separator) + "Owner")), "No owner")
48+ if ((i.payments[0].assetId != unit))
49+ then throw("Pay in waves")
50+ else if ((parseIntValue(price) > amount))
51+ then throw("Invalid payment")
52+ else [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(value(addressFromString(owner)), parseIntValue(price), unit), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))]
31353 }
31454
31555
31656
31757 @Callable(i)
318-func declineSlot (nftId) = {
319- let assetId = fromBase58String(nftId)
320- let $t081048142 = getSlot(assetId)
321- let type = $t081048142._1
322- let details = $t081048142._2
323- let baseRes = [DeleteEntry(getSlotKey(type, assetId))]
324- if ((type == kSell))
325- then {
326- let $t082348281 = parseAsSell(details)
327- let seller = $t082348281._1
328- let priceValue = $t082348281._2
329- if (!(isValidCaller(i.caller, seller)))
330- then throw("Invalid caller")
331- else (baseRes ++ [ScriptTransfer(seller, 1, assetId)])
332- }
333- else {
334- let $t084268530 = parseAsAuction(details)
335- let seller = $t084268530._1
336- let startPriceValue = $t084268530._2
337- let endPriceValue = $t084268530._3
338- let startPeriodValue = $t084268530._4
339- let endPeriodValue = $t084268530._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- }
346- }
347-
348-
349-
350-@Callable(i)
351-func setTrustedIssuer (trustedAddr) = if (!(isAdmin(i.caller)))
352- then throw("Only admin")
353- else [BooleanEntry(getTrustedKey(addressFromStringValue(trustedAddr)), true)]
354-
355-
356-
357-@Callable(i)
358-func getPriceAtCurrentMoment (nftId,moment) = {
359- let assetId = fromBase58String(nftId)
360- let $t090719134 = calcPriceAtCurrentMoment(assetId, moment)
361- let seller = $t090719134._1
362- let price = $t090719134._2
363-[IntegerEntry(getPriceKey(assetId), price)]
58+func sellNFT (price) = {
59+ let $t023692454 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount))
60+ let token0 = $t023692454._1
61+ let amount0 = $t023692454._2
62+ if (!(isNft(token0)))
63+ then throw("Token is not NFT")
64+ else [StringEntry(((kPrice + separator) + toBase58String(value(i.payments[0].assetId))), toString(price)), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))]
36465 }
36566
36667

github/deemru/w8io/169f3d6 
46.34 ms