Guest User

Untitled

a guest
Sep 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. import "./MarketPlace.sol";
  4.  
  5. contract Auction{
  6. bytes32 public offerTitle;
  7. address public owner;
  8. int256 public lastOffer ;
  9. address public winner;
  10. MarketPlace public parentMarketPlace;
  11. bool public auctionEndedFlag;
  12. bool public auctionCanceledFlag;
  13.  
  14. event OfferAdded(address offrFrom, int256 price);
  15.  
  16. event AuctionCreated(address indexed parentMarketPlace, address indexed createdBy, bytes32 auctionName);
  17.  
  18. event AuctionEnded(address winner, int256 winningPrice);
  19. event AuctionCanceled();
  20.  
  21. constructor(bytes32 _offerTitle, address _owner) public {
  22. parentMarketPlace = MarketPlace(msg.sender);
  23. offerTitle = _offerTitle;
  24. owner = _owner;
  25. lastOffer = 0;
  26. winner = address(0);
  27. auctionEndedFlag = false;
  28. emit AuctionCreated(parentMarketPlace, owner, offerTitle);
  29. }
  30.  
  31. modifier auctionOpen(){
  32. require(auctionEndedFlag == false, "auction already ended");
  33. _;
  34. }
  35.  
  36. modifier onlyAuthorized(){
  37. require(parentMarketPlace.users(msg.sender) == true, "Not autorized for this auction");
  38. _;
  39. }
  40.  
  41. function addOffer(int256 price) external auctionOpen onlyAuthorized {
  42. require(msg.sender != owner, "you can not offer for your own auction");
  43. require(price > lastOffer, "Offer to small");
  44. lastOffer = price;
  45. winner = msg.sender;
  46. emit OfferAdded(msg.sender, price);
  47. }
  48.  
  49. modifier onlyOwner(){
  50. require(owner == msg.sender);
  51. _;
  52. }
  53.  
  54. function endAuction() external onlyOwner{
  55. require(auctionCanceledFlag == false, "auction already canceled");
  56. require(auctionEndedFlag == false, "auction already eneded");
  57. auctionEndedFlag = true;
  58. emit AuctionEnded(winner, lastOffer);
  59. }
  60.  
  61. function cancelAuction() external onlyOwner{
  62. require(auctionEndedFlag == false, "auction already eneded");
  63. require(auctionCanceledFlag == false, "auction already canceled");
  64. auctionCanceledFlag = true;
  65. emit AuctionCanceled();
  66. }
  67. }
Add Comment
Please, Sign In to add comment