Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. pragma solidity ^0.5.0;
  2.  
  3.  
  4. import "./DappToken.sol";
  5.  
  6.  
  7. contract DappTokenSale {
  8.  
  9. address admin;
  10. DappToken public tokenContract;
  11. uint256 public tokenPrice;
  12. uint256 public tokensSold;
  13.  
  14. event Sell(address _buyer, uint256 _amount);
  15.  
  16. constructor (DappToken _tokenContract, uint256 _tokenPrice) public {
  17. admin = msg.sender;
  18. tokenContract = _tokenContract;
  19. tokenPrice = _tokenPrice;
  20. }
  21. function multiply (uint x, uint y) internal pure returns (uint z) {
  22. require(y == 0 || (z = x * y) / y == x);
  23. }
  24.  
  25. function buyTokens (uint256 _numberOfTokens) public payable {
  26.  
  27. require (msg.value == multiply(_numberOfTokens, tokenPrice));
  28. require (tokenContract.balanceOf(address(this)) >= _numberOfTokens);
  29. require (tokenContract.transfer(msg.sender, _numberOfTokens));
  30.  
  31.  
  32. tokensSold += _numberOfTokens;
  33. emit Sell(msg.sender, _numberOfTokens);
  34. }
  35. function endSale () public {
  36.  
  37. require (msg.value == admin);
  38. require (tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
  39. selfdestruct(admin);
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement