Resolve a Blockstack decentralized identifier (DID) to its blockchain record.
    Works for names and subdomains.

    DID format: did:stack:v0:${address}-${name_index}, where:
    * address is the address that created the name this DID references (version byte 0 or 5)
    * name_index is the nth name ever created by this address.

    Returns the blockchain record on success
    Returns {'error': ...} on failure

def get_DID_record(did, proxy=None, hostport=None):
    """
    Resolve a Blockstack decentralized identifier (DID) to its blockchain record.
    Works for names and subdomains.

    DID format: did:stack:v0:${address}-${name_index}, where:
    * address is the address that created the name this DID references (version byte 0 or 5)
    * name_index is the nth name ever created by this address.

    Returns the blockchain record on success
    Returns {'error': ...} on failure
    """
    assert proxy or hostport, 'Need proxy or hostport'
    if proxy is None:
        proxy = connect_hostport(hostport)
 
    # what do we expect?
    required = None
    is_blockstack_id = False
    is_blockstack_subdomain = False

    did_info = parse_DID(did)
    if did_info['name_type'] == 'name':
        # full name
        required = NAMEOP_SCHEMA_REQUIRED[:]
        is_blockstack_id = True
        
    elif did_info['name_type'] == 'subdomain':
        # subdomain 
        required = SUBDOMAIN_SCHEMA_REQUIRED[:]
        is_blockstack_subdomain = True

    else:
        # invalid
        raise ValueError("Not a valid name or subdomain DID: {}".format(did))
        
    nameop_schema = {
        'type': 'object',
        'properties': NAMEOP_SCHEMA_PROPERTIES,
        'required': required
    }

    rec_schema = {
        'type': 'object',
        'properties': {
            'record': nameop_schema,
        },
        'required': [
            'record'
        ],
    }

    resp_schema = json_response_schema(rec_schema)
    resp = {}

    try:
        resp = proxy.get_DID_record(did)
        resp = json_validate(resp_schema, resp)
        if json_is_error(resp):
            return resp

    except ValidationError as e:
        if BLOCKSTACK_DEBUG:
            log.exception(e)

        resp = {'error': 'Server response did not match expected schema.  You are likely communicating with an out-of-date Blockstack node.', 'http_status': 502}
        return resp

    except socket.timeout:
        log.error("Connection timed out")
        resp = {'error': 'Connection to remote host timed out.', 'http_status': 503}
        return resp

    except socket.error as se:
        log.error("Connection error {}".format(se.errno))
        resp = {'error': 'Connection to remote host failed.', 'http_status': 502}
        return resp

    except Exception as ee:
        if BLOCKSTACK_DEBUG:
            log.exception(ee)

        log.error("Caught exception while connecting to Blockstack node: {}".format(ee))
        resp = {'error': 'Failed to contact Blockstack node.  Try again with `--debug`.', 'http_status': 500}
        return resp

    final_name_state = resp['record']

    # remove extra fields that shouldn't be present
    for extra_field in ['expired', 'expire_block', 'renewal_deadline']:
        if extra_field in final_name_state:
            del final_name_state[extra_field]

    return final_name_state