-
Notifications
You must be signed in to change notification settings - Fork 0
/
auction.sol
43 lines (33 loc) · 1.03 KB
/
auction.sol
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
39
40
41
42
contract Auction {
bool isOpen;
address owner;
uint256 maxBid;
mapping(address => uint) bids;
constructor() public { owner = msg.sender; }
// Access controls.
modifier ownerOnly() { require(owner == msg.sender); _; }
function releaseTo(address _new) public ownerOnly { owner = _new; }
function open() public ownerOnly { isOpen = true; }
function close() public ownerOnly { isOpen = false; }
// Place a bid.
function deposit() public payable {
uint256 bid = bids[msg.sender] + msg.value;
require(isOpen);
require(bid > maxBid);
bids[msg.sender] = bid;
maxBid = bid;
}
// Withdraw a losing bid.
function withdraw() public payable {
uint256 bid = bids[msg.sender];
require(isOpen);
require(bid < maxBid);
bids[msg.sender] = 0;
msg.sender.transfer(bid);
}
}
contract Manager {
Auction auction;
constructor() public { auction = new Auction(); }
function openAuction() public { auction.open(); }
}