| 3284 | } |
| 3285 | |
| 3286 | static struct command_result *openchannel_init(struct command *cmd, |
| 3287 | struct peer *peer, |
| 3288 | struct amount_sat amount, |
| 3289 | struct amount_sat request_amt, |
| 3290 | const struct wally_psbt *psbt, |
| 3291 | u32 feerate_per_kw_funding, |
| 3292 | u32 feerate_per_kw, |
| 3293 | const u8 *our_upfront_shutdown_script, |
| 3294 | bool announce_channel, |
| 3295 | const struct lease_rates *rates, |
| 3296 | const struct channel_type *ctype) |
| 3297 | { |
| 3298 | u32 *our_upfront_shutdown_script_wallet_index; |
| 3299 | u32 found_wallet_index; |
| 3300 | u32 anchor_feerate; |
| 3301 | struct channel *channel; |
| 3302 | struct open_attempt *oa; |
| 3303 | int fds[2]; |
| 3304 | |
| 3305 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { |
| 3306 | return command_fail(cmd, FUND_MAX_EXCEEDED, |
| 3307 | "Failed to create socketpair: %s", |
| 3308 | strerror(errno)); |
| 3309 | } |
| 3310 | |
| 3311 | /* Now we can't fail, create channel */ |
| 3312 | channel = new_unsaved_channel(peer, |
| 3313 | peer->ld->config.fee_base, |
| 3314 | peer->ld->config.fee_per_satoshi); |
| 3315 | /* We derive initial channel_id *now*, so we can tell it to connectd. */ |
| 3316 | derive_tmp_channel_id(&channel->cid, |
| 3317 | &channel->local_basepoints.revocation); |
| 3318 | |
| 3319 | /* Get a new open_attempt going */ |
| 3320 | channel->opener = LOCAL; |
| 3321 | channel->open_attempt = oa = new_channel_open_attempt(channel); |
| 3322 | channel->channel_flags = OUR_CHANNEL_FLAGS; |
| 3323 | oa->funding = amount; |
| 3324 | oa->cmd = cmd; |
| 3325 | |
| 3326 | if (!announce_channel) { |
| 3327 | channel->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; |
| 3328 | log_info(peer->ld->log, |
| 3329 | "Will open private channel with node %s", |
| 3330 | fmt_node_id(tmpctx, &peer->id)); |
| 3331 | } |
| 3332 | |
| 3333 | /* Needs to be stolen away from cmd */ |
| 3334 | if (our_upfront_shutdown_script) |
| 3335 | oa->our_upfront_shutdown_script |
| 3336 | = tal_steal(oa, our_upfront_shutdown_script); |
| 3337 | |
| 3338 | /* Determine the wallet index for our_upfront_shutdown_script, |
| 3339 | * NULL if not found. */ |
| 3340 | if (wallet_can_spend(cmd->ld->wallet, |
| 3341 | oa->our_upfront_shutdown_script, |
| 3342 | tal_bytelen(oa->our_upfront_shutdown_script), |
| 3343 | &found_wallet_index, NULL)) { |
no test coverage detected