Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. pragma solidity ^0.4.13;
  2.  
  3. contract SimpleAuction {
  4. uint auctionEnd;
  5. address public highestBidder;
  6. uint public highestBid;
  7. address beneficiary;
  8.  
  9. // Allowed withdrawals of previous bids
  10. mapping(address => uint) pendingReturns;
  11.  
  12. // Set to true at the end, disallows any change
  13. bool ended;
  14.  
  15. // Events that will be fired on changes.
  16. event HighestBidIncreased(address bidder, uint amount);
  17. event AuctionEnded(address winner, uint amount);
  18.  
  19. function SimpleAuction (uint _biddingTime, address _beneficiary) public {
  20. beneficiary = _beneficiary;
  21. auctionEnd = now + _biddingTime;
  22. }
  23.  
  24. function bid() payable {
  25. require (msg.value > highestBid);
  26. if (highestBidder != 0) {
  27. pendingReturns[highestBidder] = pendingReturns[highestBidder]+highestBid;
  28. }
  29. highestBidder = msg.sender;
  30. highestBid = msg.value;
  31. HighestBidIncreased(msg.sender, msg.value);
  32. }
  33.  
  34. function withdraw() public returns (bool) {
  35. uint amount = pendingReturns[msg.sender];
  36. if (amount > 0) {
  37. pendingReturns[msg.sender] = 0;
  38. if (!msg.sender.send(amount)) {
  39. pendingReturns[msg.sender] = amount;
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45.  
  46. function getFunds() constant public returns(uint) {
  47. return this.balance;
  48. }
  49.  
  50. function EndAuction() public {
  51. // 1. Conditions
  52. require (!ended); // this function has already been called
  53. // 2. Effects
  54. ended = true;
  55. AuctionEnded(highestBidder, highestBid);
  56. if(!beneficiary.send(this.balance)){ }// this step will transfer the amount to beneficiary
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement