MCPcopy Create free account
hub / github.com/ElementsProject/lightning / openchannel2_hook_cb

Function openchannel2_hook_cb

lightningd/dual_open_control.c:619–679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619static void
620openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
621{
622 struct subd *dualopend = payload->dualopend;
623 struct channel *channel = payload->channel;
624 u32 *our_shutdown_script_wallet_index;
625 u8 *msg;
626
627 /* Our daemon died! */
628 if (!dualopend)
629 return;
630
631 /* Free payload regardless of what happens next */
632 tal_steal(tmpctx, payload);
633
634 channel = dualopend->channel;
635
636 /* Channel open is currently in progress elsewhere! */
637 if (channel->open_attempt) {
638 msg = towire_dualopend_fail(NULL, "Already initiated channel"
639 " open");
640 log_debug(dualopend->ld->log,
641 "Our open in progress, denying their offer");
642 return subd_send_msg(dualopend, take(msg));
643 }
644
645 tal_del_destructor2(dualopend, openchannel2_remove_dualopend, payload);
646
647 if (payload->err_msg) {
648 log_debug(dualopend->ld->log,
649 "openchannel2 hook rejects and says '%s'",
650 payload->err_msg);
651 msg = towire_dualopend_fail(NULL, payload->err_msg);
652 return subd_send_msg(dualopend, take(msg));
653 }
654
655 /* Determine the wallet index for our_shutdown_scriptpubkey,
656 * NULL if not found. */
657 u32 found_wallet_index;
658 bool is_p2sh;
659 if (wallet_can_spend(dualopend->ld->wallet,
660 payload->our_shutdown_scriptpubkey,
661 &found_wallet_index,
662 &is_p2sh)) {
663 our_shutdown_script_wallet_index = tal(tmpctx, u32);
664 *our_shutdown_script_wallet_index = found_wallet_index;
665 } else
666 our_shutdown_script_wallet_index = NULL;
667
668 channel->cid = payload->channel_id;
669 channel->opener = REMOTE;
670 channel->open_attempt = new_channel_open_attempt(channel);
671 msg = towire_dualopend_got_offer_reply(NULL,
672 payload->accepter_funding,
673 payload->psbt,
674 payload->our_shutdown_scriptpubkey,
675 our_shutdown_script_wallet_index,
676 payload->rates);

Callers 1

Calls 3

wallet_can_spendFunction · 0.85
new_channel_open_attemptFunction · 0.85
subd_send_msgFunction · 0.70

Tested by

no test coverage detected