tx · 9wuEB5QZmcXQ8SjdzgfbM9CzXd9dhyYq1TAbJodqZ3TR

3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H:  -0.01000000 Waves

2022.11.08 14:16 [2308094] smart account 3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H > SELF 0.00000000 Waves

{ "type": 13, "id": "9wuEB5QZmcXQ8SjdzgfbM9CzXd9dhyYq1TAbJodqZ3TR", "fee": 1000000, "feeAssetId": null, "timestamp": 1667906210685, "version": 2, "chainId": 84, "sender": "3N4boZRUJ2LxY5jLyp6hmxGktqnawQidu6H", "senderPublicKey": "BDeCphaaC4MZvfmbJqQZ78EvuEBZTJ1VEW7fbxue8BUu", "proofs": [ "3FNkFJCywAbHG2hLrzAWSXobCBCq1ZbD1mnMsP6M6ABELeXSReQKmhRVjFSV966qc5VM4iXfLiRbQy9bVi3gJUam" ], "script": "base64:BgIQCAISBQoDCAgBEgMKAQgSAAUACXNlcGFyYXRvcgIBXwAEa0J1eQIDYnV5AAVrU2VsbAIEc2VsbAAGa1ByaWNlAgVwcmljZQEFaXNOZnQBB2Fzc2V0SWQEByRtYXRjaDAJAOwHAQUHYXNzZXRJZAMJAAECBQckbWF0Y2gwAgVBc3NldAQFdG9rZW4FByRtYXRjaDADAwkAAAIIBQV0b2tlbghkZWNpbWFscwAACQAAAggFBXRva2VuCHF1YW50aXR5AAEHCQAAAggFBXRva2VuCnJlaXNzdWFibGUHBwcDAWkBCGlzc3VlTmZ0AwRuYW1lBG1ldGEFcHJpY2UECG5ld1Rva2VuCQDCCAUFBG5hbWUFBG1ldGEAAQAABwQHaXNzdWVJZAkAuAgBBQhuZXdUb2tlbgkAzAgCBQhuZXdUb2tlbgkAzAgCCQELU3RyaW5nRW50cnkCCQCsAgIJAKwCAgUGa1ByaWNlBQlzZXBhcmF0b3IJANgEAQUHaXNzdWVJZAkApAMBBQVwcmljZQUDbmlsAWkBBmJ1eU5GVAEFbmZ0SUQEB2Fzc2V0SWQJANkEAQUFbmZ0SUQEBmFtb3VudAkBBXZhbHVlAQgJAJEDAggFAWkIcGF5bWVudHMAAAZhbW91bnQEBXByaWNlCQETdmFsdWVPckVycm9yTWVzc2FnZQIJAKIIAQkArAICCQCsAgIFBmtQcmljZQUJc2VwYXJhdG9yBQVuZnRJRAIeVGhlcmUgaXMgbm8gcHJpY2UgZm9yIHRoaXMgTkZUAwkBAiE9AggJAJEDAggFAWkIcGF5bWVudHMAAAdhc3NldElkBQR1bml0CQACAQIMUGF5IGluIHdhdmVzAwkAZgIJAQ1wYXJzZUludFZhbHVlAQUFcHJpY2UFBmFtb3VudAkAAgECD0ludmFsaWQgcGF5bWVudAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIAAQUHYXNzZXRJZAkAzAgCCQELU3RyaW5nRW50cnkCCQCsAgIJAKwCAgkApQgBCAUBaQZjYWxsZXIFCXNlcGFyYXRvcgUEa0J1eQkArAICCQCsAgIFBW5mdElEBQlzZXBhcmF0b3IJAKQDAQUGYW1vdW50BQNuaWwBaQEHc2VsbE5GVAAECyR0MDExNzkxMjY0CQCUCgIJAQV2YWx1ZQEICQCRAwIIBQFpCHBheW1lbnRzAAAHYXNzZXRJZAkBBXZhbHVlAQgJAJEDAggFAWkIcGF5bWVudHMAAAZhbW91bnQEBnRva2VuMAgFCyR0MDExNzkxMjY0Al8xBAdhbW91bnQwCAULJHQwMTE3OTEyNjQCXzIEBXByaWNlCQERQGV4dHJOYXRpdmUoMTA1OCkBCQCsAgIJAKwCAgUGa1ByaWNlBQlzZXBhcmF0b3IJARN2YWx1ZU9yRXJyb3JNZXNzYWdlAgkA2AQBBQZ0b2tlbjACHlRoZXJlIGlzIG5vIHByaWNlIGZvciB0aGlzIE5GVAMJAQEhAQkBBWlzTmZ0AQUGdG9rZW4wCQACAQIQVG9rZW4gaXMgbm90IE5GVAkAzAgCCQEOU2NyaXB0VHJhbnNmZXIDCAUBaQZjYWxsZXIJAQ1wYXJzZUludFZhbHVlAQUFcHJpY2UFBHVuaXQJAMwIAgkBC1N0cmluZ0VudHJ5AgkArAICCQCsAgIJAKUIAQgFAWkGY2FsbGVyBQlzZXBhcmF0b3IFBWtTZWxsCQCsAgIJAKwCAgkA2AQBBQZ0b2tlbjAFCXNlcGFyYXRvcgkApAMBBQdhbW91bnQwBQNuaWwAkvj1WQ==", "height": 2308094, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: DyCbjGcAJwMHyz1FMLjUHGm493mA17Rw6QWrtYYNKF33 Next: BEZat7kRqHYX2wbpznW5M8nPUswcc3JpodCd35stevgG 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 issueNft (name,meta,price) = {
26+ let newToken = Issue(name, meta, 1, 0, false)
27+ let issueId = calculateAssetId(newToken)
28+[newToken, StringEntry(((kPrice + separator) + toBase58String(issueId)), toString(price))]
25829 }
25930
26031
26132
26233 @Callable(i)
263-func addAuction (startPrice,endPrice,start,end) = {
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)])
34+func buyNFT (nftID) = {
35+ let assetId = fromBase58String(nftID)
36+ let amount = value(i.payments[0].amount)
37+ let price = valueOrErrorMessage(getString(((kPrice + separator) + nftID)), "There is no price for this NFT")
38+ if ((i.payments[0].assetId != unit))
39+ then throw("Pay in waves")
40+ else if ((parseIntValue(price) > amount))
41+ then throw("Invalid payment")
42+ else [ScriptTransfer(i.caller, 1, assetId), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))]
27043 }
27144
27245
27346
27447 @Callable(i)
275-func buyFromSlot (nftId) = {
276- let $t060146103 = $Tuple2(i.payments[0].assetId, value(i.payments[0].amount))
277- let paymentAsset = $t060146103._1
278- let paymentAmount = $t060146103._2
279- let assetId = fromBase58String(nftId)
280- let $t061476185 = getSlot(assetId)
281- let type = $t061476185._1
282- let details = $t061476185._2
283- let baseRes = [ScriptTransfer(i.caller, 1, assetId), DeleteEntry(getSlotKey(type, assetId))]
284- if ((type == kSell))
285- then {
286- let $t063276374 = parseAsSell(details)
287- let seller = $t063276374._1
288- let priceValue = $t063276374._2
289- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, priceValue), {
290- let $t064596561 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, priceValue)
291- let sellerAmount = $t064596561._1
292- let buyerAmount = $t064596561._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 $t067786847 = calcPriceAtCurrentMoment(assetId, height)
301- let seller = $t067786847._1
302- let actualPrice = $t067786847._2
303- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, actualPrice), {
304- let $t069337036 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, actualPrice)
305- let sellerAmount = $t069337036._1
306- let buyerAmount = $t069337036._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- }
313- }
314-
315-
316-
317-@Callable(i)
318-func declineSlot (nftId) = {
319- let assetId = fromBase58String(nftId)
320- let $t073377375 = getSlot(assetId)
321- let type = $t073377375._1
322- let details = $t073377375._2
323- let baseRes = [DeleteEntry(getSlotKey(type, assetId))]
324- if ((type == kSell))
325- then {
326- let $t074677514 = parseAsSell(details)
327- let seller = $t074677514._1
328- let priceValue = $t074677514._2
329- if (!(isValidCaller(i.caller, seller)))
330- then throw("Invalid caller")
331- else (baseRes ++ [ScriptTransfer(seller, 1, assetId)])
332- }
333- else {
334- let $t076597763 = parseAsAuction(details)
335- let seller = $t076597763._1
336- let startPriceValue = $t076597763._2
337- let endPriceValue = $t076597763._3
338- let startPeriodValue = $t076597763._4
339- let endPeriodValue = $t076597763._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 $t083048367 = calcPriceAtCurrentMoment(assetId, moment)
361- let seller = $t083048367._1
362- let price = $t083048367._2
363-[IntegerEntry(getPriceKey(assetId), price)]
48+func sellNFT () = {
49+ let $t011791264 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount))
50+ let token0 = $t011791264._1
51+ let amount0 = $t011791264._2
52+ let price = getStringValue(((kPrice + separator) + valueOrErrorMessage(toBase58String(token0), "There is no price for this NFT")))
53+ if (!(isNft(token0)))
54+ then throw("Token is not NFT")
55+ else [ScriptTransfer(i.caller, parseIntValue(price), unit), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))]
36456 }
36557
36658
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 issueNft (name,meta,price) = {
26+ let newToken = Issue(name, meta, 1, 0, false)
27+ let issueId = calculateAssetId(newToken)
28+[newToken, StringEntry(((kPrice + separator) + toBase58String(issueId)), toString(price))]
25829 }
25930
26031
26132
26233 @Callable(i)
263-func addAuction (startPrice,endPrice,start,end) = {
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)])
34+func buyNFT (nftID) = {
35+ let assetId = fromBase58String(nftID)
36+ let amount = value(i.payments[0].amount)
37+ let price = valueOrErrorMessage(getString(((kPrice + separator) + nftID)), "There is no price for this NFT")
38+ if ((i.payments[0].assetId != unit))
39+ then throw("Pay in waves")
40+ else if ((parseIntValue(price) > amount))
41+ then throw("Invalid payment")
42+ else [ScriptTransfer(i.caller, 1, assetId), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount)))]
27043 }
27144
27245
27346
27447 @Callable(i)
275-func buyFromSlot (nftId) = {
276- let $t060146103 = $Tuple2(i.payments[0].assetId, value(i.payments[0].amount))
277- let paymentAsset = $t060146103._1
278- let paymentAmount = $t060146103._2
279- let assetId = fromBase58String(nftId)
280- let $t061476185 = getSlot(assetId)
281- let type = $t061476185._1
282- let details = $t061476185._2
283- let baseRes = [ScriptTransfer(i.caller, 1, assetId), DeleteEntry(getSlotKey(type, assetId))]
284- if ((type == kSell))
285- then {
286- let $t063276374 = parseAsSell(details)
287- let seller = $t063276374._1
288- let priceValue = $t063276374._2
289- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, priceValue), {
290- let $t064596561 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, priceValue)
291- let sellerAmount = $t064596561._1
292- let buyerAmount = $t064596561._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 $t067786847 = calcPriceAtCurrentMoment(assetId, height)
301- let seller = $t067786847._1
302- let actualPrice = $t067786847._2
303- valueOrElse(isCorrectPayments(paymentAsset, paymentAmount, actualPrice), {
304- let $t069337036 = resultFundsAmounts(isTrustedNft(assetId), paymentAmount, actualPrice)
305- let sellerAmount = $t069337036._1
306- let buyerAmount = $t069337036._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- }
313- }
314-
315-
316-
317-@Callable(i)
318-func declineSlot (nftId) = {
319- let assetId = fromBase58String(nftId)
320- let $t073377375 = getSlot(assetId)
321- let type = $t073377375._1
322- let details = $t073377375._2
323- let baseRes = [DeleteEntry(getSlotKey(type, assetId))]
324- if ((type == kSell))
325- then {
326- let $t074677514 = parseAsSell(details)
327- let seller = $t074677514._1
328- let priceValue = $t074677514._2
329- if (!(isValidCaller(i.caller, seller)))
330- then throw("Invalid caller")
331- else (baseRes ++ [ScriptTransfer(seller, 1, assetId)])
332- }
333- else {
334- let $t076597763 = parseAsAuction(details)
335- let seller = $t076597763._1
336- let startPriceValue = $t076597763._2
337- let endPriceValue = $t076597763._3
338- let startPeriodValue = $t076597763._4
339- let endPeriodValue = $t076597763._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 $t083048367 = calcPriceAtCurrentMoment(assetId, moment)
361- let seller = $t083048367._1
362- let price = $t083048367._2
363-[IntegerEntry(getPriceKey(assetId), price)]
48+func sellNFT () = {
49+ let $t011791264 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount))
50+ let token0 = $t011791264._1
51+ let amount0 = $t011791264._2
52+ let price = getStringValue(((kPrice + separator) + valueOrErrorMessage(toBase58String(token0), "There is no price for this NFT")))
53+ if (!(isNft(token0)))
54+ then throw("Token is not NFT")
55+ else [ScriptTransfer(i.caller, parseIntValue(price), unit), StringEntry(((toString(i.caller) + separator) + kSell), ((toBase58String(token0) + separator) + toString(amount0)))]
36456 }
36557
36658

github/deemru/w8io/026f985 
56.19 ms