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

Function json_parse_deprecated

lightningd/plugin.c:986–1027  ·  view source on GitHub ↗

Parse deprecated field, as either bool or an array of strings */

Source from the content-addressed store, hash-verified

984
985/* Parse deprecated field, as either bool or an array of strings */
986static const char *json_parse_deprecated(const tal_t *ctx,
987 const char *buffer,
988 const jsmntok_t *deprtok,
989 const char **depr_start,
990 const char **depr_end)
991{
992 bool is_depr;
993
994 *depr_start = *depr_end = NULL;
995
996 if (!deprtok)
997 return NULL;
998
999 /* Not every plugin will track deprecation cycles (and that's OK!):
1000 * pretend it's just been deprecated. */
1001 if (json_to_bool(buffer, deprtok, &is_depr)) {
1002 if (is_depr)
1003 *depr_start = CLN_NEXT_VERSION;
1004 return NULL;
1005 }
1006
1007 if (deprtok->type != JSMN_ARRAY || deprtok->size > 2) {
1008 return tal_fmt(ctx, "\"deprecated\" must be an array of 1 or 2 elements, not %.*s",
1009 deprtok->end - deprtok->start,
1010 buffer + deprtok->start);
1011 }
1012
1013 *depr_start = json_strdup(ctx, buffer, deprtok + 1);
1014 if (version_to_number(*depr_start) == 0)
1015 return tal_fmt(ctx,
1016 "invalid \"deprecated\" start version %s",
1017 *depr_start);
1018
1019 if (deprtok->size == 2) {
1020 *depr_end = json_strdup(ctx, buffer, deprtok + 2);
1021 if (version_to_number(*depr_end) == 0)
1022 return tal_fmt(ctx,
1023 "invalid \"deprecated\" end version %s",
1024 *depr_end);
1025 }
1026 return NULL;
1027}
1028
1029/* Add a single plugin option to the plugin as well as registering it with the
1030 * command line options. */

Callers 2

plugin_opt_addFunction · 0.85
plugin_rpcmethod_addFunction · 0.85

Calls 3

version_to_numberFunction · 0.85
json_to_boolFunction · 0.50
json_strdupFunction · 0.50

Tested by

no test coverage detected