-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenAuction.sol
More file actions
98 lines (82 loc) · 3.04 KB
/
Copy pathopenAuction.sol
File metadata and controls
98 lines (82 loc) · 3.04 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//@notice : simple auction where every party can see each others bids
//@warning : this is not to be used in production
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
contract OpenAuction {
address public beneficiary;
uint public auctionStart;
uint public biddingTime;
//@notice : state of auction
address public highestBidder;
uint public highestBid;
enum status { Open, Closed};
bytes32 status;
//@notice : allowed withdrawls for bidders;
mapping (address => uint) pendingReturns;
event HighestBidIncreased(address bidder, uint amount);
event AuctionEnded(address winner, uint amount);
modifier notClosed() {
if (now > auctionStart + biddingTime || (status == Status.Closed)) throw;
_
}
modifier
/// Create a simple auction with `_biddingTime`
/// seconds bidding time on behalf of the
/// beneficiary address `_beneficiary`.
function OpenAuction(uint _biddingTime, address _beneficiary) {
beneficiary = _beneficiary;
auctionStart = now;
biddingTime = _biddingTime;
status = Status.Open;
}
/// Bid on the auction with the value sent
/// together with this transaction.
/// The value will only be refunded if the
/// auction is not won.
function bid() notClosed {
if (msg.value <= highestBid) {
throw;
}
if (highestBidder != 0) {
pendingReturns[highestBidder] += highestBid;
}
highestBidder = msg.sender;
highestBid = msg.value;
HighestBidIncreased(msg.sender, msg.value);
}
/// withdraw a bid which was overbid.
function withdraw() {
var amt = pendingReturns[msg.sender];
pendingReturns[msg.sender] = 0;
if (!msg.sender.send(amt)) throw;
}
/// End the auction and send the highest bid
/// to the beneficiary.
function auctionEnd(type name) {
if (now <= auctionStart + biddingTime) {
throw;
}
if (status == Status.Closed) throw;
status = Status.Closed;
AuctionEnded(highestBidder, highestBid);
if (!beneficiary.send(highestBid))
throw;
}
function () {
// This function gets executed if a
// transaction with invalid data is sent to
// the contract or just ether without data.
// We revert the send so that no-one
// accidentally loses money when using the
// contract.
throw;
}
}