PostDeliveryCrowdsale.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. pragma solidity ^0.4.24;
  2. import "../validation/TimedCrowdsale.sol";
  3. import "../../token/ERC20/IERC20.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. * @param _beneficiary Whose tokens will be withdrawn.
  15. */
  16. function withdrawTokens(address _beneficiary) public {
  17. require(hasClosed());
  18. uint256 amount = balances[_beneficiary];
  19. require(amount > 0);
  20. balances[_beneficiary] = 0;
  21. _deliverTokens(_beneficiary, amount);
  22. }
  23. /**
  24. * @dev Overrides parent by storing balances instead of issuing tokens right away.
  25. * @param _beneficiary Token purchaser
  26. * @param _tokenAmount Amount of tokens purchased
  27. */
  28. function _processPurchase(
  29. address _beneficiary,
  30. uint256 _tokenAmount
  31. )
  32. internal
  33. {
  34. balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
  35. }
  36. }