| 2543 | } |
| 2544 | |
| 2545 | static struct command_result *json_stfu_channels(struct command *cmd, |
| 2546 | const char *buffer, |
| 2547 | const jsmntok_t *obj UNNEEDED, |
| 2548 | const jsmntok_t *params) |
| 2549 | { |
| 2550 | struct channel *channel, **channels; |
| 2551 | const jsmntok_t *channel_ids_tok, *channel_id_tok; |
| 2552 | struct command_result *result; |
| 2553 | struct splice_command *cc; |
| 2554 | struct stfu_req_info *req; |
| 2555 | size_t i; |
| 2556 | |
| 2557 | if (!param_check(cmd, buffer, params, |
| 2558 | p_opt("channel_ids", param_array, &channel_ids_tok), |
| 2559 | NULL)) |
| 2560 | return command_param_failed(); |
| 2561 | |
| 2562 | channels = tal_arr(cmd, struct channel*, 0); |
| 2563 | json_for_each_arr(i, channel_id_tok, channel_ids_tok) { |
| 2564 | result = param_channel_for_splice(cmd, NULL, buffer, channel_id_tok, |
| 2565 | &channel); |
| 2566 | if (result) |
| 2567 | return result; |
| 2568 | if (splice_command_for_chan(cmd->ld, channel)) |
| 2569 | return command_fail(cmd, |
| 2570 | SPLICE_BUSY_ERROR, |
| 2571 | "Currently waiting on previous" |
| 2572 | " splice command to finish."); |
| 2573 | |
| 2574 | tal_arr_expand(&channels, channel); |
| 2575 | } |
| 2576 | |
| 2577 | if (!tal_count(channels)) |
| 2578 | return command_fail_badparam(cmd, "channel_ids", buffer, |
| 2579 | channel_ids_tok, |
| 2580 | "Must specify a channel"); |
| 2581 | |
| 2582 | if (command_check_only(cmd)) |
| 2583 | return command_check_done(cmd); |
| 2584 | |
| 2585 | req = tal(cmd, struct stfu_req_info); |
| 2586 | |
| 2587 | /* Next we split into multiple `stfu` commands. The final command to |
| 2588 | * return finish the cmd response */ |
| 2589 | req->results = tal_arr(cmd, struct stfu_result*, 0); |
| 2590 | req->channel_ids = tal_arr(cmd, struct channel_id*, |
| 2591 | tal_count(channels)); |
| 2592 | |
| 2593 | for (i = 0; i < tal_count(channels); i++) { |
| 2594 | channel = channels[i]; |
| 2595 | |
| 2596 | req->channel_ids[i] = tal(req->channel_ids, struct channel_id); |
| 2597 | *req->channel_ids[i] = channel->cid; |
| 2598 | |
| 2599 | cc = tal(cmd, struct splice_command); |
| 2600 | |
| 2601 | list_add_tail(&cmd->ld->splice_commands, &cc->list); |
| 2602 | tal_add_destructor(cc, destroy_splice_command); |
nothing calls this directly
no test coverage detected