code: def event_filter_for_payments(
          event: architecture.Event,
          token_network_identifier: TokenNetworkID = None,
          partner_address: Address = None,
  ) -> bool:
      
      is_matching_event = (
          isinstance(event, EVENTS_PAYMENT_HISTORY_RELATED) and
          (
              token_network_identifier is None or
              token_network_identifier == event.token_network_identifier
          )
      )
      if not is_matching_event:
          return False
  
      sent_and_target_matches = (
          isinstance(event, (EventPaymentSentFailed, EventPaymentSentSuccess)) and
          (
              partner_address is None or
              event.target == partner_address
          )
      )
      received_and_initiator_matches = (
          isinstance(event, EventPaymentReceivedSuccess) and
          (
              partner_address is None or
              event.initiator == partner_address
          )
      )
      return sent_and_target_matches or received_and_initiator_matches
docs: Filters out non payment history related events
  
      - If no other args are given, all payment related events match
      - If a token network identifier is given then only payment events for that match
      - If a partner is also given then if the event is a payment sent event and the
        target matches it's returned. If it's a payment received and the initiator matches
        then it's returned.