Skip to content

Instantly share code, notes, and snippets.

@pabloruiz55
Created November 14, 2017 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pabloruiz55/99da5a8c839f2fbff0945475354eb9ba to your computer and use it in GitHub Desktop.
Save pabloruiz55/99da5a8c839f2fbff0945475354eb9ba to your computer and use it in GitHub Desktop.
//Anyone can bid by calling this function and supplying the corresponding eth
function bid() public payable {
require(auctionStarted);
require(now < auctionEndTime);
require(msg.sender != auctioneer);
require(highestBidder != msg.sender); //If sender is already the highest bidder, reject it.
address _newBidder = msg.sender;
uint previousBid = balances[_newBidder];
uint _newBid = msg.value + previousBid;
require (_newBid == highestBid + (5 * 10 ** 16)); //Each bid has to be 0.05 eth higher
// The highest bidder is now the second highest bidder
secondHighestBid = highestBid;
secondHighestBidder = highestBidder;
highestBid = _newBid;
highestBidder = _newBidder;
latestBidTime = now;
//Update the bidder's balance so they can later withdraw any pending balance
balances[_newBidder] = _newBid;
//If there's less than an hour remaining and someone bids, extend end time.
if(auctionEndTime - now < 3600)
auctionEndTime += 3600; // Each bid extends the auctionEndTime by 1 hour
E_Bid(highestBidder, highestBid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment