From 08070257f84a80db6af84a117d1e3798b6fb9348 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Wed, 25 Mar 2026 17:38:03 +0100 Subject: [PATCH] fix expiration handling (#32) --- nwcp.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nwcp.py b/nwcp.py index cfa7f82..9e45622 100644 --- a/nwcp.py +++ b/nwcp.py @@ -378,6 +378,17 @@ class NWCServiceProvider: sent_events.append(res) return sent_events + def _extract_expiration_from_tags(self, tags: list) -> int: + expiration = -1 + for tag in tags: + try: + if tag[0] == "expiration" and len(tag) > 1: + expiration = int(tag[1]) + break + except Exception: + pass + return expiration + async def _on_event_message(self, msg): if not self.sub: return @@ -387,7 +398,7 @@ class NWCServiceProvider: if not self._verify_event(event): raise Exception("Invalid event signature") tags = event["tags"] - expiration = int(next((tag for tag in tags if tag[0] == "expiration"), -1)) + expiration = self._extract_expiration_from_tags(tags) # Handle event expiration if the relay doesn't support nip 40 if expiration > 0 and expiration < int(time.time()): logger.debug("Event expired")