<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_DID_name(self, did):
 """ Given a DID, get the name Return None if not found, or if the name was revoked Raise if the DID is invalid """

        did = str(did)
        did_info = None
        try:
            did_info = parse_DID(did)
            assert did_info['name_type'] == 'name'
        except Exception as e:
            if BLOCKSTACK_DEBUG:
                log.exception(e)

            raise ValueError("Invalid DID: {}".format(did))

        cur = self.db.cursor()
        historic_name_info = namedb_get_historic_names_by_address(cur, did_info['address'], offset=did_info['index'], count=1)
        if historic_name_info is None:
            # no such name
            return None

        name = historic_name_info[0]['name']
        block_height = historic_name_info[0]['block_id']
        vtxindex = historic_name_info[0]['vtxindex']
                    
        log.debug("DID {} refers to {}-{}-{}".format(did, name, block_height, vtxindex))

        name_rec = self.get_name(name, include_history=True, include_expired=True)
        if name_rec is None:
            # dead
            return None

        name_rec_latest = None
        found = False

        for height in sorted(name_rec['history'].keys()):
            if found:
                break

            if height < block_height:
                continue

            for state in name_rec['history'][height]:
                if height == block_height and state['vtxindex'] < vtxindex:
                    # too soon
                    continue

                if state['op'] == NAME_PREORDER:
                    # looped to the next iteration of this name
                    found = True
                    break

                if state['revoked']:
                    # revoked
                    log.debug("DID {} refers to {}-{}-{}, which is revoked at {}-{}".format(did, name, block_height, vtxindex, height, state['vtxindex']))
                    return None

                name_rec_latest = state

        return name_rec_latest