| 3043 | } |
| 3044 | |
| 3045 | static struct command_result *openchannel_init(struct command *cmd, |
| 3046 | struct peer *peer, |
| 3047 | struct amount_sat amount, |
| 3048 | struct amount_sat request_amt, |
| 3049 | const struct wally_psbt *psbt, |
| 3050 | u32 feerate_per_kw_funding, |
| 3051 | u32 feerate_per_kw, |
| 3052 | const u8 *our_upfront_shutdown_script, |
| 3053 | bool announce_channel, |
| 3054 | const struct lease_rates *rates, |
| 3055 | const struct channel_type *ctype) |
| 3056 | { |
| 3057 | u32 *our_upfront_shutdown_script_wallet_index; |
| 3058 | u32 found_wallet_index; |
| 3059 | u32 anchor_feerate; |
| 3060 | struct channel *channel; |
| 3061 | struct open_attempt *oa; |
| 3062 | int fds[2]; |
| 3063 | |
| 3064 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { |
| 3065 | return command_fail(cmd, FUND_MAX_EXCEEDED, |
| 3066 | "Failed to create socketpair: %s", |
| 3067 | strerror(errno)); |
| 3068 | } |
| 3069 | |
| 3070 | /* Now we can't fail, create channel */ |
| 3071 | channel = new_unsaved_channel(peer, |
| 3072 | peer->ld->config.fee_base, |
| 3073 | peer->ld->config.fee_per_satoshi); |
| 3074 | /* We derive initial channel_id *now*, so we can tell it to connectd. */ |
| 3075 | derive_tmp_channel_id(&channel->cid, |
| 3076 | &channel->local_basepoints.revocation); |
| 3077 | |
| 3078 | /* Get a new open_attempt going */ |
| 3079 | channel->opener = LOCAL; |
| 3080 | channel->open_attempt = oa = new_channel_open_attempt(channel); |
| 3081 | channel->channel_flags = OUR_CHANNEL_FLAGS; |
| 3082 | oa->funding = amount; |
| 3083 | oa->cmd = cmd; |
| 3084 | |
| 3085 | if (!announce_channel) { |
| 3086 | channel->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; |
| 3087 | log_info(peer->ld->log, |
| 3088 | "Will open private channel with node %s", |
| 3089 | fmt_node_id(tmpctx, &peer->id)); |
| 3090 | } |
| 3091 | |
| 3092 | /* Needs to be stolen away from cmd */ |
| 3093 | if (our_upfront_shutdown_script) |
| 3094 | oa->our_upfront_shutdown_script |
| 3095 | = tal_steal(oa, our_upfront_shutdown_script); |
| 3096 | |
| 3097 | /* Determine the wallet index for our_upfront_shutdown_script, |
| 3098 | * NULL if not found. */ |
| 3099 | if (wallet_can_spend(cmd->ld->wallet, |
| 3100 | oa->our_upfront_shutdown_script, |
| 3101 | tal_bytelen(oa->our_upfront_shutdown_script), |
| 3102 | &found_wallet_index, NULL)) { |
no test coverage detected