# Buggy code
def is_valid_tx(tx):
    """
    Verify whether a dictionary that contains a transaction, is valid.
    """
    required_fields = [
        "trader_id",
        "order_number",
        "partner_trader_id",
        "partner_order_number",
        "transaction_number",
        "assets",
        "transferred",
        "timestamp",
        "payment_complete",
        "status",
    ]
    if not MarketBlock.has_fields(required_fields, tx):
        return False
    if len(tx) != len(required_fields):
        return False

    required_types = [
        ("trader_id", str),
        ("order_number", int),
        ("partner_trader_id", str),
        ("partner_order_number", int),
        ("transaction_number", int),
        ("assets", dict),
        ("transferred", dict),
        ("timestamp", float),
        ("payment_complete", bool),
        ("status", str),
    ]

    if not MarketBlock.is_valid_trader_id(
        tx["trader_id"]
    ) or not MarketBlock.is_valid_trader_id(tx["partner_trader_id"]):
        return False
    if not MarketBlock.is_valid_asset_pair(tx["assets"]):
        return False
    if not MarketBlock.is_valid_asset_pair(tx["transferred"]):
        return False
    if not MarketBlock.has_required_types(required_types, tx):
        return False

    return True


# Traceback (ZeroDivisionError)
Traceback (most recent call last):
File "/Users/martijndevos/Documents/tribler/TriblerGUI/widgets/marketpage.py", line 322, in <lambda>
lambda _, id1=first_wallet_id, id2=second_wallet_id: self.on_asset_type_changed(id1, id2))
File "/Users/martijndevos/Documents/tribler/TriblerGUI/widgets/marketpage.py", line 333, in on_asset_type_changed
self.update_filter_bids_list()
File "/Users/martijndevos/Documents/tribler/TriblerGUI/widgets/marketpage.py", line 193, in update_filter_bids_list
self.create_widget_item_from_tick(self.window().bids_list, bid, is_ask=False))
File "/Users/martijndevos/Documents/tribler/TriblerGUI/widgets/marketpage.py", line 143, in create_widget_item_from_tick
return TickWidgetItem(tick_list, tick, asset1_prec, asset2_prec)
File "/Users/martijndevos/Documents/tribler/TriblerGUI/widgets/tickwidgetitem.py", line 17, in __init__
self.price = float(self.total_volume) / float(prec_div(tick["assets"]["second"]["amount"], asset2_prec))
ZeroDivisionError: float division by zero

# Fixed code
def is_valid_tx(tx):
    """
    Verify whether a dictionary that contains a transaction, is valid.
    """
    required_fields = [
        "trader_id",
        "order_number",
        "partner_trader_id",
        "partner_order_number",
        "transaction_number",
        "assets",
        "transferred",
        "timestamp",
        "payment_complete",
        "status",
    ]
    if not MarketBlock.has_fields(required_fields, tx):
        return False
    if len(tx) != len(required_fields):
        return False

    required_types = [
        ("trader_id", str),
        ("order_number", int),
        ("partner_trader_id", str),
        ("partner_order_number", int),
        ("transaction_number", int),
        ("assets", dict),
        ("transferred", dict),
        ("timestamp", float),
        ("payment_complete", bool),
        ("status", str),
    ]

    if not MarketBlock.is_valid_trader_id(
        tx["trader_id"]
    ) or not MarketBlock.is_valid_trader_id(tx["partner_trader_id"]):
        return False
    if not MarketBlock.is_valid_asset_pair(tx["assets"]):
        return False
    if not MarketBlock.is_valid_asset_pair(tx["transferred"], amount_positive=False):
        return False
    if not MarketBlock.has_required_types(required_types, tx):
        return False

    return True