Created
June 29, 2017 19:08
-
-
Save brynbellomy/59edbeefcc94c9e85bcea06e4291d33c to your computer and use it in GitHub Desktop.
medium-auction-contract-6.sol
This file contains hidden or 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
| function placeBid() | |
| payable | |
| onlyAfterStart | |
| onlyBeforeEnd | |
| onlyNotCanceled | |
| onlyNotOwner | |
| returns (bool success) | |
| { | |
| // reject payments of 0 ETH | |
| if (msg.value == 0) throw; | |
| // calculate the user's total bid based on the current amount they've sent to the contract | |
| // plus whatever has been sent with this transaction | |
| uint newBid = fundsByBidder[msg.sender] + msg.value; | |
| // if the user isn't even willing to overbid the highest binding bid, there's nothing for us | |
| // to do except revert the transaction. | |
| if (newBid <= highestBindingBid) throw; | |
| // grab the previous highest bid (before updating fundsByBidder, in case msg.sender is the | |
| // highestBidder and is just increasing their maximum bid). | |
| uint highestBid = fundsByBidder[highestBidder]; | |
| fundsByBidder[msg.sender] = newBid; | |
| if (newBid <= highestBid) { | |
| // if the user has overbid the highestBindingBid but not the highestBid, we simply | |
| // increase the highestBindingBid and leave highestBidder alone. | |
| // note that this case is impossible if msg.sender == highestBidder because you can never | |
| // bid less ETH than you already have. | |
| highestBindingBid = min(newBid + bidIncrement, highestBid); | |
| } else { | |
| // if msg.sender is already the highest bidder, they must simply be wanting to raise | |
| // their maximum bid, in which case we shouldn't increase the highestBindingBid. | |
| // if the user is NOT highestBidder, and has overbid highestBid completely, we set them | |
| // as the new highestBidder and recalculate highestBindingBid. | |
| if (msg.sender != highestBidder) { | |
| highestBidder = msg.sender; | |
| highestBindingBid = min(newBid, highestBid + bidIncrement); | |
| } | |
| highestBid = newBid; | |
| } | |
| LogBid(msg.sender, newBid, highestBidder, highestBid, highestBindingBid); | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment