Skip to content

Instantly share code, notes, and snippets.

@goodjoon
Created March 26, 2016 16:58
Show Gist options
  • Select an option

  • Save goodjoon/bba246f0ce012dd6919a to your computer and use it in GitHub Desktop.

Select an option

Save goodjoon/bba246f0ce012dd6919a to your computer and use it in GitHub Desktop.
contract SimpleAuction {
address public beneficiary;
uint public auctionStart;
uint public biddingTime;
address public highestBidder;
uint public highestBid;
bool ended;
event HighestBidIncreased(address bidder, uint amount);
event AuctionEnded(address winner, uint amount);
function SimpleAuction(uint _biddingTime, address _beneficiary) {
beneficiary = _beneficiary;
auctionStart = now;
biddingTime = _biddingTime;
}
function bid() {
if (now > auctionStart + biddingTime) throw;
// 신고가가 아니면 중단하고 돈 돌려줌
if (msg.value <= highestBid) throw;
// 이전 highestBidder 에게 돈 돌려줌
if (highestBidder != 0) highestBidder.send(highestBid);
highestBidder = msg.sender;
highestBid = msg.value;
// event 날려줌
HighestBidIncreased(msg.sender, msg.value);
}
// Acuction 을 끝내고 highestBid 를 beneficiary 에게 보냄
function auctionEnd() {
if (now <= auctionStart + biddingTime) throw;
if (ended) throw;
AuctionEnded(highestBidder, highestBid);
beneficiary.send(this.balance);
ended = true;
}
function() {
// 이 함수는 invalid 데이터나 data 없이 ether 만 보내진 경우
// 실행된다. 이렇게 해서 실수로 돈이 Contract 로 보내지는걸 막는다.
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment