| 560 | }; |
| 561 | |
| 562 | static struct command_result *param_channel_or_peer(struct command *cmd, |
| 563 | const char *name, |
| 564 | const char *buffer, |
| 565 | const jsmntok_t *tok, |
| 566 | struct some_channel **sc) |
| 567 | { |
| 568 | struct peer *peer = peer_from_json(cmd->ld, buffer, tok); |
| 569 | bool more_than_one; |
| 570 | |
| 571 | (*sc)->unsaved_channel = NULL; |
| 572 | (*sc)->uc = NULL; |
| 573 | |
| 574 | if (peer) { |
| 575 | (*sc)->channel = peer_any_active_channel(peer, &more_than_one); |
| 576 | if ((*sc)->channel) { |
| 577 | if (more_than_one) |
| 578 | goto more_than_one; |
| 579 | return NULL; |
| 580 | } |
| 581 | } else { |
| 582 | struct command_result *res; |
| 583 | res = command_find_channel(cmd, buffer, tok, &(*sc)->channel); |
| 584 | if (res) |
| 585 | return res; |
| 586 | assert((*sc)->channel); |
| 587 | return NULL; |
| 588 | } |
| 589 | |
| 590 | /* OK, we have a peer, but no active channels. */ |
| 591 | (*sc)->uc = peer->uncommitted_channel; |
| 592 | if ((*sc)->uc) |
| 593 | return NULL; |
| 594 | |
| 595 | (*sc)->unsaved_channel = peer_any_unsaved_channel(peer, &more_than_one); |
| 596 | if ((*sc)->unsaved_channel) { |
| 597 | if (more_than_one) |
| 598 | goto more_than_one; |
| 599 | return NULL; |
| 600 | } |
| 601 | |
| 602 | return command_fail(cmd, LIGHTNINGD, "Peer has no active channel"); |
| 603 | |
| 604 | more_than_one: |
| 605 | return command_fail(cmd, LIGHTNINGD, |
| 606 | "Peer has multiple channels: use channel_id or short_channel_id"); |
| 607 | } |
| 608 | |
| 609 | static struct command_result *json_close(struct command *cmd, |
| 610 | const char *buffer, |
nothing calls this directly
no test coverage detected