6 | | - | let b = "buy" |
---|
7 | | - | |
---|
8 | | - | let c = "price" |
---|
9 | | - | |
---|
10 | | - | let d = "sell" |
---|
11 | | - | |
---|
12 | | - | let e = "bid" |
---|
13 | | - | |
---|
14 | | - | let f = $Tuple4("OPEN", "CLOSED", "REWARDED", "CANCELED") |
---|
15 | | - | |
---|
16 | | - | let g = base58'3MvjAaDYHpS4A5K4CV3kZMMEH9m9JdBSvbq' |
---|
17 | | - | |
---|
18 | | - | func h (i) = { |
---|
19 | | - | let j = assetInfo(i) |
---|
20 | | - | if ($isInstanceOf(j, "Asset")) |
---|
21 | | - | then { |
---|
22 | | - | let k = j |
---|
23 | | - | if (if ((k.decimals == 0)) |
---|
24 | | - | then (k.quantity == 1) |
---|
25 | | - | else false) |
---|
26 | | - | then (k.reissuable == false) |
---|
27 | | - | else false |
---|
28 | | - | } |
---|
29 | | - | else false |
---|
30 | | - | } |
---|
31 | | - | |
---|
32 | | - | |
---|
33 | | - | @Callable(l) |
---|
34 | | - | func createNft (m,n,o,p,q,r,s,t,u) = { |
---|
35 | | - | let v = Issue(m, s, 1, 0, false) |
---|
36 | | - | let w = calculateAssetId(v) |
---|
37 | | - | let x = l.transactionId |
---|
38 | | - | [v, ScriptTransfer(l.caller, 1, w), StringEntry(((toBase58String(w) + a) + "Owner"), toString(l.caller)), StringEntry(((toBase58String(w) + a) + "nft_type"), p), StringEntry(((toBase58String(w) + a) + "nft_tags"), q), StringEntry(((toBase58String(w) + a) + "nft_dAppAddress"), o), IntegerEntry(((toBase58String(w) + a) + "nft_selling_price"), r), StringEntry(((toBase58String(w) + a) + "nft_onSell"), t), StringEntry(((toBase58String(w) + a) + "nft_data"), u), StringEntry(((toBase58String(x) + a) + "issue_nft"), toBase58String(w))] |
---|
39 | | - | } |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | |
---|
43 | | - | @Callable(l) |
---|
44 | | - | func sellNFT (y) = { |
---|
45 | | - | let x = l.transactionId |
---|
46 | | - | let z = l.caller.bytes |
---|
47 | | - | let A = $Tuple2(value(l.payments[0].assetId), value(l.payments[0].amount)) |
---|
48 | | - | let B = A._1 |
---|
49 | | - | let C = A._2 |
---|
50 | | - | if (!(h(B))) |
---|
51 | | - | then throw("Token is not NFT") |
---|
52 | | - | else [StringEntry(((c + a) + toBase58String(value(l.payments[0].assetId))), toString(y)), StringEntry(((toString(l.caller) + a) + d), ((toBase58String(B) + a) + toString(C)))] |
---|
53 | | - | } |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Callable(l) |
---|
58 | | - | func buyNFT (D,E) = { |
---|
59 | | - | let i = fromBase58String(D) |
---|
60 | | - | let F = value(l.payments[0].amount) |
---|
61 | | - | let G = { |
---|
62 | | - | let j = getString(this, (("nft_" + E) + "_owner")) |
---|
63 | | - | if ($isInstanceOf(j, "String")) |
---|
| 6 | + | @Callable(b) |
---|
| 7 | + | func addAuction (c,d,e,f) = { |
---|
| 8 | + | let g = toBase58String(b.transactionId) |
---|
| 9 | + | let h = value(b.payments[0].assetId) |
---|
| 10 | + | let i = value(e) |
---|
| 11 | + | let j = (lastBlock.height + f) |
---|
| 12 | + | let k = b.caller.bytes |
---|
| 13 | + | let l = { |
---|
| 14 | + | let m = getString(this, ((toBase58String(h) + "nft_status_") + toBase58String(k))) |
---|
| 15 | + | if ($isInstanceOf(m, "String")) |
---|
100 | | - | else [StringEntry(((x + "_nft_start_auction_date_") + toBase58String(O)), J), StringEntry(((x + "_nft_end_auction_date_") + toBase58String(O)), K), StringEntry((x + "_nft_start_price"), L), StringEntry((x + "duration_of_auction"), M), StringEntry((x + "_nft_owner"), toString(l.caller)), StringEntry((x + "_nft_on_auction"), toBase58String(N)), StringEntry((x + "_previous_bidder"), "none"), StringEntry((x + "_highest_bid"), "0"), StringEntry((x + "_winner_of_nft"), "0"), StringEntry((x + "_bidder_count"), "0"), StringEntry((x + "_nft_status"), "OPEN")] |
---|
| 26 | + | else if ((f > a)) |
---|
| 27 | + | then throw(("Duration is too long. Must be less than or equal to 7 " + toString(a))) |
---|
| 28 | + | else [StringEntry(((g + "_nft_start_auction_date_") + toBase58String(k)), c), StringEntry(((g + "_nft_end_auction_date_") + toBase58String(k)), d), StringEntry((g + "_nft_start_price"), e), StringEntry((g + "_nft_owner"), toString(b.caller)), StringEntry((g + "_nft_on_auction"), toBase58String(h)), StringEntry((g + "_previous_bidder"), "none"), StringEntry((g + "_highest_bid"), "0"), StringEntry((g + "_winner_of_nft"), "0"), StringEntry((g + "_bidder_count"), "0"), StringEntry((g + "_nft_status"), "OPEN")] |
---|
102 | | - | |
---|
103 | | - | |
---|
104 | | - | |
---|
105 | | - | @Callable(l) |
---|
106 | | - | func placeBid (Q,N,n,R) = { |
---|
107 | | - | let x = toBase58String(l.transactionId) |
---|
108 | | - | let O = l.caller.bytes |
---|
109 | | - | let i = fromBase58String(N) |
---|
110 | | - | let S = l.payments[0].amount |
---|
111 | | - | let T = getStringValue(this, (Q + "_highest_bid")) |
---|
112 | | - | let U = getString(this, (Q + "_previous_bidder")) |
---|
113 | | - | let V = getStringValue(this, (Q + "_bidder_count")) |
---|
114 | | - | let W = getStringValue(this, (Q + "_winner_of_nft")) |
---|
115 | | - | let P = getStringValue(this, (Q + "_nft_status")) |
---|
116 | | - | if ((l.payments[0].assetId != unit)) |
---|
117 | | - | then throw("Pay in waves") |
---|
118 | | - | else if ((P != "OPEN")) |
---|
119 | | - | then throw("Not open for auction") |
---|
120 | | - | else if ((parseIntValue(T) >= S)) |
---|
121 | | - | then throw("Bid is less then starting/highest Bid") |
---|
122 | | - | else if ((T == "0")) |
---|
123 | | - | then [StringEntry((Q + "_highest_bid"), toString(S)), StringEntry((Q + "_winner_of_nft"), toBase58String(l.caller.bytes)), StringEntry((Q + "_bidder_count"), toString((parseIntValue(V) + 1))), StringEntry((Q + "_nft_id"), toBase58String(i)), StringEntry((Q + "_nft_owner"), n), StringEntry((((x + "_") + Q) + "_highest_bid"), toString(S)), StringEntry((((x + "_") + Q) + "_winner"), toBase58String(l.caller.bytes)), StringEntry((((x + "_") + Q) + "_bidder_count"), toString((parseIntValue(V) + 1))), StringEntry((((x + "_") + Q) + "_nft_id"), toBase58String(i)), StringEntry((((x + "_") + Q) + "_nft_owner"), n), StringEntry((x + "_bid_for_nft_by"), toBase58String(O)), StringEntry((x + "_bid_price_place"), R), StringEntry((x + "_previous_bid_amount_refund_to_address"), W), StringEntry((x + "_prevoius_bid_amount_refund"), T)] |
---|
124 | | - | else [StringEntry((Q + "_highest_bid"), toString(S)), StringEntry((Q + "_winner_of_nft"), toBase58String(l.caller.bytes)), StringEntry((Q + "_bidder_count"), toString((parseIntValue(V) + 1))), StringEntry((Q + "_nft_id"), toBase58String(i)), StringEntry((Q + "_nft_owner"), n), StringEntry((((x + "_") + Q) + "_highest_bid"), toString(S)), StringEntry((((x + "_") + Q) + "_winner"), toBase58String(l.caller.bytes)), StringEntry((((x + "_") + Q) + "_bidder_count"), toString((parseIntValue(V) + 1))), StringEntry((((x + "_") + Q) + "_nft_id"), toBase58String(i)), StringEntry((((x + "_") + Q) + "_nft_owner"), n), StringEntry((x + "_bid_for_nft_by"), toBase58String(O)), StringEntry((x + "_bid_price_place"), R), StringEntry((x + "_previous_bid_amount_refund_to_address"), W), StringEntry((x + "_prevoius_bid_amount_refund"), T), ScriptTransfer(Address(fromBase58String(W)), parseIntValue(T), unit)] |
---|
125 | | - | } |
---|
126 | | - | |
---|
127 | | - | |
---|
128 | | - | |
---|
129 | | - | @Callable(l) |
---|
130 | | - | func acceptBidOffer (Q,N,X) = { |
---|
131 | | - | let x = toBase58String(l.transactionId) |
---|
132 | | - | let O = l.caller.bytes |
---|
133 | | - | let i = fromBase58String(N) |
---|
134 | | - | let Y = getStringValue(this, (Q + "_highest_bid")) |
---|
135 | | - | let Z = getStringValue(this, (Q + "_winner_of_nft")) |
---|
136 | | - | [ScriptTransfer(Address(O), parseIntValue(Y), unit), ScriptTransfer(Address(fromBase58String(Z)), 1, i), StringEntry((x + "_amount_paid_to_owner"), Y), StringEntry((x + "_nft_transfer_to"), Z), StringEntry((x + "_nft_status"), "REWARDED"), StringEntry((Q + "_amount_paid_to_owner"), Y), StringEntry((Q + "_nft_transfer_to"), Z), StringEntry((Q + "_nft_status"), "REWARDED")] |
---|
137 | | - | } |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | |
---|
141 | | - | @Callable(l) |
---|
142 | | - | func cancelAuction (Q) = { |
---|
143 | | - | let x = toBase58String(l.transactionId) |
---|
144 | | - | let O = l.caller.bytes |
---|
145 | | - | let aa = getStringValue(this, (Q + "_nft_status")) |
---|
146 | | - | let ab = getStringValue(this, (Q + "_winner_of_nft")) |
---|
147 | | - | let ac = getStringValue(this, (Q + "_nft_owner")) |
---|
148 | | - | let N = getStringValue(this, (Q + "_nft_on_auction")) |
---|
149 | | - | let ad = getStringValue(this, (Q + "_highest_bid")) |
---|
150 | | - | if ((ab == "0")) |
---|
151 | | - | then [StringEntry(((x + Q) + "_nft_status"), "CANCELED"), ScriptTransfer(Address(fromBase58String(ac)), 1, fromBase58String(N))] |
---|
152 | | - | else [StringEntry((Q + "_nft_status"), "CANCELED"), StringEntry((Q + "_previous_bid_amount_refund_to_address"), ab), StringEntry((Q + "_prevoius_bid_amount_refund"), ad), StringEntry((x + "_nft_status"), "CANCELED"), StringEntry((x + "_previous_bid_amount_refund_to_address"), ab), StringEntry((x + "_prevoius_bid_amount_refund"), ad), ScriptTransfer(Address(fromBase58String(ac)), 1, fromBase58String(N)), ScriptTransfer(Address(fromBase58String(ab)), parseIntValue(ad), unit)] |
---|
153 | | - | } |
---|
154 | | - | |
---|
155 | | - | |
---|
156 | | - | |
---|
157 | | - | @Callable(l) |
---|
158 | | - | func withdrawBid (ae) = { |
---|
159 | | - | let O = l.caller.bytes |
---|
160 | | - | let af = getStringValue(this, (ae + "_highest_bid")) |
---|
161 | | - | let ag = getStringValue(this, (ae + "_winner")) |
---|
162 | | - | let ah = getStringValue(this, (ae + "_nft_id")) |
---|
163 | | - | if ((toBase58String(O) != ag)) |
---|
164 | | - | then throw("No bid") |
---|
165 | | - | else [StringEntry((ae + "_nft_bid"), "WITHDRAW"), StringEntry((ae + "_nft_id"), ah), StringEntry((ae + "_bidding_price_refund_amount"), af), ScriptTransfer(l.caller, parseIntValue(af), unit)] |
---|
166 | | - | } |
---|
167 | | - | |
---|
168 | | - | |
---|
169 | | - | |
---|
170 | | - | @Callable(l) |
---|
171 | | - | func testBid (ai) = [StringEntry("E8kkFBYCy44JJaq6pAZ6KizsuResi5UKNhbD1WNZwhhY_highest_bid", "0")] |
---|