daily pastebin goal
29%
SHARE
TWEET

Conference_New_V2

a guest Mar 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.5.6;
  2.  
  3. import "./Conference_Ownable_New.sol";
  4.  
  5. contract Conference_New_V2 is Conference_Ownable_New{
  6.  
  7.     mapping(address => Registrant) public registrantsPaid;
  8.  
  9.     uint public numRegistrants;
  10.     uint public quota;
  11.  
  12.     event Deposit(address _from, uint _amount, string _name);
  13.     event Refund(address _to, uint _amount, string _name);
  14.     event AlreadyRefunded(address _to, string _name);
  15.  
  16.     struct Registrant {
  17.         uint256 price;
  18.         string name;
  19.     }
  20.  
  21.     constructor() public {
  22.         quota = 500;
  23.         numRegistrants = 0;
  24.     }
  25.  
  26.     function getPrice(address _recipient) public view returns (uint price) {
  27.         return registrantsPaid[_recipient].price;
  28.     }
  29.  
  30.     function getName(address _recipient) public view returns (string memory name) {
  31.         return registrantsPaid[_recipient].name;
  32.     }
  33.  
  34.  
  35.     function buyTicket(string memory _name) public payable returns (bool success) {
  36.         require(numRegistrants < quota);
  37.         Registrant storage reg = registrantsPaid[msg.sender];
  38.         reg.price = msg.value;
  39.         reg.name = _name;
  40.         numRegistrants++;
  41.         emit Deposit(msg.sender, msg.value, _name);
  42.         return true;
  43.     }
  44.  
  45.     function refundTicket(address payable _recipient) onlyAdminOrOrganizer public {
  46.         Registrant storage reg = registrantsPaid[_recipient];
  47.    
  48.         uint amount = reg.price;
  49.    
  50.         if (amount == 0) {
  51.             emit AlreadyRefunded(_recipient, reg.name);
  52.             revert();
  53.         } else if (address(this).balance >= amount) {
  54.             reg.price = 0;
  55.             numRegistrants--;
  56.             emit Refund(_recipient, amount, reg.name);
  57.             _recipient.transfer(amount);
  58.         }
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top