contract MESH is StandardToken {

    function () public {
        revert();
    }

    string public name = "MeshBox";                   //fancy name
    uint8 public decimals = 18;                //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
    string public symbol = "MESH";                 //An identifier
    string public version = 'v0.1';       //MESH 0.1 standard. Just an arbitrary versioning scheme.
    uint256 public allocateEndTime;

    
    // The nonce for avoid transfer replay attacks
    mapping(address => uint256) nonces;

    constructor() public {
        allocateEndTime = now + 1 days;
    }

    /*
     * Proxy transfer MESH. When some users of the ethereum account has no ether,
     * he or she can authorize the agent for broadcast transactions, and agents may charge agency fees
     * @param _from
     * @param _to
     * @param _value
     * @param feeMesh
     * @param _v
     * @param _r
     * @param _s
     */
    function transferProxy(address _from, address _to, uint256 _value, uint256 _feeMesh,
        uint8 _v,bytes32 _r, bytes32 _s) public transferAllowed(_from) returns (bool){

        if(balances[_from] < _feeMesh + _value 
            || _feeMesh > _feeMesh + _value) revert();

        uint256 nonce = nonces[_from];
        bytes32 h = keccak256(_from,_to,_value,_feeMesh,nonce,address(this));
        if(_from != ecrecover(h,_v,_r,_s)) revert();

        if(balances[_to] + _value < balances[_to]
            || balances[msg.sender] + _feeMesh < balances[msg.sender]) revert();
        balances[_to] += _value;
        emit Transfer(_from, _to, _value);

        balances[msg.sender] += _feeMesh;
        emit Transfer(_from, msg.sender, _feeMesh);

        balances[_from] -= _value + _feeMesh;
        nonces[_from] = nonce + 1;
        return true;
    }

    /*
     * Proxy approve that some one can authorize the agent for broadcast transaction
     * which call approve method, and agents may charge agency fees
     * @param _from The address which should tranfer MESH to others
     * @param _spender The spender who allowed by _from
     * @param _value The value that should be tranfered.
     * @param _v
     * @param _r
     * @param _s
     */
    function approveProxy(address _from, address _spender, uint256 _value,
        uint8 _v,bytes32 _r, bytes32 _s) public returns (bool success) {

        uint256 nonce = nonces[_from];
        bytes32 hash = keccak256(_from,_spender,_value,nonce,address(this));
        if(_from != ecrecover(hash,_v,_r,_s)) revert();
        allowed[_from][_spender] = _value;
        emit Approval(_from, _spender, _value);
        nonces[_from] = nonce + 1;
        return true;
    }

    /*
     * Get the nonce
     * @param _addr
     */
    function getNonce(address _addr) public constant returns (uint256){
        return nonces[_addr];
    }

    // Allocate tokens to the users
    // @param _owners The owners list of the token
    // @param _values The value list of the token
    function allocateTokens(address[] _owners, uint256[] _values) public onlyOwner {

        if(allocateEndTime < now) revert();
        if(_owners.length != _values.length) revert();

        for(uint256 i = 0; i < _owners.length ; i++){
            address to = _owners[i];
            uint256 value = _values[i];
            if(totalSupply + value <= totalSupply || balances[to] + value <= balances[to]) revert();
            totalSupply += value;
            balances[to] += value;
        }
    }
}
function approveProxy(address _from, address _spender, uint256 _value,
    uint8 _v,bytes32 _r, bytes32 _s) public returns (bool success) {

    uint256 nonce = nonces[_from];
    bytes32 hash = keccak256(_from,_spender,_value,nonce,address(this));
    if(_from != ecrecover(hash,_v,_r,_s)) revert();
    allowed[_from][_spender] = _value;
    emit Approval(_from, _spender, _value);
    nonces[_from] = nonce + 1;
    return true;
}

/*
 * Proxy approve that some one can authorize the agent for broadcast transaction
 * which call approve method, and agents may charge agency fees
 * @param _from The address which should tranfer MESH to others
 * @param _spender The spender who allowed by _from
 * @param _value The value that should be tranfered.
 * @param _v
 * @param _r
 * @param _s
 */