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