diff --git a/lightningd/notification.c b/lightningd/notification.c index d307ddaa7..365dd0148 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -5,7 +5,6 @@ #include const char *notification_topics[] = { - "invoice_payment", "channel_opened", "forward_event" }; @@ -119,17 +118,33 @@ void notify_warning(struct lightningd *ld, struct log_entry *l) plugins_notify(ld->plugins, take(n)); } +static void invoice_payment_notification_serialize(struct json_stream *stream, + struct amount_msat amount, + struct preimage preimage, + const struct json_escape *label) +{ + json_object_start(stream, "invoice_payment"); + json_add_string(stream, "msat", + type_to_string(tmpctx, struct amount_msat, &amount)); + json_add_hex(stream, "preimage", &preimage, sizeof(preimage)); + json_add_escaped_string(stream, "label", label); + json_object_end(stream); +} + +REGISTER_NOTIFICATION(invoice_payment, + invoice_payment_notification_serialize) + void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount, struct preimage preimage, const struct json_escape *label) { - struct jsonrpc_notification *n = - jsonrpc_notification_start(NULL, "invoice_payment"); - json_object_start(n->stream, "invoice_payment"); - json_add_string(n->stream, "msat", - type_to_string(tmpctx, struct amount_msat, &amount)); - json_add_hex(n->stream, "preimage", &preimage, sizeof(preimage)); - json_add_escaped_string(n->stream, "label", label); - json_object_end(n->stream); + void (*serialize)(struct json_stream *, + struct amount_msat, + struct preimage, + const struct json_escape *) = invoice_payment_notification_gen.serialize; + + struct jsonrpc_notification *n + = jsonrpc_notification_start(NULL, invoice_payment_notification_gen.topic); + serialize(n->stream, amount, preimage, label); jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); }