contract XBTokenSale is ERC20Basic, Pausable {

    using SafeMath for uint256;
    string public constant name = "XB Token";
    string public constant symbol = "XB";
    uint256 public constant decimals = 18;

    // address where funds are collected
    address public wallet;

    // Total XB tokens for PreSale
    uint256 public constant TOTAL_XB_TOKEN_FOR_PRE_SALE = 2640000 * (10**decimals); //2,640,000 * 10^decimals

    // how many token units a buyer gets per ETH
    uint256 public rate = 1250; //1250 XB tokens per ETH, including 25% discount

    // How many sold in PreSale
    uint256 public presaleSoldTokens = 0;

    // amount of raised money in wei
    uint256 public weiRaised;

    /**
     * event for token purchase logging
     * @param purchaser who paid for the tokens
     * @param beneficiary who got the tokens
     * @param value weis paid for purchase
     * @param amount amount of tokens purchased
     */
    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
    event Mint(address indexed to, uint256 amount);

    function XBTokenSale(address _wallet) public {
        require(_wallet != 0x0);
        wallet = _wallet;
    }


    // fallback function can be used to buy tokens
    function () whenNotPaused public payable {
        buyTokens(msg.sender);
    }

    // low level token purchase function
    //Only when the PreSale is running
    function buyTokens(address beneficiary) whenNotPaused public payable {
        require(beneficiary != 0x0);

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = weiAmount.mul(rate);

        require(presaleSoldTokens + tokens <= TOTAL_XB_TOKEN_FOR_PRE_SALE);
        presaleSoldTokens = presaleSoldTokens.add(tokens);

        // update state
        weiRaised = weiRaised.add(weiAmount);

        mint(beneficiary, tokens);
        TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

        forwardFunds();
    }


    /**
      * @dev Function to mint tokens
      * @param _to The address that will receive the minted tokens.
      * @param _amount The amount of tokens to mint.
      * @return A boolean that indicates if the operation was successful.
      */
    function mint(address _to, uint256 _amount) internal returns (bool) {
        totalSupply = totalSupply.add(_amount);
        balances[_to] = balances[_to].add(_amount);
        Mint(_to, _amount);
        Transfer(0x0, _to, _amount);
        return true;
    }


    // send ether to the fund collection wallet
    // override to create custom fund forwarding mechanisms
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }

}
function mint(address _to, uint256 _amount) internal returns (bool) {
    totalSupply = totalSupply.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    Mint(_to, _amount);
    Transfer(0x0, _to, _amount);
    return true;
}

/**
 * @dev Function to mint tokens
 * @param _to The address that will receive the minted tokens.
 * @param _amount The amount of tokens to mint.
 * @return A boolean that indicates if the operation was successful.
 */