Skip to content

Instantly share code, notes, and snippets.

@udany
Created January 25, 2018 23:43
Show Gist options
  • Save udany/c3936fdd55076e220757067d87141831 to your computer and use it in GitHub Desktop.
Save udany/c3936fdd55076e220757067d87141831 to your computer and use it in GitHub Desktop.
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