Get the state(s) that a given account was in at a given block height
    Normally this is one state if nothing happened in this block.
    Otherwise, this is one or more states.

    Returns an array of states

def namedb_get_account_at(cur, address, block_number):
    """
    Get the state(s) that a given account was in at a given block height
    Normally this is one state if nothing happened in this block.
    Otherwise, this is one or more states.

    Returns an array of states
    """
    query = 'SELECT * FROM accounts WHERE address = ? AND block_id = ? ORDER BY block_id DESC, vtxindex DESC'
    args = (address, block_number)
    history_rows = namedb_query_execute(cur, query, args)
    ret = []

    for row in history_rows:
        tmp = {}
        tmp.update(row)
        ret.append(tmp)

    if len(ret) > 0:
        # account changed in this block
        return ret
    
    # if the account did not change in this block, then find the latest version of this account at this block
    query = 'SELECT * from accounts WHERE address = ? AND block_id < ? ORDER BY block_id DESC,vtxindex DESC LIMIT 1'
    args = (address, block_number)
    history_rows = namedb_query_execute(cur, query, args)

    for row in history_rows:
        tmp = {}
        tmp.update(row)
        ret.append(tmp)

    return ret