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

Function openchannel2_hook_cb

lightningd/dual_open_control.c:656–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

654}
655
656static void
657openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
658{
659 struct subd *dualopend = payload->dualopend;
660 struct channel *channel = payload->channel;
661 u32 *our_shutdown_script_wallet_index;
662 u8 *msg;
663
664 /* Our daemon died! */
665 if (!dualopend)
666 return;
667
668 /* Free payload regardless of what happens next */
669 tal_steal(tmpctx, payload);
670
671 channel = dualopend->channel;
672
673 /* Channel open is currently in progress elsewhere! */
674 if (channel->open_attempt) {
675 msg = towire_dualopend_fail(NULL, "Already initiated channel"
676 " open");
677 log_debug(dualopend->ld->log,
678 "Our open in progress, denying their offer");
679 return subd_send_msg(dualopend, take(msg));
680 }
681
682 tal_del_destructor2(dualopend, openchannel2_remove_dualopend, payload);
683
684 if (payload->err_msg) {
685 log_debug(dualopend->ld->log,
686 "openchannel2 hook rejects and says '%s'",
687 payload->err_msg);
688 msg = towire_dualopend_fail(NULL, payload->err_msg);
689 return subd_send_msg(dualopend, take(msg));
690 }
691
692 /* Determine the wallet index for our_shutdown_scriptpubkey,
693 * NULL if not found. */
694 u32 found_wallet_index;
695 if (wallet_can_spend(dualopend->ld->wallet,
696 payload->our_shutdown_scriptpubkey,
697 tal_bytelen(payload->our_shutdown_scriptpubkey),
698 &found_wallet_index, NULL)) {
699 our_shutdown_script_wallet_index = tal(tmpctx, u32);
700 *our_shutdown_script_wallet_index = found_wallet_index;
701 } else
702 our_shutdown_script_wallet_index = NULL;
703
704 channel->cid = payload->channel_id;
705 channel->opener = REMOTE;
706 channel->open_attempt = new_channel_open_attempt(channel);
707 channel->req_confirmed_ins[REMOTE] =
708 payload->req_confirmed_ins_remote;
709 msg = towire_dualopend_got_offer_reply(NULL,
710 payload->accepter_funding,
711 payload->psbt,
712 payload->our_shutdown_scriptpubkey,
713 our_shutdown_script_wallet_index,

Callers 1

Calls 4

wallet_can_spendFunction · 0.85
tal_bytelenFunction · 0.85
new_channel_open_attemptFunction · 0.85
subd_send_msgFunction · 0.70

Tested by

no test coverage detected