MCPcopy Create free account
hub / github.com/ElementsProject/lightning / param_channel_or_peer

Function param_channel_or_peer

lightningd/closing_control.c:563–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561}
562
563static struct command_result *param_channel_or_peer(struct command *cmd,
564 const char *name,
565 const char *buffer,
566 const jsmntok_t *tok,
567 struct some_channel **sc)
568{
569 struct peer *peer = peer_from_json(cmd->ld, buffer, tok);
570 bool more_than_one;
571
572 (*sc)->unsaved_channel = NULL;
573 (*sc)->uc = NULL;
574
575 if (peer) {
576 (*sc)->channel = peer_any_channel_bystate(peer, channel_state_can_close, &more_than_one);
577 if ((*sc)->channel) {
578 if (more_than_one)
579 goto more_than_one;
580 return NULL;
581 }
582 } else {
583 struct command_result *res;
584 res = command_find_channel(cmd, name, buffer, tok, &(*sc)->channel);
585 if (res)
586 return res;
587 assert((*sc)->channel);
588 if (!channel_state_can_close((*sc)->channel->state))
589 return command_fail_badparam(cmd, name, buffer, tok,
590 tal_fmt(tmpctx, "Channel in state %s",
591 channel_state_name((*sc)->channel)));
592 return NULL;
593 }
594
595 /* OK, we have a peer, but no active channels. */
596 (*sc)->uc = peer->uncommitted_channel;
597 if ((*sc)->uc)
598 return NULL;
599
600 (*sc)->unsaved_channel = peer_any_channel_bystate(peer, channel_state_uncommitted, &more_than_one);
601 if ((*sc)->unsaved_channel) {
602 if (more_than_one)
603 goto more_than_one;
604 return NULL;
605 }
606
607 return command_fail(cmd, LIGHTNINGD, "Peer has no active channel");
608
609more_than_one:
610 return command_fail(cmd, LIGHTNINGD,
611 "Peer has multiple channels: use channel_id or short_channel_id");
612}
613
614static struct command_result *json_close(struct command *cmd,
615 const char *buffer,

Callers

nothing calls this directly

Calls 7

peer_from_jsonFunction · 0.85
command_find_channelFunction · 0.85
channel_state_can_closeFunction · 0.85
peer_any_channel_bystateFunction · 0.70
channel_state_nameFunction · 0.70
command_failFunction · 0.70
command_fail_badparamFunction · 0.50

Tested by

no test coverage detected