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

Function json_add_rune

plugins/offers.c:1613–1776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1611}
1612
1613static void json_add_rune(struct command *cmd, struct json_stream *js, const struct rune *rune)
1614{
1615 const char *string;
1616
1617 /* Simplest to check everything for UTF-8 compliance at once.
1618 * Since separators are | and & (which cannot appear inside
1619 * UTF-8 multichars), if the entire thing is valid UTF-8 then
1620 * each part is. */
1621 string = rune_to_string(tmpctx, rune);
1622 if (!utf8_check(string, strlen(string))) {
1623 json_add_hex(js, "hex", string, strlen(string));
1624 json_add_string(js, "warning_rune_invalid_utf8",
1625 "Rune contains invalid UTF-8 strings");
1626 json_add_bool(js, "valid", false);
1627 return;
1628 }
1629
1630 if (rune->unique_id)
1631 json_add_string(js, "unique_id", rune->unique_id);
1632 if (rune->version)
1633 json_add_string(js, "version", rune->version);
1634 json_add_string(js, "string", take(string));
1635
1636 json_array_start(js, "restrictions");
1637 for (size_t i = rune->unique_id ? 1 : 0; i < tal_count(rune->restrs); i++) {
1638 const struct rune_restr *restr = rune->restrs[i];
1639 char *summary = tal_strdup(tmpctx, "");
1640 const char *sep = "";
1641
1642 json_object_start(js, NULL);
1643 json_array_start(js, "alternatives");
1644 for (size_t j = 0; j < tal_count(restr->alterns); j++) {
1645 const struct rune_altern *alt = restr->alterns[j];
1646 const char *annotation, *value;
1647 bool int_val = false, time_val = false;
1648
1649 if (streq(alt->fieldname, "time")) {
1650 annotation = "in seconds since 1970";
1651 time_val = true;
1652 } else if (streq(alt->fieldname, "id"))
1653 annotation = "of commanding peer";
1654 else if (streq(alt->fieldname, "method"))
1655 annotation = "of command";
1656 else if (streq(alt->fieldname, "pnum")) {
1657 annotation = "number of command parameters";
1658 int_val = true;
1659 } else if (streq(alt->fieldname, "rate")) {
1660 annotation = "max per minute";
1661 int_val = true;
1662 } else if (strstarts(alt->fieldname, "parr")) {
1663 annotation = tal_fmt(tmpctx, "array parameter #%s", alt->fieldname+4);
1664 } else if (strstarts(alt->fieldname, "pname"))
1665 annotation = tal_fmt(tmpctx, "object parameter '%s'", alt->fieldname+5);
1666 else
1667 annotation = "unknown condition?";
1668
1669 tal_append_fmt(&summary, "%s", sep);
1670

Callers 1

json_decodeFunction · 0.70

Calls 12

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

Tested by

no test coverage detected