fix expiration handling (#32)

This commit is contained in:
Riccardo Balbo 2026-03-25 17:38:03 +01:00 • committed by GitHub
commit 08070257f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

13
nwcp.py
View file

@ -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")