diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index 0cf22eb98..c40e9d6a7 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -653,6 +653,22 @@ at the time lightningd broadcasts the notification. `coin_type` is the BIP173 name for the coin which moved. +### `openchannel_peer_sigs` + +When opening a channel with a peer using the collaborative transaction protocol +(`opt_dual_fund`), this notification is fired when the peer sends us their funding +transaction signatures, `tx_signatures`. We update the in-progress PSBT and return it +here, with the peer's signatures attached. + +```json +{ + "openchannel_peer_sigs": { + "channel_id": "", + "signed_psbt": "" + } +} +``` ## Hooks diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 5e714bc59..bc35e24d4 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -449,6 +450,10 @@ static void peer_tx_sigs_msg(struct channel *channel, const u8 *msg) } wallet_channel_save(ld->wallet, channel); + + /* Send notification with peer's signed PSBT */ + notify_openchannel_peer_sigs(ld, &channel->cid, + channel->psbt); } void forget_channel(struct channel *channel, const char *why) diff --git a/lightningd/notification.c b/lightningd/notification.c index 9d7f395c3..a6de02c1e 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -467,3 +467,31 @@ void notify_coin_mvt(struct lightningd *ld, jsonrpc_notification_end(n); plugins_notify(ld->plugins, take(n)); } + +static void openchannel_peer_sigs_serialize(struct json_stream *stream, + const struct channel_id *cid, + const struct wally_psbt *psbt) +{ + json_object_start(stream, "openchannel_peer_sigs"); + json_add_channel_id(stream, "channel_id", cid); + json_add_psbt(stream, "signed_psbt", psbt); + json_object_end(stream); +} + +REGISTER_NOTIFICATION(openchannel_peer_sigs, + openchannel_peer_sigs_serialize); + +void notify_openchannel_peer_sigs(struct lightningd *ld, + const struct channel_id *cid, + const struct wally_psbt *psbt) +{ + void (*serialize)(struct json_stream *, + const struct channel_id *cid, + const struct wally_psbt *) = openchannel_peer_sigs_notification_gen.serialize; + + struct jsonrpc_notification *n = + jsonrpc_notification_start(NULL, "openchannel_peer_sigs"); + serialize(n->stream, cid, psbt); + jsonrpc_notification_end(n); + plugins_notify(ld->plugins, take(n)); +} diff --git a/lightningd/notification.h b/lightningd/notification.h index 000c76d28..ce9f056d1 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -19,9 +19,11 @@ #include #include #include +#include #include struct onionreply; +struct wally_psbt; bool notifications_have_topic(const char *topic); @@ -86,4 +88,8 @@ void notify_sendpay_failure(struct lightningd *ld, void notify_coin_mvt(struct lightningd *ld, const struct coin_mvt *mvt); + +void notify_openchannel_peer_sigs(struct lightningd *ld, + const struct channel_id *cid, + const struct wally_psbt *psbt); #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */