diff --git a/lightningd/notification.c b/lightningd/notification.c index 3efcf99a2..f17750287 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -4,10 +4,6 @@ #include #include -const char *notification_topics[] = { - "forward_event" -}; - static struct notification *find_notification_by_topic(const char* topic) { static struct notification **notilist = NULL; @@ -27,10 +23,6 @@ bool notifications_have_topic(const char *topic) if (noti) return true; - /* TODO: Remove this block after making all notifications registered. */ - for (size_t i=0; iplugins, take(n)); } -void notify_forward_event(struct lightningd *ld, - const struct htlc_in *in, - const struct htlc_out *out, - enum forward_status state, - enum onion_type failcode, - struct timeabs *resolved_time) +static void forward_event_notification_serialize(struct json_stream *stream, + const struct htlc_in *in, + const struct htlc_out *out, + enum forward_status state, + enum onion_type failcode, + struct timeabs *resolved_time) { - struct jsonrpc_notification *n = - jsonrpc_notification_start(NULL, "forward_event"); /* Here is more neat to initial a forwarding structure than * to pass in a bunch of parameters directly*/ struct forwarding *cur = tal(tmpctx, struct forwarding); @@ -211,8 +201,29 @@ void notify_forward_event(struct lightningd *ld, cur->received_time = in->received_time; cur->resolved_time = tal_steal(cur, resolved_time); - json_format_forwarding_object(n->stream, "forward_event", cur); + json_format_forwarding_object(stream, "forward_event", cur); +} +REGISTER_NOTIFICATION(forward_event, + forward_event_notification_serialize); + +void notify_forward_event(struct lightningd *ld, + const struct htlc_in *in, + const struct htlc_out *out, + enum forward_status state, + enum onion_type failcode, + struct timeabs *resolved_time) +{ + void (*serialize)(struct json_stream *, + const struct htlc_in *, + const struct htlc_out *, + enum forward_status, + enum onion_type, + struct timeabs *) = forward_event_notification_gen.serialize; + + struct jsonrpc_notification *n + = jsonrpc_notification_start(NULL, forward_event_notification_gen.topic); + serialize(n->stream, in, out, state, failcode, resolved_time); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } diff --git a/lightningd/peer_htlcs.h b/lightningd/peer_htlcs.h index 0d54b8cad..fdf0b4e47 100644 --- a/lightningd/peer_htlcs.h +++ b/lightningd/peer_htlcs.h @@ -73,8 +73,9 @@ void htlcs_resubmit(struct lightningd *ld, struct htlc_in_map *unprocessed); void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage); void fail_htlc(struct htlc_in *hin, enum onion_type failcode); -/* This json process will be both used in 'notify_forward_event()' - * and 'listforwardings_add_forwardings()'*/ +/* This json process will be used as the serialize method for + * forward_event_notification_gen and be used in + * `listforwardings_add_forwardings()`. */ void json_format_forwarding_object(struct json_stream *response, const char *fieldname, const struct forwarding *cur); #endif /* LIGHTNING_LIGHTNINGD_PEER_HTLCS_H */