Last active
March 21, 2016 08:26
-
-
Save y12studio/725d5dd9a06a6cdfe7b1 to your computer and use it in GitHub Desktop.
Y12 Simple Open Auction 2
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
// Solidity by Example — Solidity 0.2.0 documentation http://solidity.readthedocs.org/en/latest/solidity-by-example.html | |
// Ethereum以太坊智能合約環境說明 https://gist.github.com/y12studio/f142cd9789c7d396d8f7 | |
contract YSOA { | |
// time periods in seconds. | |
address public beneficiary; | |
address public feeDao; | |
uint public auctionStart; | |
uint public biddingTime; | |
uint32 public feePpm; | |
uint public feeBalance; | |
// Current state of the auction. | |
address public highestBidder; | |
uint public highestBid; | |
// Set to true at the end, disallows any change | |
bool ended; | |
// Events that will be fired on changes. | |
event HighestBidIncreased(address bidder, uint amount); | |
event AuctionEnded(address winner, uint amount); | |
// Create a simple auction with `_biddingTime` | |
// seconds bidding time on behalf of the | |
// beneficiary address `_beneficiary`. | |
// feeDao address | |
// feeRate parts per million(PPM), 0.256% = 2560 ppm | |
function YSOA(uint _biddingTime, address _beneficiary, address _feeDao, uint32 _feePpm) { | |
beneficiary = _beneficiary; | |
feeDao = _feeDao; | |
feePpm = _feePpm; | |
auctionStart = now; | |
biddingTime = _biddingTime; | |
} | |
/// Bid on the auction with the value sent | |
/// together with this transaction. | |
/// The value will only be refunded if the | |
/// auction is not won. | |
function bid() { | |
// No arguments are necessary, all | |
// information is already part of | |
// the transaction. | |
if (now > auctionStart + biddingTime) | |
// Revert the call if the bidding | |
// period is over. | |
throw; | |
if (msg.value <= highestBid) | |
// If the bid is not higher, send the | |
// money back. | |
throw; | |
if (highestBidder != 0) { | |
uint fee = highestBid/1000000*feePpm; | |
feeBalance += fee; | |
highestBidder.send(highestBid-fee); | |
} | |
highestBidder = msg.sender; | |
highestBid = msg.value; | |
HighestBidIncreased(msg.sender, msg.value); | |
} | |
// End the auction and send the highest bid to the beneficiary. | |
function auctionEnd() { | |
if (now <= auctionStart + biddingTime) | |
throw; // auction did not yet end | |
if (ended) | |
throw; // this function has already been called | |
AuctionEnded(highestBidder, highestBid); | |
uint benAmount = this.balance-feeBalance; | |
if(feeBalance>0){ | |
feeDao.send(feeBalance); | |
} | |
beneficiary.send(benAmount); | |
ended = true; | |
} | |
function rescueBalanceDevOnly(){ | |
beneficiary.send(this.balance); | |
} | |
function () { | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment