def _merge_block(internal_transactions, transactions, whitelist):
    """
    Merge responses with trace and chain transactions. Remove non-whitelisted fields

    Parameters
    ----------
    internal_transactions : list
        List of trace transactions
    transactions : list
        List of chain transactions
    whitelist : list
        List of allowed fields

    Returns
    -------
    list
        List of trace transactions extended with whitelisted fields from related chain transactions
    """
    transactions_by_id = {
        (transaction["hash"], transaction["blockHash"]): transaction
        for transaction in transactions
    }
    for transaction in internal_transactions:
        hash = transaction["transactionHash"]
        block = transaction["blockHash"]
        if (hash, block) in transactions_by_id:
            whitelisted_fields = {
                key: value
                for key, value in transactions_by_id[(hash, block)].items()
                if key in whitelist
            }
            transaction.update(whitelisted_fields)
            del transactions_by_id[(hash, block)]
    return internal_transactions