lightningd/notification: add 'channel_opened' notification

This notification is sent when a peer succesfully opens a channel to us
This commit is contained in:
darosior
2019-07-25 16:11:44 +02:00
committed by Christian Decker
parent f55d29ee49
commit 736651ba43
3 changed files with 29 additions and 1 deletions

View File

@@ -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));
}

View File

@@ -1,8 +1,11 @@
#ifndef LIGHTNING_LIGHTNINGD_NOTIFICATION_H
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <bitcoin/tx.h>
#include <ccan/json_escape/json_escape.h>
#include <common/amount.h>
#include <common/node_id.h>
#include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h>
#include <lightningd/log.h>
@@ -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 */

View File

@@ -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);