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

Function autocomplete_node_id

common/splice_script.c:977–1021  ·  view source on GitHub ↗

Checks token->str for a short node id and auto completes it. */

Source from the content-addressed store, hash-verified

975
976/* Checks token->str for a short node id and auto completes it. */
977static bool autocomplete_node_id(struct token *token,
978 struct splice_script_chan **channels,
979 bool *multiple_nodes,
980 bool *chan_id_overmatch)
981{
982 struct node_id *match;
983 struct node_id candidate;
984 size_t len = strlen(token->str) / 2;
985
986 *multiple_nodes = false;
987 *chan_id_overmatch = false;
988
989 if (strlen(token->str) < NODEID_MIN_CHARS)
990 return false;
991 if (len > PUBKEY_CMPR_LEN)
992 return false;
993 if (!hex_decode(token->str, len * 2,
994 candidate.k, len))
995 return false;
996
997 match = NULL;
998 for (size_t i = 0; i < tal_count(channels); i++) {
999 if (len <= sizeof(channels[i]->node_id.k)
1000 && memeq(candidate.k, len, channels[i]->node_id.k, len)) {
1001 /* must not match multiple node ids */
1002 if (match && !node_id_eq(match, &channels[i]->node_id)) {
1003 *multiple_nodes = true;
1004 return true;
1005 }
1006 match = &channels[i]->node_id;
1007 }
1008 /* nodeid query must *not* match any channel ids */
1009 if (len <= sizeof(channels[i]->chan_id.id)
1010 && memeq(candidate.k, len, channels[i]->chan_id.id, len))
1011 *chan_id_overmatch = true;
1012 }
1013
1014 if (!match)
1015 return false;
1016
1017 assert(!token->node_id);
1018 token->node_id = tal_dup(token, struct node_id, match);
1019
1020 return true;
1021}
1022
1023static bool autocomplete_chan_id(struct token *token,
1024 struct splice_script_chan **channels,

Callers 1

type_dataFunction · 0.85

Calls 3

hex_decodeFunction · 0.85
memeqFunction · 0.85
node_id_eqFunction · 0.85

Tested by

no test coverage detected