Created
January 25, 2018 23:43
-
-
Save udany/c3936fdd55076e220757067d87141831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.19; | |
contract Auction { | |
uint ask; | |
uint startTime; | |
uint timeLimit; | |
address owner; | |
bool completed; | |
uint winningBid; | |
address winningBidder; | |
function Auction(uint _ask, uint _timeLimit) public { | |
owner = msg.sender; | |
ask = _ask; | |
startTime = now; | |
timeLimit = _timeLimit; | |
} | |
function isActive() view public returns (bool) { | |
return timeLimit == 0 || now < (startTime + timeLimit); | |
} | |
function bid() payable public { | |
require(isActive()); | |
require(ask <= msg.value); | |
require(winningBid < msg.value); | |
if (winningBidder > 0) { | |
// Return winningBidder funds | |
uint x = winningBid; | |
winningBid = 0; | |
winningBidder.transfer(x); | |
} | |
// Set new winning bid | |
winningBid = msg.value; | |
winningBidder = msg.sender; | |
} | |
function getAsk() public view returns (uint) { | |
return ask; | |
} | |
function getWinningBid() public view returns (uint) { | |
return winningBid; | |
} | |
function payOwner() public { | |
require(!isActive()); | |
require(!completed); | |
require(msg.sender == winningBidder); | |
completed = true; | |
if (!owner.send(winningBid)) revert(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment