PostDeliveryCrowdsale.sol 1.2 KB

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