PostDeliveryCrowdsale.sol 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. constructor() internal {}
  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. * @return the balance of an account.
  25. */
  26. function balanceOf(address account) public view returns(uint256) {
  27. return _balances[account];
  28. }
  29. /**
  30. * @dev Overrides parent by storing balances instead of issuing tokens right away.
  31. * @param beneficiary Token purchaser
  32. * @param tokenAmount Amount of tokens purchased
  33. */
  34. function _processPurchase(
  35. address beneficiary,
  36. uint256 tokenAmount
  37. )
  38. internal
  39. {
  40. _balances[beneficiary] = _balances[beneficiary].add(tokenAmount);
  41. }
  42. }