PostDeliveryCrowdsale.sol 1000 B

1234567891011121314151617181920212223242526272829303132333435
  1. pragma solidity ^0.4.18;
  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 Overrides parent by storing balances instead of issuing tokens right away.
  14. * @param _beneficiary Token purchaser
  15. * @param _tokenAmount Amount of tokens purchased
  16. */
  17. function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
  18. balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount);
  19. }
  20. /**
  21. * @dev Withdraw tokens only after crowdsale ends.
  22. */
  23. function withdrawTokens() public {
  24. require(hasClosed());
  25. uint256 amount = balances[msg.sender];
  26. require(amount > 0);
  27. balances[msg.sender] = 0;
  28. _deliverTokens(msg.sender, amount);
  29. }
  30. }