2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let keyTopBalance = "_bid" |
---|
5 | | - | |
---|
6 | | - | let keyTopBidder = "_topbidder" |
---|
7 | | - | |
---|
8 | | - | let keyToken = "_token" |
---|
9 | | - | |
---|
10 | | - | let keyOrganizer = "_organizer" |
---|
11 | | - | |
---|
12 | | - | let keyHeight = "_height" |
---|
13 | | - | |
---|
14 | | - | let isFinished = (height >= extract(getInteger(this, keyHeight))) |
---|
15 | | - | |
---|
16 | | - | func getBalance (address) = match getInteger(this, address) { |
---|
17 | | - | case a: Int => |
---|
18 | | - | a |
---|
19 | | - | case _ => |
---|
20 | | - | 0 |
---|
21 | | - | } |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | func getTopBalance () = match getInteger(this, keyTopBalance) { |
---|
25 | | - | case a: Int => |
---|
26 | | - | a |
---|
27 | | - | case _ => |
---|
28 | | - | 0 |
---|
29 | | - | } |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | @Callable(i) |
---|
33 | | - | func bid () = { |
---|
34 | | - | let bidder = toBase58String(i.caller.bytes) |
---|
35 | | - | let currentBalance = getBalance(bidder) |
---|
36 | | - | if (!(isFinished)) |
---|
37 | | - | then { |
---|
38 | | - | let payment = match i.payment { |
---|
39 | | - | case p: AttachedPayment => |
---|
40 | | - | p |
---|
41 | | - | case _ => |
---|
42 | | - | throw("You have to provide a payment to your bid") |
---|
43 | | - | } |
---|
44 | | - | if ((payment.assetId != unit)) |
---|
45 | | - | then throw("This wallet cannot hold assets other than $Waves") |
---|
46 | | - | else { |
---|
47 | | - | let actualBalance = (currentBalance + payment.amount) |
---|
48 | | - | let topbidderBalance = getTopBalance() |
---|
49 | | - | if ((actualBalance > topbidderBalance)) |
---|
50 | | - | then WriteSet([DataEntry(bidder, actualBalance), DataEntry(keyTopBalance, actualBalance), DataEntry(keyTopBidder, bidder)]) |
---|
51 | | - | else WriteSet([DataEntry(bidder, actualBalance)]) |
---|
52 | | - | } |
---|
53 | | - | } |
---|
54 | | - | else throw("Auction is over") |
---|
55 | | - | } |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | @Callable(i) |
---|
60 | | - | func withdraw (address) = { |
---|
61 | | - | let bidder = if ((address == "")) |
---|
62 | | - | then toBase58String(i.caller.bytes) |
---|
63 | | - | else if (if (if (if (if ((address == keyTopBalance)) |
---|
64 | | - | then true |
---|
65 | | - | else (address == keyTopBidder)) |
---|
66 | | - | then true |
---|
67 | | - | else (address == keyToken)) |
---|
68 | | - | then true |
---|
69 | | - | else (address == keyOrganizer)) |
---|
70 | | - | then true |
---|
71 | | - | else (address == keyHeight)) |
---|
72 | | - | then throw("Nice try") |
---|
73 | | - | else address |
---|
74 | | - | let isTopBidder = (getString(this, keyTopBidder) == bidder) |
---|
75 | | - | let isOrganizer = (getString(this, keyOrganizer) == bidder) |
---|
76 | | - | let isBidder = (getBalance(bidder) > 0) |
---|
77 | | - | if (isFinished) |
---|
78 | | - | then if (if (isTopBidder) |
---|
79 | | - | then true |
---|
80 | | - | else isOrganizer) |
---|
81 | | - | then { |
---|
82 | | - | let topBidder = extract(getString(this, keyTopBidder)) |
---|
83 | | - | let Organizer = extract(addressFromString(extract(getString(this, keyOrganizer)))) |
---|
84 | | - | let topBidderAmount = getBalance(topBidder) |
---|
85 | | - | let Token = fromBase58String(extract(getString(this, keyToken))) |
---|
86 | | - | if ((topBidderAmount > 0)) |
---|
87 | | - | then ScriptResult(WriteSet([DataEntry(topBidder, 0)]), TransferSet([ScriptTransfer(extract(addressFromString(topBidder)), 1, Token), ScriptTransfer(Organizer, topBidderAmount, unit)])) |
---|
88 | | - | else throw("Not again") |
---|
89 | | - | } |
---|
90 | | - | else if (isBidder) |
---|
91 | | - | then { |
---|
92 | | - | let amount = getBalance(bidder) |
---|
93 | | - | ScriptResult(WriteSet([DataEntry(bidder, 0)]), TransferSet([ScriptTransfer(extract(addressFromString(bidder)), amount, unit)])) |
---|
94 | | - | } |
---|
95 | | - | else throw("Wrong address or noting to transfer") |
---|
96 | | - | else throw("Auction is not finished yet") |
---|
97 | | - | } |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | @Verifier(tx) |
---|
101 | | - | func verify () = true |
---|
102 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|