8 | | - | let artefactsAddress = base58'3P5E9xamcWoymiqLx8ZdmR7o4fJSRMGp1WR' |
---|
9 | | - | |
---|
10 | | - | let feeAggregator = base58'3P6AobNbcQ3ZjcRY37mJPKN8PP9Giz8kgeY' |
---|
11 | | - | |
---|
12 | | - | let eggAssetId = base58'C1iWsKGqLwjHUndiQ7iXpdmPum9PeCDFfyXBdJJosDRS' |
---|
13 | | - | |
---|
14 | | - | let kGlobalCounter = "GLOBAL_COUNTER" |
---|
15 | | - | |
---|
16 | | - | let feePercent = 5 |
---|
17 | | - | |
---|
18 | | - | let artefactsFeePercent = 20 |
---|
19 | | - | |
---|
20 | | - | func tryGetInteger (key) = { |
---|
21 | | - | let val = match getInteger(this, key) { |
---|
22 | | - | case b: Int => |
---|
23 | | - | b |
---|
24 | | - | case _ => |
---|
25 | | - | 0 |
---|
26 | | - | } |
---|
27 | | - | val |
---|
| 6 | + | @Callable(i) |
---|
| 7 | + | func call () = { |
---|
| 8 | + | let asset = Issue("Asset", "", 1, 0, true, unit, 0) |
---|
| 9 | + | let assetId = calculateAssetId(asset) |
---|
| 10 | + | [BinaryEntry("bin", base58''), BooleanEntry("bool", true), IntegerEntry("int", 1), StringEntry("str", ""), DeleteEntry("str"), asset, Reissue(assetId, 1, false), Burn(assetId, 1), ScriptTransfer(i.caller, 1, assetId)] |
---|
31 | | - | func tryGetString (key) = { |
---|
32 | | - | let val = match getString(this, key) { |
---|
33 | | - | case b: String => |
---|
34 | | - | b |
---|
35 | | - | case _ => |
---|
36 | | - | "" |
---|
37 | | - | } |
---|
38 | | - | val |
---|
39 | | - | } |
---|
40 | | - | |
---|
41 | | - | |
---|
42 | | - | func tryGetBoolean (key) = match getBoolean(this, key) { |
---|
43 | | - | case b: Boolean => |
---|
44 | | - | b |
---|
45 | | - | case _ => |
---|
46 | | - | false |
---|
47 | | - | } |
---|
48 | | - | |
---|
49 | | - | |
---|
50 | | - | func getGlobalCounter () = tryGetInteger(kGlobalCounter) |
---|
51 | | - | |
---|
52 | | - | |
---|
53 | | - | func getAssetGenotype (assetId) = if ((value(assetInfo(assetId)).issuer == Address(artefactsAddress))) |
---|
54 | | - | then "ART" |
---|
55 | | - | else { |
---|
56 | | - | let asset1 = match getString(Address(incubatorAddress), toBase58String(assetId)) { |
---|
57 | | - | case b: String => |
---|
58 | | - | b |
---|
59 | | - | case _ => |
---|
60 | | - | "" |
---|
61 | | - | } |
---|
62 | | - | if ((asset1 != "")) |
---|
63 | | - | then asset1 |
---|
64 | | - | else { |
---|
65 | | - | let asset2 = match getString(Address(breederAddress), toBase58String(assetId)) { |
---|
66 | | - | case c: String => |
---|
67 | | - | c |
---|
68 | | - | case _ => |
---|
69 | | - | "" |
---|
70 | | - | } |
---|
71 | | - | if ((asset2 != "")) |
---|
72 | | - | then asset2 |
---|
73 | | - | else "" |
---|
74 | | - | } |
---|
75 | | - | } |
---|
76 | | - | |
---|
77 | | - | |
---|
78 | | - | @Callable(i) |
---|
79 | | - | func instantBuy (auctionId) = { |
---|
80 | | - | let isEggSell = tryGetBoolean((("auction_" + auctionId) + "_eggSell")) |
---|
81 | | - | let paymentAssetId = if ((isEggSell == true)) |
---|
82 | | - | then eggAssetId |
---|
83 | | - | else unit |
---|
84 | | - | let paymentAssetName = if ((isEggSell == true)) |
---|
85 | | - | then "EGG" |
---|
86 | | - | else "WAVES" |
---|
87 | | - | let pmt = value(i.payments[0]) |
---|
88 | | - | let amount = pmt.amount |
---|
89 | | - | let assetId = tryGetString((("auction_" + auctionId) + "_assetId")) |
---|
90 | | - | let bidId = toBase58String(i.transactionId) |
---|
91 | | - | let auctionStatus = tryGetString((("auction_" + auctionId) + "_status")) |
---|
92 | | - | let finalFee = if ((tryGetBoolean((("auction_" + auctionId) + "_isArtefact")) == true)) |
---|
93 | | - | then artefactsFeePercent |
---|
94 | | - | else feePercent |
---|
95 | | - | if ((pmt.assetId != paymentAssetId)) |
---|
96 | | - | then throw((("Auction does only support " + paymentAssetName) + " payments.")) |
---|
97 | | - | else if ((auctionStatus != "open")) |
---|
98 | | - | then throw("Auction is closed. You cannot place a bid.") |
---|
99 | | - | else { |
---|
100 | | - | let instantPrice = tryGetInteger((("auction_" + auctionId) + "_instantPrice")) |
---|
101 | | - | if ((instantPrice > amount)) |
---|
102 | | - | then throw(("For instant purchase you need to pay at least " + toString(instantPrice))) |
---|
103 | | - | else { |
---|
104 | | - | let auctionOwner = tryGetString((("auction_" + auctionId) + "_owner")) |
---|
105 | | - | let recordPrice = tryGetInteger((assetId + "_recordPrice")) |
---|
106 | | - | let newRecordPrice = max([recordPrice, amount]) |
---|
107 | | - | [StringEntry((("auction_" + auctionId) + "_status"), "finished"), IntegerEntry((("auction_" + auctionId) + "_finalPrice"), amount), IntegerEntry((assetId + "_recordPrice"), newRecordPrice), StringEntry((((("assetId_" + assetId) + "_bid_") + bidId) + "_data"), (((((("{\"auctionId\": \"" + auctionId) + "\", \"author\": \"") + toString(i.originCaller)) + "\", \"amount\": \"") + toString(amount)) + "\", \"status\": \"finished\"}")), DeleteEntry((((("address_" + auctionOwner) + "_auction_") + auctionId) + "_lockedNFT")), ScriptTransfer(i.originCaller, 1, fromBase58String(getStringValue(this, (("auction_" + auctionId) + "_assetId")))), ScriptTransfer(addressFromStringValue(auctionOwner), fraction(amount, (100 - finalFee), 100), paymentAssetId), ScriptTransfer(Address(feeAggregator), fraction(amount, finalFee, 100), paymentAssetId)] |
---|
108 | | - | } |
---|
109 | | - | } |
---|
110 | | - | } |
---|
111 | | - | |
---|
| 14 | + | @Verifier(tx) |
---|
| 15 | + | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|