39 | | - | func addAuction (start,end,startPrice,duration,payment_currency) = { |
---|
40 | | - | let txId = toBase58String(i.transactionId) |
---|
41 | | - | let nftId = value(i.payments[0].assetId) |
---|
42 | | - | let price = value(startPrice) |
---|
43 | | - | let endHeight = (lastBlock.height + duration) |
---|
44 | | - | let caller = i.caller.bytes |
---|
45 | | - | let checkNftAuctioned = match getString(this, (((toBase58String(nftId) + separator) + "nft_status_") + toBase58String(caller))) { |
---|
46 | | - | case a: String => |
---|
47 | | - | true |
---|
48 | | - | case _ => |
---|
49 | | - | false |
---|
50 | | - | } |
---|
51 | | - | if ((checkNftAuctioned == true)) |
---|
52 | | - | then throw("Already in auction list") |
---|
53 | | - | else if ((duration > maxAuctionDuration)) |
---|
54 | | - | then throw(("Duration is too long. Must be less than or equal to 30 " + toString(maxAuctionDuration))) |
---|
55 | | - | else if ((i.payments[0].assetId == unit)) |
---|
56 | | - | then throw("NFT not attached") |
---|
57 | | - | else if ((i.payments[0].assetId == teams)) |
---|
58 | | - | then throw("NFT not attached") |
---|
59 | | - | else [StringEntry(((txId + "nft_start_auction_date") + toBase58String(caller)), start), StringEntry(((txId + "nft_end_auction_date") + toBase58String(caller)), end), StringEntry((txId + "_nft_start_price"), startPrice), StringEntry((txId + "_nft_owner"), toString(i.caller)), StringEntry((txId + "_nft_on_auction"), toBase58String(nftId)), StringEntry((txId + "_previous_bidder"), "none"), StringEntry((txId + "_highest_bid"), "0"), StringEntry((txId + "_winner_of_nft"), "0"), StringEntry((txId + "_bidder_count"), "0"), StringEntry((txId + "_nft_status"), "OPEN")] |
---|
| 7 | + | func token () = { |
---|
| 8 | + | let asset = Issue("shub", "This is an ordinary token", 10000000, 2, true) |
---|
| 9 | + | let assetId = calculateAssetId(asset) |
---|
| 10 | + | let Alice = Address(base58'3NCspLgbmcyQ76ZL6Jw4gFZLmbhwdKKXUQs') |
---|
| 11 | + | [asset, ScriptTransfer(Alice, 1000, assetId)] |
---|
63 | | - | |
---|
64 | | - | @Callable(i) |
---|
65 | | - | func placeBid (auctionId,nftId,nft_owner,bid_price,current_currency) = { |
---|
66 | | - | let txId = toBase58String(i.transactionId) |
---|
67 | | - | let caller = i.caller.bytes |
---|
68 | | - | let assetId = fromBase58String(nftId) |
---|
69 | | - | let tokenType = i.payments[0].assetId |
---|
70 | | - | let currentBidPrice = i.payments[0].amount |
---|
71 | | - | let getLastWinnerBidPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
72 | | - | let getPreviousBidderAddress = getString(this, (auctionId + "_previous_bidder")) |
---|
73 | | - | let currentBidCount = getStringValue(this, (auctionId + "_bidder_count")) |
---|
74 | | - | let getLastWinnerAddress = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
75 | | - | let checkNftAuctioned = getStringValue(this, (auctionId + "_nft_status")) |
---|
76 | | - | if ((checkNftAuctioned != "OPEN")) |
---|
77 | | - | then throw("Not open for auction") |
---|
78 | | - | else if ((parseIntValue(getLastWinnerBidPrice) >= currentBidPrice)) |
---|
79 | | - | then throw("Bid is less then starting/highest Bid") |
---|
80 | | - | else if ((getLastWinnerBidPrice == "0")) |
---|
81 | | - | then [StringEntry((auctionId + "_highest_bid"), toString(currentBidPrice)), StringEntry((auctionId + "_winner_of_nft"), toBase58String(i.caller.bytes)), StringEntry((auctionId + "_bidder_count"), toString((parseIntValue(currentBidCount) + 1))), StringEntry((auctionId + "_nft_id"), toBase58String(assetId)), StringEntry((auctionId + "_nft_owner"), nft_owner), StringEntry((((txId + "_") + auctionId) + "_highest_bid"), toString(currentBidPrice)), StringEntry((((txId + "_") + auctionId) + "_winner"), toBase58String(i.caller.bytes)), StringEntry((((txId + "_") + auctionId) + "_bidder_count"), toString((parseIntValue(currentBidCount) + 1))), StringEntry((((txId + "_") + auctionId) + "_nft_id"), toBase58String(assetId)), StringEntry((((txId + "_") + auctionId) + "_nft_owner"), nft_owner), StringEntry((txId + "_bid_for_nft_by"), toBase58String(caller)), StringEntry((txId + "_bid_price_place"), bid_price), StringEntry((txId + "_previous_bid_amount_refund_to_address"), getLastWinnerAddress), StringEntry((txId + "_prevoius_bid_amount_refund"), getLastWinnerBidPrice)] |
---|
82 | | - | else if ((getLastWinnerBidPrice != "0")) |
---|
83 | | - | then [ScriptTransfer(Address(fromBase58String(getLastWinnerAddress)), parseIntValue(getLastWinnerBidPrice), tokenType), StringEntry((txId + "_previous_bid_amount_refund_to_address"), getLastWinnerAddress), StringEntry((txId + "_prevoius_bid_amount_refund"), getLastWinnerBidPrice), StringEntry((auctionId + "_bidder_count"), toString((parseIntValue(currentBidCount) + 1))), StringEntry((auctionId + "_highest_bid"), toString(currentBidPrice)), StringEntry((auctionId + "_winner_of_nft"), toBase58String(i.caller.bytes)), StringEntry((auctionId + "_nft_id"), toBase58String(assetId)), StringEntry((auctionId + "_nft_owner"), nft_owner), StringEntry((((txId + "_") + auctionId) + "_highest_bid"), toString(currentBidPrice)), StringEntry((((txId + "_") + auctionId) + "_winner"), toBase58String(i.caller.bytes)), StringEntry((((txId + "_") + auctionId) + "_bidder_count"), toString((parseIntValue(currentBidCount) + 1))), StringEntry((((txId + "_") + auctionId) + "_nft_id"), toBase58String(assetId)), StringEntry((((txId + "_") + auctionId) + "_nft_owner"), nft_owner), StringEntry((txId + "_bid_for_nft_by"), toBase58String(caller)), StringEntry((txId + "_bid_price_place"), bid_price)] |
---|
84 | | - | else nil |
---|
85 | | - | } |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | @Callable(i) |
---|
90 | | - | func acceptBidOffer (auctionId,nftId,bid_amount_from_user,current_currency) = { |
---|
91 | | - | let asimiString = "9yhJDfWjPpv6tFjWRD1AJyBQwausJf2ZdxzLn86Uknnq" |
---|
92 | | - | let txId = toBase58String(i.transactionId) |
---|
93 | | - | let amountUnit = fromBase58String(current_currency) |
---|
94 | | - | let caller = i.caller.bytes |
---|
95 | | - | let assetId = fromBase58String(nftId) |
---|
96 | | - | let getNftWinningPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
97 | | - | let getNftWinningamount = ((parseIntValue(getNftWinningPrice) / 1000) * 975) |
---|
98 | | - | let platform_fee = ((parseIntValue(getNftWinningPrice) / 1000) * 25) |
---|
99 | | - | let getAuctionWinner = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
100 | | - | if ((current_currency == asimiString)) |
---|
101 | | - | then [ScriptTransfer(Address(caller), getNftWinningamount, amountUnit), ScriptTransfer(Address(fromBase58String(getAuctionWinner)), 1, assetId), StringEntry((txId + "_amount_paid_to_owner"), getNftWinningPrice), StringEntry((txId + "_nft_transfer_to"), getAuctionWinner), StringEntry((txId + "_nft_status"), "REWARDED"), StringEntry((auctionId + "_amount_paid_to_owner"), getNftWinningPrice), StringEntry((auctionId + "_nft_transfer_to"), getAuctionWinner), StringEntry((auctionId + "_nft_status"), "REWARDED")] |
---|
102 | | - | else if ((current_currency == "WAVES")) |
---|
103 | | - | then [ScriptTransfer(Address(caller), getNftWinningamount, unit), ScriptTransfer(Address(fromBase58String(getAuctionWinner)), 1, assetId), StringEntry((txId + "_amount_paid_to_owner"), getNftWinningPrice), StringEntry((txId + "_nft_transfer_to"), getAuctionWinner), StringEntry((txId + "_nft_status"), "REWARDED"), StringEntry((auctionId + "_amount_paid_to_owner"), getNftWinningPrice), StringEntry((auctionId + "_nft_transfer_to"), getAuctionWinner), StringEntry((auctionId + "_nft_status"), "REWARDED")] |
---|
104 | | - | else nil |
---|
105 | | - | } |
---|
106 | | - | |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | @Callable(i) |
---|
110 | | - | func cancelAuction (auctionId) = { |
---|
111 | | - | let txId = toBase58String(i.transactionId) |
---|
112 | | - | let caller = i.caller.bytes |
---|
113 | | - | let auctionStatus = getStringValue(this, (auctionId + "_nft_status")) |
---|
114 | | - | let biddingWinner = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
115 | | - | let nftOwner = getStringValue(this, (auctionId + "_nft_owner")) |
---|
116 | | - | let nftId = getStringValue(this, (auctionId + "_nft_on_auction")) |
---|
117 | | - | let biddingPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
118 | | - | if ((biddingWinner == "0")) |
---|
119 | | - | then [StringEntry(((txId + auctionId) + "_nft_status"), "CANCELED"), ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId))] |
---|
120 | | - | else if ((biddingWinner != "0")) |
---|
121 | | - | then throw("soory you can't cancel it because already auction placed by someone") |
---|
122 | | - | else nil |
---|
123 | | - | } |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | |
---|
127 | | - | @Callable(i) |
---|
128 | | - | func nftback (auctionId) = { |
---|
129 | | - | let caller = i.caller.bytes |
---|
130 | | - | let nftId = getStringValue(this, (auctionId + "_nft_on_auction")) |
---|
131 | | - | let nftOwner = getStringValue(this, (auctionId + "_nft_owner")) |
---|
132 | | - | [StringEntry((auctionId + "_nft_status"), "Auction_time over"), ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId))] |
---|
133 | | - | } |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | |
---|
137 | | - | @Callable(i) |
---|
138 | | - | func withdrawMoney (auctionId,current_currency) = { |
---|
139 | | - | let caller = i.caller.bytes |
---|
140 | | - | let asimiString = "9yhJDfWjPpv6tFjWRD1AJyBQwausJf2ZdxzLn86Uknnq" |
---|
141 | | - | let txId = toBase58String(i.transactionId) |
---|
142 | | - | let amountUnit = fromBase58String(current_currency) |
---|
143 | | - | let bidPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
144 | | - | let asBidder = getStringValue(this, (auctionId + "_winner")) |
---|
145 | | - | let bidForNFT = getStringValue(this, (auctionId + "_nft_id")) |
---|
146 | | - | if ((current_currency == asimiString)) |
---|
147 | | - | then [StringEntry((auctionId + "_nft_bid"), "WITHDRAW"), StringEntry((auctionId + "_nft_id"), bidForNFT), StringEntry((auctionId + "_bidding_price_refund_amount"), bidPrice), ScriptTransfer(i.caller, parseIntValue(bidPrice), amountUnit)] |
---|
148 | | - | else if ((current_currency == "WAVES")) |
---|
149 | | - | then [StringEntry((auctionId + "_nft_bid"), "WITHDRAW"), StringEntry((auctionId + "_nft_id"), bidForNFT), StringEntry((auctionId + "_bidding_price_refund_amount"), bidPrice), ScriptTransfer(i.caller, parseIntValue(bidPrice), unit)] |
---|
150 | | - | else nil |
---|
151 | | - | } |
---|
152 | | - | |
---|
153 | | - | |
---|
154 | | - | |
---|
155 | | - | @Callable(i) |
---|
156 | | - | func automateFunction (auctionId,current_currency) = { |
---|
157 | | - | let caller = i.caller.bytes |
---|
158 | | - | let nftId = getStringValue(this, (auctionId + "_nft_on_auction")) |
---|
159 | | - | let nftOwner = getStringValue(this, (auctionId + "_nft_owner")) |
---|
160 | | - | let asimiString = "9yhJDfWjPpv6tFjWRD1AJyBQwausJf2ZdxzLn86Uknnq" |
---|
161 | | - | let amountUnit = fromBase58String(current_currency) |
---|
162 | | - | let getLastWinnerBidPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
163 | | - | let getLastWinnerAddress = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
164 | | - | let biddingWinner = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
165 | | - | if ((biddingWinner == "0")) |
---|
166 | | - | then [ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId))] |
---|
167 | | - | else if (if ((biddingWinner != "0")) |
---|
168 | | - | then (current_currency == asimiString) |
---|
169 | | - | else false) |
---|
170 | | - | then [ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId)), ScriptTransfer(Address(fromBase58String(getLastWinnerAddress)), parseIntValue(getLastWinnerBidPrice), amountUnit)] |
---|
171 | | - | else if (if ((biddingWinner != "0")) |
---|
172 | | - | then (current_currency == "WAVES") |
---|
173 | | - | else false) |
---|
174 | | - | then [ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId)), ScriptTransfer(Address(fromBase58String(getLastWinnerAddress)), parseIntValue(getLastWinnerBidPrice), unit)] |
---|
175 | | - | else nil |
---|
176 | | - | } |
---|
177 | | - | |
---|
| 15 | + | @Verifier(tx) |
---|
| 16 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|