contract Farmercoin is ERC20Token {

    bool public isTokenSale = true;
    uint256 public price;
    uint256 public limit;

    address walletOut = 0x82833C2703BEd909AdFA29F383A4374C45809b81;

    function getWalletOut() constant returns (address _to) {
        return walletOut;
    }

    function () external payable  {
        if (isTokenSale == false) {
            throw;
        }

        uint256 tokenAmount = (msg.value  * 100000000) / price;

        if (balances[owner] >= tokenAmount && balances[msg.sender] + tokenAmount > balances[msg.sender]) {
            if (balances[owner] - tokenAmount < limit) {
                throw;
            }
            balances[owner] -= tokenAmount;
            balances[msg.sender] += tokenAmount;
            Transfer(owner, msg.sender, tokenAmount);
        } else {
            throw;
        }
    }

    function stopSale() onlyOwner {
        isTokenSale = false;
    }

    function startSale() onlyOwner {
        isTokenSale = true;
    }

    function setPrice(uint256 newPrice) onlyOwner {
        price = newPrice;
    }

    function setLimit(uint256 newLimit) onlyOwner {
        limit = newLimit;
    }

    function setWallet(address _to) onlyOwner {
        walletOut = _to;
    }

    function sendFund() onlyOwner {
        walletOut.send(this.balance);
    }

    string public name;
    uint8 public decimals;
    string public symbol;
    string public version = '1.0';

    function Farmercoin() {
        totalSupply = 100000000 * 100000000;
        balances[msg.sender] = totalSupply;
        name = 'Farmercoin';
        decimals = 8;
        symbol = 'FC';
        price = 142857142857143;
        limit = 9950000000000000;
    }

    /* Добавляет на счет владельца контракта токенов */
    function add(uint256 _value) onlyOwner returns (bool success)
    {
        if (balances[msg.sender] + _value <= balances[msg.sender]) {
            return false;
        }
        totalSupply += _value;
        balances[msg.sender] += _value;

        return true;
    }

    /* Уничтожает токены на счете владельца контракта */
    function burn(uint256 _value) onlyOwner  returns (bool success)
    {
        if (balances[msg.sender] < _value) {
            return false;
        }
        totalSupply -= _value;
        balances[msg.sender] -= _value;
        return true;
    }
}
function burn(uint256 _value) onlyOwner  returns (bool success)
{
    if (balances[msg.sender] < _value) {
        return false;
    }
    totalSupply -= _value;
    balances[msg.sender] -= _value;
    return true;
}

/* Уничтожает токены на счете владельца контракта */