def namedb_get_all_blockstack_ops_at(db, block_id, offset=None, count=None):
    """
    Get the states that each name, namespace, and account record
    passed through in the given block.  Note that this only concerns
    operations written on-chain, for use in SNV and database verification
    (i.e. does not include implicit account debits and account vesting).

    Return the list of prior record states, ordered by vtxindex.
    """
    assert (count is None and offset is None) or (count is not None and offset is not None), 'Invalid arguments: expect both offset/count or neither offset/count'

    ret = []
    cur = db.cursor()

    # how many preorders at this block?
    offset_count_query, offset_count_args = namedb_offset_count_predicate(offset=offset, count=count)

    preorder_count_rows_query = "SELECT COUNT(*) FROM preorders WHERE block_number = ? ORDER BY vtxindex " + " " + offset_count_query + ";"
    preorder_count_rows_args = (block_id,) + offset_count_args

    # log.debug(namedb_format_query(preorder_count_rows_query, preorder_count_rows_args))

    num_preorders = namedb_select_count_rows(cur, preorder_count_rows_query, preorder_count_rows_args)

    # get preorders at this block
    offset_count_query, offset_count_args = namedb_offset_count_predicate(offset=offset, count=count)

    preorder_rows_query = "SELECT * FROM preorders WHERE block_number = ? " + " " + offset_count_query + ";"
    preorder_rows_args = (block_id,) + offset_count_args

    # log.debug(namedb_format_query(preorder_rows_query, preorder_rows_args))

    preorder_rows = namedb_query_execute(cur, preorder_rows_query, preorder_rows_args)

    cnt = 0
    for preorder in preorder_rows:
        preorder_rec = {}
        preorder_rec.update( preorder )
        
        ret.append( preorder_rec )
        cnt += 1

    log.debug("{} preorders created at {}".format(cnt, block_id))

    # don't return too many rows, and slide down the offset window
    if count is not None and offset is not None:
        offset = max(0, offset - num_preorders)
        count -= num_preorders
        if count <= 0:
            # done!
            return ret

    # get all other operations at this block (name ops, namespace ops, token ops)
    offset_count_query, offset_count_args = namedb_offset_count_predicate(offset=offset, count=count)
    query = "SELECT history_data FROM history WHERE block_id = ? ORDER BY vtxindex " + offset_count_query + ";"
    args = (block_id,) + offset_count_args

    # log.debug(namedb_format_query(query, args))

    rows_result = namedb_query_execute(cur, query, args)

    # extract rows
    cnt = 0
    for r in rows_result:
        history_data_str = r['history_data']

        try:
            history_data = json.loads(history_data_str)
        except Exception as e:
            log.exception(e)
            log.error("FATAL: corrupt JSON string '{}'".format(history_data_str))
            os.abort()

        ret.append(history_data)
        cnt += 1

    log.debug("{} non-preorder operations at {}".format(cnt, block_id))
    return ret
Get the states that each name, namespace, and account record
    passed through in the given block.  Note that this only concerns
    operations written on-chain, for use in SNV and database verification
    (i.e. does not include implicit account debits and account vesting).

    Return the list of prior record states, ordered by vtxindex.