43 | | - | |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | @Callable(i) |
---|
47 | | - | func sellNFT (price,payment_currency) = { |
---|
48 | | - | let txId = i.transactionId |
---|
49 | | - | let seller = i.caller.bytes |
---|
50 | | - | let $t019011986 = $Tuple2(value(i.payments[0].assetId), value(i.payments[0].amount)) |
---|
51 | | - | let token0 = $t019011986._1 |
---|
52 | | - | let amount0 = $t019011986._2 |
---|
53 | | - | if (!(isNft(token0))) |
---|
54 | | - | then throw("Token is not NFT") |
---|
55 | | - | else [StringEntry(((kPrice + separator) + toBase58String(value(i.payments[0].assetId))), (price + payment_currency)), StringEntry(((toString(i.caller) + separator) + kSell), (((toBase58String(token0) + separator) + toString(amount0)) + payment_currency))] |
---|
56 | | - | } |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | @Callable(i) |
---|
61 | | - | func buyNFT (nftID,current_nft_owner) = { |
---|
62 | | - | let assetId = fromBase58String(nftID) |
---|
63 | | - | let amount = value(i.payments[0].amount) |
---|
64 | | - | let checkOwnerIsSame = match getString(this, (("nft_" + current_nft_owner) + "_owner")) { |
---|
65 | | - | case a: String => |
---|
66 | | - | a |
---|
67 | | - | case _ => |
---|
68 | | - | false |
---|
69 | | - | } |
---|
70 | | - | let price = getStringValue(((((kPrice + separator) + nftID) + "_") + current_nft_owner)) |
---|
71 | | - | if ((current_nft_owner == toString(i.caller))) |
---|
72 | | - | then throw("current Owner of NFT not able to purchase") |
---|
73 | | - | else if ((i.payments[0].assetId == teams)) |
---|
74 | | - | then [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(Address(fromBase58String(current_nft_owner)), amount, teams), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount))), DeleteEntry((("nft_" + current_nft_owner) + "_owner")), StringEntry((("nft_" + current_nft_owner) + "_owner"), toString(i.caller)), StringEntry(((nftID + separator) + "_owner"), toString(i.caller))] |
---|
75 | | - | else if ((i.payments[0].assetId == unit)) |
---|
76 | | - | then [ScriptTransfer(i.caller, 1, assetId), ScriptTransfer(Address(fromBase58String(current_nft_owner)), amount, unit), StringEntry(((toString(i.caller) + separator) + kBuy), ((nftID + separator) + toString(amount))), DeleteEntry((("nft_" + current_nft_owner) + "_owner")), StringEntry((("nft_" + current_nft_owner) + "_owner"), toString(i.caller)), StringEntry(((nftID + separator) + "_owner"), toString(i.caller))] |
---|
77 | | - | else nil |
---|
78 | | - | } |
---|
79 | | - | |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | @Callable(i) |
---|
83 | | - | func cancelSell (nftId) = { |
---|
84 | | - | let txId = toBase58String(i.transactionId) |
---|
85 | | - | let seller = i.caller.bytes |
---|
86 | | - | [StringEntry(((txId + nftId) + "_nft_status"), "CANCELED"), ScriptTransfer(Address(seller), 1, fromBase58String(nftId))] |
---|
87 | | - | } |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | |
---|
91 | | - | @Callable(i) |
---|
92 | | - | func addAuction (start,end,startPrice,duration,payment_currency) = { |
---|
93 | | - | let txId = toBase58String(i.transactionId) |
---|
94 | | - | let nftId = value(i.payments[0].assetId) |
---|
95 | | - | let price = value(startPrice) |
---|
96 | | - | let endHeight = (lastBlock.height + duration) |
---|
97 | | - | let caller = i.caller.bytes |
---|
98 | | - | let checkNftAuctioned = match getString(this, (((toBase58String(nftId) + separator) + "nft_status_") + toBase58String(caller))) { |
---|
99 | | - | case a: String => |
---|
100 | | - | true |
---|
101 | | - | case _ => |
---|
102 | | - | false |
---|
103 | | - | } |
---|
104 | | - | if ((checkNftAuctioned == true)) |
---|
105 | | - | then throw("Already in auction list") |
---|
106 | | - | else if ((duration > maxAuctionDuration)) |
---|
107 | | - | then throw(("Duration is too long. Must be less than or equal to 7 " + toString(maxAuctionDuration))) |
---|
108 | | - | else if ((i.payments[0].assetId == unit)) |
---|
109 | | - | then throw("NFT not attached") |
---|
110 | | - | else if ((i.payments[0].assetId == teams)) |
---|
111 | | - | then throw("NFT not attached") |
---|
112 | | - | 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 + payment_currency)), 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")] |
---|
113 | | - | } |
---|
114 | | - | |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | @Callable(i) |
---|
118 | | - | func placeBid (auctionId,nftId,nft_owner,startPrice,bid_price) = { |
---|
119 | | - | let txId = toBase58String(i.transactionId) |
---|
120 | | - | let caller = i.caller.bytes |
---|
121 | | - | let assetId = fromBase58String(nftId) |
---|
122 | | - | let currentBidPrice = i.payments[0].amount |
---|
123 | | - | let getLastWinnerBidPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
124 | | - | let getPreviousBidderAddress = getString(this, (auctionId + "_previous_bidder")) |
---|
125 | | - | let currentBidCount = getStringValue(this, (auctionId + "_bidder_count")) |
---|
126 | | - | let getLastWinnerAddress = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
127 | | - | let checkNftAuctioned = getStringValue(this, (auctionId + "_nft_status")) |
---|
128 | | - | if ((checkNftAuctioned != "OPEN")) |
---|
129 | | - | then throw("Not open for auction") |
---|
130 | | - | else if ((parseIntValue(getLastWinnerBidPrice) >= currentBidPrice)) |
---|
131 | | - | then throw("Bid is less then starting/highest Bid") |
---|
132 | | - | else if ((getLastWinnerBidPrice == "0")) |
---|
133 | | - | 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)] |
---|
134 | | - | else if ((i.payments[0].assetId == unit)) |
---|
135 | | - | 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), ScriptTransfer(Address(fromBase58String(getLastWinnerAddress)), parseIntValue(getLastWinnerBidPrice), unit)] |
---|
136 | | - | else if ((i.payments[0].assetId == teams)) |
---|
137 | | - | 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), ScriptTransfer(Address(fromBase58String(getLastWinnerAddress)), parseIntValue(getLastWinnerBidPrice), teams)] |
---|
138 | | - | else nil |
---|
139 | | - | } |
---|
140 | | - | |
---|
141 | | - | |
---|
142 | | - | |
---|
143 | | - | @Callable(i) |
---|
144 | | - | func acceptBidOffer (auctionId,nftId,bid_amount_from_user) = { |
---|
145 | | - | let txId = toBase58String(i.transactionId) |
---|
146 | | - | let caller = i.caller.bytes |
---|
147 | | - | let assetId = fromBase58String(nftId) |
---|
148 | | - | let getNftWinningPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
149 | | - | let getAuctionWinner = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
150 | | - | [ScriptTransfer(Address(caller), parseIntValue(getNftWinningPrice), teams), 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")] |
---|
151 | | - | } |
---|
152 | | - | |
---|
153 | | - | |
---|
154 | | - | |
---|
155 | | - | @Callable(i) |
---|
156 | | - | func cancelAuction (auctionId) = { |
---|
157 | | - | let txId = toBase58String(i.transactionId) |
---|
158 | | - | let caller = i.caller.bytes |
---|
159 | | - | let auctionStatus = getStringValue(this, (auctionId + "_nft_status")) |
---|
160 | | - | let biddingWinner = getStringValue(this, (auctionId + "_winner_of_nft")) |
---|
161 | | - | let nftOwner = getStringValue(this, (auctionId + "_nft_owner")) |
---|
162 | | - | let nftId = getStringValue(this, (auctionId + "_nft_on_auction")) |
---|
163 | | - | let biddingPrice = getStringValue(this, (auctionId + "_highest_bid")) |
---|
164 | | - | if ((biddingWinner == "0")) |
---|
165 | | - | then [StringEntry(((txId + auctionId) + "_nft_status"), "CANCELED"), ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId))] |
---|
166 | | - | else if ((i.payments[0].assetId == unit)) |
---|
167 | | - | then [StringEntry((auctionId + "_nft_status"), "CANCELED"), StringEntry((auctionId + "_previous_bid_amount_refund_to_address"), biddingWinner), StringEntry((auctionId + "_prevoius_bid_amount_refund"), biddingPrice), StringEntry((txId + "_nft_status"), "CANCELED"), StringEntry((txId + "_previous_bid_amount_refund_to_address"), biddingWinner), StringEntry((txId + "_prevoius_bid_amount_refund"), biddingPrice), ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId)), ScriptTransfer(Address(fromBase58String(biddingWinner)), parseIntValue(biddingPrice), unit)] |
---|
168 | | - | else if ((i.payments[0].assetId == teams)) |
---|
169 | | - | then [StringEntry((auctionId + "_nft_status"), "CANCELED"), StringEntry((auctionId + "_previous_bid_amount_refund_to_address"), biddingWinner), StringEntry((auctionId + "_prevoius_bid_amount_refund"), biddingPrice), StringEntry((txId + "_nft_status"), "CANCELED"), StringEntry((txId + "_previous_bid_amount_refund_to_address"), biddingWinner), StringEntry((txId + "_prevoius_bid_amount_refund"), biddingPrice), ScriptTransfer(Address(fromBase58String(nftOwner)), 1, fromBase58String(nftId)), ScriptTransfer(Address(fromBase58String(biddingWinner)), parseIntValue(biddingPrice), teams)] |
---|
170 | | - | else nil |
---|
171 | | - | } |
---|
172 | | - | |
---|
173 | | - | |
---|
174 | | - | |
---|
175 | | - | @Callable(i) |
---|
176 | | - | func withdrawBid (bidTxId) = { |
---|
177 | | - | let caller = i.caller.bytes |
---|
178 | | - | let bidPrice = getStringValue(this, (bidTxId + "_highest_bid")) |
---|
179 | | - | let asBidder = getStringValue(this, (bidTxId + "_winner")) |
---|
180 | | - | let bidForNFT = getStringValue(this, (bidTxId + "_nft_id")) |
---|
181 | | - | if ((toBase58String(caller) != asBidder)) |
---|
182 | | - | then throw("No bid") |
---|
183 | | - | else [StringEntry((bidTxId + "_nft_bid"), "WITHDRAW"), StringEntry((bidTxId + "_nft_id"), bidForNFT), StringEntry((bidTxId + "_bidding_price_refund_amount"), bidPrice), ScriptTransfer(i.caller, parseIntValue(bidPrice), unit)] |
---|
184 | | - | } |
---|
185 | | - | |
---|
186 | | - | |
---|
187 | | - | |
---|
188 | | - | @Callable(i) |
---|
189 | | - | func manualFundTransfer (recepientAddr,message) = { |
---|
190 | | - | let caller = i.caller.bytes |
---|
191 | | - | let reciver = fromBase58String(recepientAddr) |
---|
192 | | - | let amount = i.payments[0].amount |
---|
193 | | - | if ((i.payments[0].assetId == unit)) |
---|
194 | | - | then [IntegerEntry((toBase58String(caller) + "_transfer"), amount), StringEntry((toBase58String(caller) + "_transfer_to"), recepientAddr), ScriptTransfer(Address(reciver), amount, unit)] |
---|
195 | | - | else if ((i.payments[0].assetId == teams)) |
---|
196 | | - | then [IntegerEntry((toBase58String(caller) + "_transfer"), amount), StringEntry((toBase58String(caller) + "_transfer_to"), recepientAddr), ScriptTransfer(Address(reciver), amount, teams)] |
---|
197 | | - | else nil |
---|
198 | | - | } |
---|
199 | | - | |
---|
200 | | - | |
---|
201 | | - | |
---|
202 | | - | @Callable(i) |
---|
203 | | - | func testBid (data) = [StringEntry("E8kkFBYCy44JJaq6pAZ6KizsuResi5UKNhbD1WNZwhhY_highest_bid", "0")] |
---|