contract CarryTokenCrowdsale is WhitelistedCrowdsale, CappedCrowdsale, Pausable {
    using SafeMath for uint256;

    uint256 constant maxGasPrice = 40000000000;  // 40 gwei

    // Individual min and max purchases.
    uint256 public individualMinPurchaseWei;
    uint256 public individualMaxCapWei;

    mapping(address => uint256) public contributions;

    // FIXME: Here we've wanted to use constructor() keyword instead,
    // but solium/solhint lint softwares don't parse it properly as of
    // April 2018.
    function CarryTokenCrowdsale(
        address _wallet,
        CarryToken _token,
        uint256 _rate,
        uint256 _cap,
        uint256 _individualMinPurchaseWei,
        uint256 _individualMaxCapWei
    ) public CappedCrowdsale(_cap) Crowdsale(_rate, _wallet, _token) {
        individualMinPurchaseWei = _individualMinPurchaseWei;
        individualMaxCapWei = _individualMaxCapWei;
    }

    function _preValidatePurchase(
        address _beneficiary,
        uint256 _weiAmount
    ) internal whenNotPaused {
        // Prevent gas war among purchasers.
        require(tx.gasprice <= maxGasPrice);

        super._preValidatePurchase(_beneficiary, _weiAmount);
        uint256 contribution = contributions[_beneficiary];
        uint256 contributionAfterPurchase = contribution.add(_weiAmount);

        // If a contributor already has purchased a minimum amount, say 0.1 ETH,
        // then they can purchase once again with less than a minimum amount,
        // say 0.01 ETH, because they have already satisfied the minimum
        // purchase.
        require(contributionAfterPurchase >= individualMinPurchaseWei);

        require(contributionAfterPurchase <= individualMaxCapWei);
    }

    function _updatePurchasingState(
        address _beneficiary,
        uint256 _weiAmount
    ) internal {
        super._updatePurchasingState(_beneficiary, _weiAmount);
        contributions[_beneficiary] = contributions[_beneficiary].add(
            _weiAmount
        );
    }
}
/**
 * @title CarryTokenCrowdsale
 * @dev The common base contract for both sales: the Carry token presale,
 * and the Carry token public crowdsale.
 */
function CarryTokenCrowdsale(
    address _wallet,
    CarryToken _token,
    uint256 _rate,
    uint256 _cap,
    uint256 _individualMinPurchaseWei,
    uint256 _individualMaxCapWei
) public CappedCrowdsale(_cap) Crowdsale(_rate, _wallet, _token) {
    individualMinPurchaseWei = _individualMinPurchaseWei;
    individualMaxCapWei = _individualMaxCapWei;
}

// FIXME: Here we've wanted to use constructor() keyword instead,
// but solium/solhint lint softwares don't parse it properly as of
// April 2018.