diff --git a/lightningd/notification.c b/lightningd/notification.c index f2a6dcb1f..55de51e9c 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -6,7 +6,8 @@ const char *notification_topics[] = { "connect", "disconnect", "warning", - "invoice_payment" + "invoice_payment", + "channel_opened" }; bool notifications_have_topic(const char *topic) @@ -76,3 +77,19 @@ void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount, jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } + +void notify_channel_opened(struct lightningd *ld, struct node_id *node_id, + struct amount_sat *funding_sat, struct bitcoin_txid *funding_txid, + bool *funding_locked) +{ + struct jsonrpc_notification *n = + jsonrpc_notification_start(NULL, "channel_opened"); + json_object_start(n->stream, "channel_opened"); + json_add_node_id(n->stream, "id", node_id); + json_add_amount_sat_only(n->stream, "amount", *funding_sat); + json_add_txid(n->stream, "funding_txid", funding_txid); + json_add_bool(n->stream, "funding_locked", funding_locked); + json_object_end(n->stream); + jsonrpc_notification_end(n); + plugins_notify(ld->plugins, take(n)); +} diff --git a/lightningd/notification.h b/lightningd/notification.h index 9d1c46304..8d4c23870 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -1,8 +1,11 @@ #ifndef LIGHTNING_LIGHTNINGD_NOTIFICATION_H #define LIGHTNING_LIGHTNINGD_NOTIFICATION_H #include "config.h" +#include +#include #include #include +#include #include #include #include @@ -19,4 +22,8 @@ void notify_warning(struct lightningd *ld, struct log_entry *l); void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount, struct preimage preimage, const struct json_escape *label); +void notify_channel_opened(struct lightningd *ld, struct node_id *node_id, + struct amount_sat *funding_sat, struct bitcoin_txid *funding_txid, + bool *funding_locked); + #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */ diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 8432d30a1..fda14c9f7 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -659,6 +659,10 @@ static void opening_fundee_finished(struct subd *openingd, channel_watch_funding(ld, channel); + /* Tell plugins about the success */ + notify_channel_opened(ld, &channel->peer->id, &channel->funding, + &channel->funding_txid, &channel->remote_funding_locked); + /* On to normal operation! */ peer_start_channeld(channel, pps, funding_signed, false);