PostDeliveryCrowdsale.sol 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pragma solidity ^0.4.24;
  2. import "../validation/TimedCrowdsale.sol";
  3. import "../../token/ERC20/ERC20.sol";
  4. import "../../math/SafeMath.sol";
  5. /**
  6. * @title PostDeliveryCrowdsale
  7. * @dev Crowdsale that locks tokens from withdrawal until it ends.
  8. */
  9. contract PostDeliveryCrowdsale is TimedCrowdsale {
  10. using SafeMath for uint256;
  11. mapping(address => uint256) public balances;
  12. /**
  13. * @dev Withdraw tokens only after crowdsale ends.
  14. */
  15. function withdrawTokens() public {
  16. require(hasClosed());
  17. uint256 amount = balances[msg.sender];
  18. require(amount > 0);
  19. balances[msg.sender] = 0;
  20. _deliverTokens(msg.sender, amount);
  21. }
  22. /**
  23. * @dev Overrides parent by storing balances instead of issuing tokens right away.
  24. * @param _beneficiary Token purchaser
  25. * @param _tokenAmount Amount of tokens purchased
  26. */
  27. function _processPurchase(
  28. address _beneficiary,
  29. uint256 _tokenAmount
  30. )
  31. internal
  32. {
  33. balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
  34. }
  35. }