4 | | - | let auctionDuration = (1440 * 1) |
---|
5 | | - | |
---|
6 | | - | @Callable(i) |
---|
7 | | - | func beginAuction (minPrice,duration) = if ((duration > auctionDuration)) |
---|
8 | | - | then throw((((("Specified duration(" + toString(duration)) + ") exceeds the maximum duration(") + toString(auctionDuration)) + ")")) |
---|
9 | | - | else { |
---|
10 | | - | let auctionId = toBase58String(i.transactionId) |
---|
11 | | - | let endTime = (lastBlock.height + duration) |
---|
12 | | - | let pmt = extract(i.payment) |
---|
13 | | - | WriteSet([DataEntry(auctionId, auctionId), DataEntry((auctionId + "_endTime"), endTime), DataEntry((auctionId + "_owner"), toBase58String(i.caller.bytes)), DataEntry((auctionId + "_itemId"), if (isDefined(pmt.assetId)) |
---|
14 | | - | then toBase58String(value(pmt.assetId)) |
---|
15 | | - | else throw("Item not atached")), DataEntry((auctionId + "_minPrice"), minPrice)]) |
---|
16 | | - | } |
---|
17 | | - | |
---|
21 | | - | func bid (auctionId) = { |
---|
22 | | - | let callerAddress = toBase58String(i.caller.bytes) |
---|
23 | | - | let endTime = getIntegerValue(this, (auctionId + "_endTime")) |
---|
24 | | - | let minPrice = getIntegerValue(this, (auctionId + "_minPrice")) |
---|
25 | | - | let highestBidAmt = getInteger(this, (auctionId + "_highestBidAmt")) |
---|
26 | | - | let highestBidder = getString(this, (auctionId + "_highestBidder")) |
---|
27 | | - | let bidFromTheSameUser = if (isDefined(highestBidder)) |
---|
28 | | - | then (value(highestBidder) == callerAddress) |
---|
29 | | - | else false |
---|
30 | | - | let totalBidAmount = (1000000 + (if (bidFromTheSameUser) |
---|
31 | | - | then value(highestBidAmt) |
---|
32 | | - | else 0)) |
---|
33 | | - | if (!(isDefined(getIntegerValue(this, auctionId)))) |
---|
34 | | - | then throw("Auction Id not found") |
---|
35 | | - | else if ((lastBlock.height >= endTime)) |
---|
36 | | - | then throw("Auction Completed") |
---|
37 | | - | else if (if (if (!(isDefined(highestBidAmt))) |
---|
38 | | - | then (minPrice >= totalBidAmount) |
---|
39 | | - | else false) |
---|
40 | | - | then true |
---|
41 | | - | else if (isDefined(highestBidAmt)) |
---|
42 | | - | then (value(highestBidAmt) >= totalBidAmount) |
---|
43 | | - | else false) |
---|
44 | | - | then throw(("Bid must be more then " + (if (!(isDefined(highestBidAmt))) |
---|
45 | | - | then toString(minPrice) |
---|
46 | | - | else toString(value(highestBidAmt))))) |
---|
47 | | - | else if (!(isDefined(highestBidder))) |
---|
48 | | - | then WriteSet([DataEntry((auctionId + "_highestBidder"), callerAddress), DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]) |
---|
49 | | - | else if (bidFromTheSameUser) |
---|
50 | | - | then WriteSet([DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]) |
---|
51 | | - | else { |
---|
52 | | - | let previousBidder = addressFromStringValue(value(highestBidder)) |
---|
53 | | - | ScriptResult(WriteSet([DataEntry((auctionId + "_highestBidder"), callerAddress), DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]), TransferSet([ScriptTransfer(previousBidder, value(highestBidAmt), unit)])) |
---|
54 | | - | } |
---|
55 | | - | } |
---|
| 7 | + | func bid (auctionId) = WriteSet([DataEntry("Content_Variable", "hello")]) |
---|