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

Function json_add_rune

plugins/offers.c:1615–1778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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