PostDeliveryCrowdsale.sol 1002 B

12345678910111213141516171819202122232425262728293031323334353637
  1. pragma solidity ^0.4.21;
  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(address _beneficiary, uint256 _tokenAmount) internal {
  28. balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
  29. }
  30. }