contract ChocolateToken is ERC20Interface, Owned, SafeMath {
    string public name = "Chocolate";
    string public symbol = "CHOC";
    uint8 public decimals = 18;
    uint public _totalSupply = 11500e18;
    bool public isLocked;
    
    address[]   private     blackList;
    address[]   private     vaultList;
    mapping(address => uint) vaultAmount;
    mapping(address => uint) vaultReleaseTime;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    constructor(address multisig) public {
        balances[multisig] = safeAdd(balances[multisig], _totalSupply);
        emit Transfer(address(0), msg.sender, _totalSupply);
        isLocked = false;
    }

    modifier isNotLocked {
        require(!isLocked);
        _;
    }

    function setIsLocked(bool _isLocked) public onlyOwner{
        isLocked = _isLocked;
    }


    // ------------------------------------------------------------------------
    // Total supply
    // ------------------------------------------------------------------------
    function totalSupply() public view returns (uint) {
        return _totalSupply  - balances[address(0)];
    }


    // ------------------------------------------------------------------------
    // Get the token balance for account `tokenOwner`
    // ------------------------------------------------------------------------
    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return balances[tokenOwner];
    }


    function isBlacklisted(address account) private view returns(bool) {
        uint i;
        for (i = 0; i < blackList.length; i++) {
            if (blackList[i] == account)
                return true;
        }
        return false;
    }
    
    
    function addBlacklist(address account) public onlyOwner {
        require(account != address(0));
        blackList.push(account);
    }
    // ------------------------------------------------------------------------
    // Transfer the balance from token owner's account to `to` account
    // - Owner's account must have sufficient balance to transfer
    // - 0 value transfers are allowed
    // ------------------------------------------------------------------------
    function transfer(address to, uint tokens) public isNotLocked returns (bool success) {
        require(isBlacklisted(msg.sender) == false);
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Token owner can approve for `spender` to transferFrom(...) `tokens`
    // from the token owner's account
    //
    // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
    // recommends that there are no checks for the approval double-spend attack
    // as this should be implemented in user interfaces
    // ------------------------------------------------------------------------
    function approve(address spender, uint tokens) public returns (bool success) {
        require(isBlacklisted(msg.sender) == false);
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Transfer `tokens` from the `from` account to the `to` account
    //
    // The calling account must already have sufficient tokens approve(...)-d
    // for spending from the `from` account and
    // - From account must have sufficient balance to transfer
    // - Spender must have sufficient allowance to transfer
    // - 0 value transfers are allowed
    // ------------------------------------------------------------------------
    function transferFrom(address from, address to, uint tokens) public isNotLocked returns (bool success) {
        require(isBlacklisted(msg.sender) == false);
        balances[from] = safeSub(balances[from], tokens);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(from, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Returns the amount of tokens approved by the owner that can be
    // transferred to the spender's account
    // ------------------------------------------------------------------------
    function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }

    function () external payable {
        revert();
    }

    function _burn(address account, uint256 amount) internal {
        require(account != address(0));

        balances[account] = safeSub(balances[account], amount);
        _totalSupply = safeSub(_totalSupply, amount);
        emit Transfer(account, address(0), amount);
    }

    // ------------------------------------------------------------------------
    // DECREASE token supply
    // ------------------------------------------------------------------------
    function burn(uint amount) public {
        require(amount > 0);
        _burn(msg.sender, amount);
    }

    // ------------------------------------------------------------------------
    // DECREASE token supply
    // ------------------------------------------------------------------------
    function burnFrom(address from, uint amount) public {
        require(allowance(from, msg.sender) >= amount);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], amount);
        _burn(from, amount);
    }

    function tokenToVault(address to, uint amount, uint releaseTime) public onlyOwner {
        require(to != address(0x0));
        vaultAmount[to] = safeAdd(vaultAmount[to], amount);
        vaultReleaseTime[to] = releaseTime;
        _totalSupply = safeAdd(_totalSupply, amount);
        balances[address(this)] = safeAdd(balances[address(this)], amount);
        vaultList.push(to);
    }

    function releaseToken() public {
        require(vaultAmount[msg.sender] > 0);
        require(block.timestamp >= vaultReleaseTime[msg.sender]);
        require(balances[address(this)] >= vaultAmount[msg.sender]);

        balances[msg.sender] = safeAdd(balances[msg.sender], vaultAmount[msg.sender]);
        balances[address(this)] = safeSub(balances[address(this)], vaultAmount[msg.sender]);
        vaultAmount[msg.sender] = 0;
        _removeFromVault(msg.sender);
    }

    function releaseTokenTo(address to) public onlyOwner {
        require(vaultAmount[to] > 0);
        require(block.timestamp >= vaultReleaseTime[to]);
        require(balances[address(this)] >= vaultAmount[to]);

        balances[to] = safeAdd(balances[to], vaultAmount[to]);
        balances[address(this)] = safeSub(balances[address(this)], vaultAmount[to]);
        vaultAmount[to] = 0;
        _removeFromVault(to);
    }

    function _removeFromVault(address addr) internal {
        uint index;
        uint length = vaultList.length;
        for (index = 0; index < length; index++){
            if (vaultList[index] == addr) {
              break;
            }
        }

        /// There is no use-case for inexistent
        assert(index < length);
        /// Remove out of list and map
        if ( index + 1 != length ) {
            /// Move the last to the current
            vaultList[index] = vaultList[length - 1];
        }
        delete vaultList[length - 1];
        vaultList.length--;
        delete vaultReleaseTime[addr];
        delete vaultAmount[addr];
    }

    function getVaultAmountFrom(address from) public view onlyOwner returns (uint amount) {
        return vaultAmount[from];
    }

    function getVaultAmount() public view returns (uint amount) {
        return vaultAmount[msg.sender];
    }

    function getVaultReleaseTimeFrom(address from) public view onlyOwner returns (uint releaseTime) {
        return vaultReleaseTime[from];
    }

    function getVaultReleaseTime() public view returns (uint releaseTime) {
        return vaultReleaseTime[msg.sender];
    }

    function getVaultList() public view onlyOwner returns (address[] memory list) {
        return vaultList;
    }
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------