| 2589 | } |
| 2590 | |
| 2591 | static struct command_result * |
| 2592 | json_openchannel_abort(struct command *cmd, |
| 2593 | const char *buffer, |
| 2594 | const jsmntok_t *obj UNNEEDED, |
| 2595 | const jsmntok_t *params) |
| 2596 | { |
| 2597 | struct channel_id *cid; |
| 2598 | struct channel *channel; |
| 2599 | u8 *msg; |
| 2600 | |
| 2601 | if (!param_check(cmd, buffer, params, |
| 2602 | p_req("channel_id", param_channel_id, &cid), |
| 2603 | NULL)) |
| 2604 | return command_param_failed(); |
| 2605 | |
| 2606 | channel = channel_by_cid(cmd->ld, cid); |
| 2607 | if (!channel) |
| 2608 | return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, |
| 2609 | "Unknown channel %s", |
| 2610 | fmt_channel_id(tmpctx, cid)); |
| 2611 | |
| 2612 | if (!channel->owner) |
| 2613 | return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, |
| 2614 | "Peer not connected"); |
| 2615 | |
| 2616 | if (!channel->open_attempt) { |
| 2617 | if (list_empty(&channel->inflights)) |
| 2618 | return command_fail(cmd, FUNDING_STATE_INVALID, |
| 2619 | "Channel open not in progress"); |
| 2620 | /* Commitments may already be stored; we can still abort |
| 2621 | * until we have sent tx_signatures. */ |
| 2622 | if (channel_funding_sigs_sent(channel)) |
| 2623 | return command_fail(cmd, FUNDING_STATE_INVALID, |
| 2624 | "Already sent sigs, can't cancel"); |
| 2625 | } else if (channel->open_attempt->cmd) { |
| 2626 | return command_fail(cmd, FUNDING_STATE_INVALID, |
| 2627 | "Another openchannel command" |
| 2628 | " is in progress"); |
| 2629 | } |
| 2630 | |
| 2631 | if (channel->openchannel_signed_cmd) |
| 2632 | return command_fail(cmd, FUNDING_STATE_INVALID, |
| 2633 | "Already sent sigs, waiting for peer's"); |
| 2634 | |
| 2635 | if (command_check_only(cmd)) |
| 2636 | return command_check_done(cmd); |
| 2637 | |
| 2638 | /* If commitments were already exchanged there's no open_attempt; |
| 2639 | * make one to park the command on, so we respond with the actual |
| 2640 | * outcome once the abort completes. */ |
| 2641 | if (!channel->open_attempt) |
| 2642 | channel->open_attempt = new_channel_open_attempt(channel); |
| 2643 | |
| 2644 | /* Mark it as aborted so when we clean-up, we send the |
| 2645 | * correct response */ |
| 2646 | channel->open_attempt->aborted = true; |
| 2647 | channel->open_attempt->cmd = cmd; |
| 2648 |
nothing calls this directly
no test coverage detected