Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.13;
- contract SimpleAuction {
- uint auctionEnd;
- address public highestBidder;
- uint public highestBid;
- address beneficiary;
- // Allowed withdrawals of previous bids
- mapping(address => uint) pendingReturns;
- // 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);
- function SimpleAuction (uint _biddingTime, address _beneficiary) public {
- beneficiary = _beneficiary;
- auctionEnd = now + _biddingTime;
- }
- function bid() payable {
- require (msg.value > highestBid);
- if (highestBidder != 0) {
- pendingReturns[highestBidder] = pendingReturns[highestBidder]+highestBid;
- }
- highestBidder = msg.sender;
- highestBid = msg.value;
- HighestBidIncreased(msg.sender, msg.value);
- }
- function withdraw() public returns (bool) {
- uint amount = pendingReturns[msg.sender];
- if (amount > 0) {
- pendingReturns[msg.sender] = 0;
- if (!msg.sender.send(amount)) {
- pendingReturns[msg.sender] = amount;
- return false;
- }
- }
- return true;
- }
- function getFunds() constant public returns(uint) {
- return this.balance;
- }
- function EndAuction() public {
- // 1. Conditions
- require (!ended); // this function has already been called
- // 2. Effects
- ended = true;
- AuctionEnded(highestBidder, highestBid);
- if(!beneficiary.send(this.balance)){ }// this step will transfer the amount to beneficiary
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement