<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def GET_names_owned_by_address( self, path_info, blockchain, address ):
 """ Get all names owned by an address Returns the list on success Return 404 on unsupported blockchain Return 502 on failure to get names for any non-specified reason """

        if not check_address(address):
            return self._reply_json({'error': 'Invalid address'}, status_code=400)

        if blockchain != 'bitcoin':
            return self._reply_json({'error': 'Unsupported blockchain'}, status_code=404)

        blockstackd_url = get_blockstackd_url()
        address = str(address)

        subdomain_names = blockstackd_client.get_subdomains_owned_by_address(address, hostport=blockstackd_url)
        if json_is_error(subdomain_names):
            log.error("Failed to fetch subdomains owned by address")
            log.error(subdomain_names)
            subdomain_names = []
        
        # make sure we have the right encoding
        new_addr = virtualchain.address_reencode(address)
        if new_addr != address:
            log.debug("Re-encode {} to {}".format(new_addr, address))
            address = new_addr
        
        res = blockstackd_client.get_names_owned_by_address(address, hostport=blockstackd_url)
        if json_is_error(res):
            log.error("Failed to get names owned by address")
            self._reply_json({'error': 'Failed to list names by address'}, status_code=res.get('http_status', 502))
            return

        self._reply_json({'names': res + subdomain_names})
        return