PostDeliveryCrowdsale.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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) private _balances;
  12. constructor() internal {}
  13. /**
  14. * @dev Withdraw tokens only after crowdsale ends.
  15. * @param beneficiary Whose tokens will be withdrawn.
  16. */
  17. function withdrawTokens(address beneficiary) public {
  18. require(hasClosed());
  19. uint256 amount = _balances[beneficiary];
  20. require(amount > 0);
  21. _balances[beneficiary] = 0;
  22. _deliverTokens(beneficiary, amount);
  23. }
  24. /**
  25. * @return the balance of an account.
  26. */
  27. function balanceOf(address account) public view returns(uint256) {
  28. return _balances[account];
  29. }
  30. /**
  31. * @dev Overrides parent by storing balances instead of issuing tokens right away.
  32. * @param beneficiary Token purchaser
  33. * @param tokenAmount Amount of tokens purchased
  34. */
  35. function _processPurchase(
  36. address beneficiary,
  37. uint256 tokenAmount
  38. )
  39. internal
  40. {
  41. _balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
  42. }
  43. }