12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- pragma solidity ^0.4.24;
- import "../../math/SafeMath.sol";
- import "../Crowdsale.sol";
- /**
- * @title TimedCrowdsale
- * @dev Crowdsale accepting contributions only within a time frame.
- */
- contract TimedCrowdsale is Crowdsale {
- using SafeMath for uint256;
- uint256 private _openingTime;
- uint256 private _closingTime;
- /**
- * @dev Reverts if not in crowdsale time range.
- */
- modifier onlyWhileOpen {
- require(isOpen());
- _;
- }
- /**
- * @dev Constructor, takes crowdsale opening and closing times.
- * @param openingTime Crowdsale opening time
- * @param closingTime Crowdsale closing time
- */
- constructor(uint256 openingTime, uint256 closingTime) internal {
- // solium-disable-next-line security/no-block-members
- require(openingTime >= block.timestamp);
- require(closingTime > openingTime);
- _openingTime = openingTime;
- _closingTime = closingTime;
- }
- /**
- * @return the crowdsale opening time.
- */
- function openingTime() public view returns(uint256) {
- return _openingTime;
- }
- /**
- * @return the crowdsale closing time.
- */
- function closingTime() public view returns(uint256) {
- return _closingTime;
- }
- /**
- * @return true if the crowdsale is open, false otherwise.
- */
- function isOpen() public view returns (bool) {
- // solium-disable-next-line security/no-block-members
- return block.timestamp >= _openingTime && block.timestamp <= _closingTime;
- }
- /**
- * @dev Checks whether the period in which the crowdsale is open has already elapsed.
- * @return Whether crowdsale period has elapsed
- */
- function hasClosed() public view returns (bool) {
- // solium-disable-next-line security/no-block-members
- return block.timestamp > _closingTime;
- }
- /**
- * @dev Extend parent behavior requiring to be within contributing period
- * @param beneficiary Token purchaser
- * @param weiAmount Amount of wei contributed
- */
- function _preValidatePurchase(
- address beneficiary,
- uint256 weiAmount
- )
- internal
- onlyWhileOpen
- view
- {
- super._preValidatePurchase(beneficiary, weiAmount);
- }
- }
|