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

Function json_stream_forward_change_id

lightningd/plugin.c:1023–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1021}
1022
1023static void json_stream_forward_change_id(struct json_stream *stream,
1024 const char *buffer,
1025 const jsmntok_t *toks,
1026 const jsmntok_t *idtok,
1027 const char *new_id,
1028 bool new_id_is_str)
1029{
1030 /* We copy everything, but replace the id. Special care has to
1031 * be taken when the id that is being replaced is a string. If
1032 * we don't crop the quotes off we'll transform a numeric
1033 * new_id into a string, or even worse, quote a string id
1034 * twice. */
1035 size_t offset = 0;
1036 bool add_quotes = false;
1037
1038 if (idtok->type == JSMN_STRING) {
1039 if (new_id_is_str)
1040 add_quotes = false;
1041 else
1042 offset = 1;
1043 } else {
1044 if (new_id_is_str)
1045 add_quotes = true;
1046 }
1047
1048 json_stream_append(stream, buffer + toks->start,
1049 idtok->start - toks->start - offset);
1050
1051 if (add_quotes)
1052 json_stream_append(stream, "\"", 1);
1053 json_stream_append(stream, new_id, strlen(new_id));
1054 if (add_quotes)
1055 json_stream_append(stream, "\"", 1);
1056 json_stream_append(stream, buffer + idtok->end + offset,
1057 toks->end - idtok->end - offset);
1058}
1059
1060static void plugin_rpcmethod_cb(const char *buffer,
1061 const jsmntok_t *toks,

Callers 3

plugin_rpcmethod_cbFunction · 0.85
plugin_notify_cbFunction · 0.85

Calls 1

json_stream_appendFunction · 0.85

Tested by

no test coverage detected