@@ -38,10 +38,15 @@ bool notifications_have_topic(const struct plugins *plugins, const char *topic)
38
38
}
39
39
40
40
/* Modern notifications X contain an object X */
41
- static struct jsonrpc_notification * notify_start (const char * name )
41
+ static struct jsonrpc_notification * notify_start (struct lightningd * ld ,
42
+ const char * name )
42
43
{
43
44
struct jsonrpc_notification * n ;
44
45
46
+ /* Optimization: does anyone care? */
47
+ if (!plugins_anyone_cares (ld -> plugins , name ))
48
+ return NULL ;
49
+
45
50
n = jsonrpc_notification_start (NULL , name );
46
51
json_object_start (n -> stream , name );
47
52
return n ;
@@ -71,7 +76,9 @@ void notify_connect(struct lightningd *ld,
71
76
bool incoming ,
72
77
const struct wireaddr_internal * addr )
73
78
{
74
- struct jsonrpc_notification * n = notify_start ("connect" );
79
+ struct jsonrpc_notification * n = notify_start (ld , "connect" );
80
+ if (!n )
81
+ return ;
75
82
connect_notification_serialize (n -> stream , nodeid , incoming , addr );
76
83
notify_send (ld , n );
77
84
}
@@ -85,7 +92,9 @@ REGISTER_NOTIFICATION(disconnect);
85
92
86
93
void notify_disconnect (struct lightningd * ld , struct node_id * nodeid )
87
94
{
88
- struct jsonrpc_notification * n = notify_start ("disconnect" );
95
+ struct jsonrpc_notification * n = notify_start (ld , "disconnect" );
96
+ if (!n )
97
+ return ;
89
98
disconnect_notification_serialize (n -> stream , nodeid );
90
99
notify_send (ld , n );
91
100
}
@@ -114,7 +123,9 @@ REGISTER_NOTIFICATION(warning);
114
123
115
124
void notify_warning (struct lightningd * ld , struct log_entry * l )
116
125
{
117
- struct jsonrpc_notification * n = notify_start ("warning" );
126
+ struct jsonrpc_notification * n = notify_start (ld , "warning" );
127
+ if (!n )
128
+ return ;
118
129
warning_notification_serialize (n -> stream , l );
119
130
notify_send (ld , n );
120
131
}
@@ -133,7 +144,9 @@ void notify_custommsg(struct lightningd *ld,
133
144
const struct node_id * peer_id ,
134
145
const u8 * msg )
135
146
{
136
- struct jsonrpc_notification * n = notify_start ("custommsg" );
147
+ struct jsonrpc_notification * n = notify_start (ld , "custommsg" );
148
+ if (!n )
149
+ return ;
137
150
custommsg_notification_serialize (n -> stream , peer_id , msg );
138
151
notify_send (ld , n );
139
152
}
@@ -167,7 +180,9 @@ void notify_onionmessage_forward_fail(struct lightningd *ld,
167
180
const u8 * outgoing ,
168
181
const struct sciddir_or_pubkey * next_node )
169
182
{
170
- struct jsonrpc_notification * n = notify_start ("onionmessage_forward_fail" );
183
+ struct jsonrpc_notification * n = notify_start (ld , "onionmessage_forward_fail" );
184
+ if (!n )
185
+ return ;
171
186
onionmessage_forward_fail_serialize (n -> stream ,
172
187
source ,
173
188
incoming ,
@@ -198,7 +213,9 @@ void notify_invoice_payment(struct lightningd *ld,
198
213
const struct json_escape * label ,
199
214
const struct bitcoin_outpoint * outpoint )
200
215
{
201
- struct jsonrpc_notification * n = notify_start ("invoice_payment" );
216
+ struct jsonrpc_notification * n = notify_start (ld , "invoice_payment" );
217
+ if (!n )
218
+ return ;
202
219
invoice_payment_notification_serialize (n -> stream , amount , preimage , label , outpoint );
203
220
notify_send (ld , n );
204
221
}
@@ -222,7 +239,9 @@ void notify_invoice_creation(struct lightningd *ld,
222
239
const struct preimage * preimage ,
223
240
const struct json_escape * label )
224
241
{
225
- struct jsonrpc_notification * n = notify_start ("invoice_creation" );
242
+ struct jsonrpc_notification * n = notify_start (ld , "invoice_creation" );
243
+ if (!n )
244
+ return ;
226
245
invoice_creation_notification_serialize (n -> stream , amount , preimage , label );
227
246
notify_send (ld , n );
228
247
}
@@ -249,7 +268,9 @@ void notify_channel_opened(struct lightningd *ld,
249
268
const struct bitcoin_txid * funding_txid ,
250
269
bool channel_ready )
251
270
{
252
- struct jsonrpc_notification * n = notify_start ("channel_opened" );
271
+ struct jsonrpc_notification * n = notify_start (ld , "channel_opened" );
272
+ if (!n )
273
+ return ;
253
274
channel_opened_notification_serialize (n -> stream , ld , node_id , funding_sat , funding_txid , channel_ready );
254
275
notify_send (ld , n );
255
276
}
@@ -292,7 +313,9 @@ void notify_channel_state_changed(struct lightningd *ld,
292
313
enum state_change cause ,
293
314
const char * message )
294
315
{
295
- struct jsonrpc_notification * n = notify_start ("channel_state_changed" );
316
+ struct jsonrpc_notification * n = notify_start (ld , "channel_state_changed" );
317
+ if (!n )
318
+ return ;
296
319
channel_state_changed_notification_serialize (n -> stream , peer_id , cid , scid , timestamp , old_state , new_state , cause , message );
297
320
notify_send (ld , n );
298
321
}
@@ -361,7 +384,9 @@ void notify_forward_event(struct lightningd *ld,
361
384
u64 created_index ,
362
385
u64 updated_index )
363
386
{
364
- struct jsonrpc_notification * n = notify_start ("forward_event" );
387
+ struct jsonrpc_notification * n = notify_start (ld , "forward_event" );
388
+ if (!n )
389
+ return ;
365
390
forward_event_notification_serialize (n -> stream , in , scid_out , amount_out , state , failcode , resolved_time , forward_style , created_index , updated_index );
366
391
notify_send (ld , n );
367
392
}
@@ -371,7 +396,9 @@ REGISTER_NOTIFICATION(sendpay_success);
371
396
void notify_sendpay_success (struct lightningd * ld ,
372
397
const struct wallet_payment * payment )
373
398
{
374
- struct jsonrpc_notification * n = notify_start ("sendpay_success" );
399
+ struct jsonrpc_notification * n = notify_start (ld , "sendpay_success" );
400
+ if (!n )
401
+ return ;
375
402
json_add_payment_fields (n -> stream , payment );
376
403
notify_send (ld , n );
377
404
}
@@ -407,7 +434,9 @@ void notify_sendpay_failure(struct lightningd *ld,
407
434
const struct routing_failure * fail ,
408
435
const char * errmsg )
409
436
{
410
- struct jsonrpc_notification * n = notify_start ("sendpay_failure" );
437
+ struct jsonrpc_notification * n = notify_start (ld , "sendpay_failure" );
438
+ if (!n )
439
+ return ;
411
440
sendpay_failure_notification_serialize (n -> stream , payment , pay_errcode , onionreply , fail , errmsg );
412
441
notify_send (ld , n );
413
442
}
@@ -492,7 +521,9 @@ REGISTER_NOTIFICATION(coin_movement);
492
521
void notify_coin_mvt (struct lightningd * ld ,
493
522
const struct coin_mvt * mvt )
494
523
{
495
- struct jsonrpc_notification * n = notify_start ("coin_movement" );
524
+ struct jsonrpc_notification * n = notify_start (ld , "coin_movement" );
525
+ if (!n )
526
+ return ;
496
527
coin_movement_notification_serialize (n -> stream , mvt );
497
528
notify_send (ld , n );
498
529
}
@@ -522,7 +553,9 @@ REGISTER_NOTIFICATION(balance_snapshot);
522
553
void notify_balance_snapshot (struct lightningd * ld ,
523
554
const struct balance_snapshot * snap )
524
555
{
525
- struct jsonrpc_notification * n = notify_start ("balance_snapshot" );
556
+ struct jsonrpc_notification * n = notify_start (ld , "balance_snapshot" );
557
+ if (!n )
558
+ return ;
526
559
balance_snapshot_serialize (n -> stream , snap );
527
560
notify_send (ld , n );
528
561
}
@@ -539,7 +572,9 @@ REGISTER_NOTIFICATION(block_added);
539
572
void notify_block_added (struct lightningd * ld ,
540
573
const struct block * block )
541
574
{
542
- struct jsonrpc_notification * n = notify_start ("block_added" );
575
+ struct jsonrpc_notification * n = notify_start (ld , "block_added" );
576
+ if (!n )
577
+ return ;
543
578
block_added_notification_serialize (n -> stream , block );
544
579
notify_send (ld , n );
545
580
}
@@ -558,7 +593,9 @@ void notify_openchannel_peer_sigs(struct lightningd *ld,
558
593
const struct channel_id * cid ,
559
594
const struct wally_psbt * psbt )
560
595
{
561
- struct jsonrpc_notification * n = notify_start ("openchannel_peer_sigs" );
596
+ struct jsonrpc_notification * n = notify_start (ld , "openchannel_peer_sigs" );
597
+ if (!n )
598
+ return ;
562
599
openchannel_peer_sigs_serialize (n -> stream , cid , psbt );
563
600
notify_send (ld , n );
564
601
}
@@ -574,7 +611,9 @@ REGISTER_NOTIFICATION(channel_open_failed);
574
611
void notify_channel_open_failed (struct lightningd * ld ,
575
612
const struct channel_id * cid )
576
613
{
577
- struct jsonrpc_notification * n = notify_start ("channel_open_failed" );
614
+ struct jsonrpc_notification * n = notify_start (ld , "channel_open_failed" );
615
+ if (!n )
616
+ return ;
578
617
channel_open_failed_serialize (n -> stream , cid );
579
618
notify_send (ld , n );
580
619
}
@@ -583,7 +622,9 @@ REGISTER_NOTIFICATION(shutdown);
583
622
584
623
bool notify_plugin_shutdown (struct lightningd * ld , struct plugin * p )
585
624
{
586
- struct jsonrpc_notification * n = notify_start ("shutdown" );
625
+ struct jsonrpc_notification * n = notify_start (ld , "shutdown" );
626
+ if (!n )
627
+ return false;
587
628
json_object_end (n -> stream );
588
629
jsonrpc_notification_end (n );
589
630
return plugin_single_notify (p , take (n ));
@@ -593,7 +634,9 @@ bool notify_deprecated_oneshot(struct lightningd *ld,
593
634
struct plugin * p ,
594
635
bool deprecated_ok )
595
636
{
596
- struct jsonrpc_notification * n = notify_start ("deprecated_oneshot" );
637
+ struct jsonrpc_notification * n = notify_start (ld , "deprecated_oneshot" );
638
+ if (!n )
639
+ return false;
597
640
json_add_bool (n -> stream , "deprecated_ok" , deprecated_ok );
598
641
json_object_end (n -> stream );
599
642
jsonrpc_notification_end (n );
@@ -616,7 +659,11 @@ REGISTER_NOTIFICATION(log);
616
659
617
660
void notify_log (struct lightningd * ld , const struct log_entry * l )
618
661
{
619
- struct jsonrpc_notification * n = notify_start ("log" );
662
+ struct jsonrpc_notification * n ;
663
+
664
+ n = notify_start (ld , "log" );
665
+ if (!n )
666
+ return ;
620
667
log_notification_serialize (n -> stream , l );
621
668
notify_send (ld , n );
622
669
}
@@ -637,7 +684,9 @@ REGISTER_NOTIFICATION(plugin_started);
637
684
638
685
void notify_plugin_started (struct lightningd * ld , struct plugin * plugin )
639
686
{
640
- struct jsonrpc_notification * n = notify_start ("plugin_started" );
687
+ struct jsonrpc_notification * n = notify_start (ld , "plugin_started" );
688
+ if (!n )
689
+ return ;
641
690
plugin_notification_serialize (n -> stream , plugin );
642
691
notify_send (ld , n );
643
692
}
@@ -646,7 +695,9 @@ REGISTER_NOTIFICATION(plugin_stopped);
646
695
647
696
void notify_plugin_stopped (struct lightningd * ld , struct plugin * plugin )
648
697
{
649
- struct jsonrpc_notification * n = notify_start ("plugin_stopped" );
698
+ struct jsonrpc_notification * n = notify_start (ld , "plugin_stopped" );
699
+ if (!n )
700
+ return ;
650
701
plugin_notification_serialize (n -> stream , plugin );
651
702
notify_send (ld , n );
652
703
}
0 commit comments