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

Function jsonrpc_request_start_

lightningd/jsonrpc.c:1348–1391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1346}
1347
1348struct jsonrpc_request *jsonrpc_request_start_(
1349 const tal_t *ctx, const char *method,
1350 const char *id_prefix, struct log *log,
1351 bool add_header,
1352 void (*notify_cb)(const char *buffer,
1353 const jsmntok_t *methodtok,
1354 const jsmntok_t *paramtoks,
1355 const jsmntok_t *idtok,
1356 void *),
1357 void (*response_cb)(const char *buffer, const jsmntok_t *toks,
1358 const jsmntok_t *idtok, void *),
1359 void *response_cb_arg)
1360{
1361 struct jsonrpc_request *r = tal(ctx, struct jsonrpc_request);
1362 static u64 next_request_id = 0;
1363 if (id_prefix)
1364 r->id = tal_fmt(r, "%s/cln:%s#%"PRIu64,
1365 id_prefix, method, next_request_id);
1366 else
1367 r->id = tal_fmt(r, "cln:%s#%"PRIu64, method, next_request_id);
1368 if (taken(id_prefix))
1369 tal_free(id_prefix);
1370 next_request_id++;
1371 r->notify_cb = notify_cb;
1372 r->response_cb = response_cb;
1373 r->response_cb_arg = response_cb_arg;
1374 r->method = tal_strdup(r, method);
1375 r->stream = new_json_stream(r, NULL, log);
1376
1377 /* Disabling this serves as an escape hatch for plugin code to
1378 * get a raw request to paste into, but get a valid request-id
1379 * assigned. */
1380 if (add_header) {
1381 json_object_start(r->stream, NULL);
1382 json_add_string(r->stream, "jsonrpc", "2.0");
1383 json_add_string(r->stream, "id", r->id);
1384 json_add_string(r->stream, "method", method);
1385 json_object_start(r->stream, "params");
1386 }
1387 if (log)
1388 log_io(log, LOG_IO_OUT, NULL, r->id, NULL, 0);
1389
1390 return r;
1391}
1392
1393void jsonrpc_request_end(struct jsonrpc_request *r)
1394{

Callers

nothing calls this directly

Calls 6

takenFunction · 0.85
tal_freeFunction · 0.85
new_json_streamFunction · 0.85
log_ioFunction · 0.70
json_object_startFunction · 0.50
json_add_stringFunction · 0.50

Tested by

no test coverage detected