@@ -89,39 +89,49 @@ async def _handle_subscriptions(self):
89
89
90
90
91
91
async def _handle_received_subscription_eosenotices (self , s ):
92
- s_original = self .original_subscription_ids [s ]
93
- event_to_forward = ["EOSE" , s_original ]
94
- del NostrRouter .received_subscription_eosenotices [s ]
95
-
96
- await self .websocket .send_text (json .dumps (event_to_forward ))
97
-
98
- async def _handle_received_subscription_events (self , s ):
99
- while len (NostrRouter .received_subscription_events [s ]):
100
- my_event = NostrRouter .received_subscription_events [s ].pop (0 )
101
- # event.to_message() does not include the subscription ID, we have to add it manually
102
- event_json = {
103
- "id" : my_event .id ,
104
- "pubkey" : my_event .public_key ,
105
- "created_at" : my_event .created_at ,
106
- "kind" : my_event .kind ,
107
- "tags" : my_event .tags ,
108
- "content" : my_event .content ,
109
- "sig" : my_event .signature ,
110
- }
111
-
112
- # this reconstructs the original response from the relay
113
- # reconstruct original subscription id
92
+ try :
93
+ if s not in self .original_subscription_ids :
94
+ return
114
95
s_original = self .original_subscription_ids [s ]
115
- event_to_forward = ["EVENT" , s_original , event_json ]
96
+ event_to_forward = ["EOSE" , s_original ]
97
+ del NostrRouter .received_subscription_eosenotices [s ]
98
+
116
99
await self .websocket .send_text (json .dumps (event_to_forward ))
100
+ except Exception as e :
101
+ logger .debug (e )
102
+
103
+ async def _handle_received_subscription_events (self , s ):
104
+ try :
105
+ if s not in NostrRouter .received_subscription_events :
106
+ return
107
+ while len (NostrRouter .received_subscription_events [s ]):
108
+ my_event = NostrRouter .received_subscription_events [s ].pop (0 )
109
+ # event.to_message() does not include the subscription ID, we have to add it manually
110
+ event_json = {
111
+ "id" : my_event .id ,
112
+ "pubkey" : my_event .public_key ,
113
+ "created_at" : my_event .created_at ,
114
+ "kind" : my_event .kind ,
115
+ "tags" : my_event .tags ,
116
+ "content" : my_event .content ,
117
+ "sig" : my_event .signature ,
118
+ }
119
+
120
+ # this reconstructs the original response from the relay
121
+ # reconstruct original subscription id
122
+ s_original = self .original_subscription_ids [s ]
123
+ event_to_forward = ["EVENT" , s_original , event_json ]
124
+ await self .websocket .send_text (json .dumps (event_to_forward ))
125
+ except Exception as e :
126
+ logger .debug (e )
117
127
118
128
def _handle_notices (self ):
119
129
while len (NostrRouter .received_subscription_notices ):
120
130
my_event = NostrRouter .received_subscription_notices .pop (0 )
121
131
# note: we don't send it to the user because we don't know who should receive it
122
132
logger .info (f"Relay ('{ my_event .url } ') notice: '{ my_event .content } ']" )
123
133
nostr .client .relay_manager .handle_notice (my_event )
124
-
134
+
125
135
126
136
127
137
def _marshall_nostr_filters (self , data : Union [dict , list ]):
0 commit comments