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

Function json_add_rune

plugins/offers.c:725–888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

723}
724
725static void json_add_rune(struct command *cmd, struct json_stream *js, const struct rune *rune)
726{
727 const char *string;
728
729 /* Simplest to check everything for UTF-8 compliance at once.
730 * Since separators are | and & (which cannot appear inside
731 * UTF-8 multichars), if the entire thing is valid UTF-8 then
732 * each part is. */
733 string = rune_to_string(tmpctx, rune);
734 if (!utf8_check(string, strlen(string))) {
735 json_add_hex(js, "hex", string, strlen(string));
736 json_add_string(js, "warning_rune_invalid_utf8",
737 "Rune contains invalid UTF-8 strings");
738 json_add_bool(js, "valid", false);
739 return;
740 }
741
742 if (rune->unique_id)
743 json_add_string(js, "unique_id", rune->unique_id);
744 if (rune->version)
745 json_add_string(js, "version", rune->version);
746 json_add_string(js, "string", take(string));
747
748 json_array_start(js, "restrictions");
749 for (size_t i = rune->unique_id ? 1 : 0; i < tal_count(rune->restrs); i++) {
750 const struct rune_restr *restr = rune->restrs[i];
751 char *summary = tal_strdup(tmpctx, "");
752 const char *sep = "";
753
754 json_object_start(js, NULL);
755 json_array_start(js, "alternatives");
756 for (size_t j = 0; j < tal_count(restr->alterns); j++) {
757 const struct rune_altern *alt = restr->alterns[j];
758 const char *annotation, *value;
759 bool int_val = false, time_val = false;
760
761 if (streq(alt->fieldname, "time")) {
762 annotation = "in seconds since 1970";
763 time_val = true;
764 } else if (streq(alt->fieldname, "id"))
765 annotation = "of commanding peer";
766 else if (streq(alt->fieldname, "method"))
767 annotation = "of command";
768 else if (streq(alt->fieldname, "pnum")) {
769 annotation = "number of command parameters";
770 int_val = true;
771 } else if (streq(alt->fieldname, "rate")) {
772 annotation = "max per minute";
773 int_val = true;
774 } else if (strstarts(alt->fieldname, "parr")) {
775 annotation = tal_fmt(tmpctx, "array parameter #%s", alt->fieldname+4);
776 } else if (strstarts(alt->fieldname, "pname"))
777 annotation = tal_fmt(tmpctx, "object parameter '%s'", alt->fieldname+5);
778 else
779 annotation = "unknown condition?";
780
781 tal_append_fmt(&summary, "%s", sep);
782

Callers 1

json_decodeFunction · 0.85

Calls 12

rune_to_stringFunction · 0.85
json_add_hexFunction · 0.85
tal_append_fmtFunction · 0.85
time_nowFunction · 0.85
utf8_checkFunction · 0.50
json_add_stringFunction · 0.50
json_add_boolFunction · 0.50
json_array_startFunction · 0.50
json_object_startFunction · 0.50
json_add_str_fmtFunction · 0.50
json_array_endFunction · 0.50
json_object_endFunction · 0.50

Tested by

no test coverage detected