| 1346 | } |
| 1347 | |
| 1348 | struct 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 | |
| 1393 | void jsonrpc_request_end(struct jsonrpc_request *r) |
| 1394 | { |
nothing calls this directly
no test coverage detected