| 1021 | } |
| 1022 | |
| 1023 | static bool autocomplete_chan_id(struct token *token, |
| 1024 | struct splice_script_chan **channels, |
| 1025 | bool *multiple_chans, |
| 1026 | bool *node_id_overmatch) |
| 1027 | { |
| 1028 | struct channel_id *match; |
| 1029 | struct channel_id candidate; |
| 1030 | size_t len = strlen(token->str) / 2; |
| 1031 | |
| 1032 | *multiple_chans = false; |
| 1033 | *node_id_overmatch = false; |
| 1034 | |
| 1035 | if (strlen(token->str) < NODEID_MIN_CHARS) |
| 1036 | return false; |
| 1037 | if (len > PUBKEY_CMPR_LEN) |
| 1038 | return false; |
| 1039 | if (!hex_decode(token->str, len * 2, |
| 1040 | candidate.id, len)) |
| 1041 | return false; |
| 1042 | |
| 1043 | match = NULL; |
| 1044 | for (size_t i = 0; i < tal_count(channels); i++) { |
| 1045 | if (len <= sizeof(channels[i]->chan_id.id) |
| 1046 | && memeq(candidate.id, len, channels[i]->chan_id.id, len)) { |
| 1047 | /* must not match multiple channel ids */ |
| 1048 | if (match && !channel_id_eq(match, &channels[i]->chan_id)) { |
| 1049 | *multiple_chans = true; |
| 1050 | return true; |
| 1051 | } |
| 1052 | match = &channels[i]->chan_id; |
| 1053 | } |
| 1054 | /* nodeid query must *not* match any node ids */ |
| 1055 | if (len <= sizeof(channels[i]->node_id.k) |
| 1056 | && memeq(candidate.id, len, channels[i]->node_id.k, len)) |
| 1057 | *node_id_overmatch = true; |
| 1058 | } |
| 1059 | |
| 1060 | if (!match) |
| 1061 | return false; |
| 1062 | |
| 1063 | assert(!token->chan_id); |
| 1064 | token->chan_id = tal_dup(token, struct channel_id, match); |
| 1065 | |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
| 1069 | static struct splice_script_error *type_data(const tal_t *ctx, |
| 1070 | struct splice_script_chan **channels, |
no test coverage detected