def get_request_by_addr(self, addr: str) -> Optional[Request]:
        """Returns a relevant request for address, from an on-chain PoV.
        (One that has been paid on-chain or is pending)

        Called in get_label_for_address and update_invoices_and_reqs_touched_by_tx
        Returns None if the address can be reused (i.e. was paid by lightning or has expired)
        """
        keys = self._requests_addr_to_key.get(addr) or []
        reqs = [self._receive_requests.get(key) for key in keys]
        reqs = [req for req in reqs if req]  # filter None
        if not reqs:
            return
        # filter out expired
        reqs = [req for req in reqs if self.get_invoice_status(req) != PR_EXPIRED]
        # filter out paid-with-lightning
        if self.lnworker:
            reqs = [req for req in reqs
                    if not req.is_lightning() or self.lnworker.get_invoice_status(req) == PR_UNPAID]
        if not reqs:
            return None
        # note: There typically should not be more than one relevant request for an address.
        #       If there's multiple, return the one created last (see #8113). Consider:
        #       - there is an old expired req1, and a newer unpaid req2, reusing the same addr (and same amount),
        #       - now req2 gets paid. however, get_invoice_status will say both req1 and req2 are PAID. (see #8061)
        #       - as a workaround, we return the request with the larger creation time.
        reqs.sort(key=lambda req: req.get_time())
        return reqs[-1]
Returns a relevant request for address, from an on-chain PoV.
        (One that has been paid on-chain or is pending)

        Called in get_label_for_address and update_invoices_and_reqs_touched_by_tx
        Returns None if the address can be reused (i.e. was paid by lightning or has expired)
        
electrum/wallet.py