<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_subdomain_history(fqn, offset=None, count=None, reverse=False, db_path=None, zonefiles_dir=None, json=False):
 """ Static method for getting all historic operations on a subdomain """

    opts = get_blockstack_opts()
    if not is_subdomains_enabled(opts):
        return []

    if db_path is None:
        db_path = opts['subdomaindb_path']
    
    if zonefiles_dir is None:
        zonefiles_dir = opts['zonefiles']

    db = SubdomainDB(db_path, zonefiles_dir)
    recs = db.get_subdomain_history(fqn, offset=offset, count=count)

    if json:
        recs = [rec.to_json() for rec in recs]
        ret = {}
        for rec in recs:
            if rec['block_number'] not in ret:
                ret[rec['block_number']] = []

            ret[rec['block_number']].append(rec)

        if reverse:
            for block_height in ret:
                ret[block_height].sort(lambda r1, r2: -1 if r1['parent_zonefile_index'] > r2['parent_zonefile_index'] or 
                                                           (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] > r2['zonefile_offset']) else
                                                       1 if r1['parent_zonefile_index'] < r2['parent_zonefile_index'] or 
                                                           (r1['parent_zonefile_index'] == r2['parent_zonefile_index'] and r1['zonefile_offset'] < r2['zonefile_offset']) else
                                                       0)
        return ret

    else:
        return recs