-
Notifications
You must be signed in to change notification settings - Fork 2
/
open_auction2.vif
38 lines (33 loc) · 1.07 KB
/
open_auction2.vif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Author: Haobin Ni, 2018
# Another simple open auction.
# Everyone can submit bids at any price.
# Everyone can end the auction after the end time.
beneficiary: IFL(address, beneficiary)
auction_start: IFL(timestamp, this)
auction_end: IFL(timestamp, this)
highest_bidder: IFL(address, this)
highest_bid: IFL(wei_value, this)
ended: IFL(bool, this)
@public
@IFL_beneficiary
def __init__(_beneficiary: address, _bidding_time: timedelta):
self.beneficiary = _beneficiary
self.auction_start = block.timestamp
self.auction_end = self.auction_start + endorse(_bidding_time, beneficiary, this)
@public
@payable
@IFL_this
def bid():
assert block.timestamp < self.auction_end
assert msg.value > self.highest_bid
if not self.highest_bid == 0:
send(self.highest_bidder, self.highest_bid)
self.highest_bidder = msg.sender
self.highest_bid = msg.value
@public
@IFL_this
def end_auction():
assert block.timestamp >= self.auction_end
assert not self.ended
self.ended = True
send(endorse(self.beneficiary, beneficiary, this), self.highest_bid)