| 378 | /* FIXME: Move lightningd/jsonrpc to common/ ? */ |
| 379 | |
| 380 | struct out_req * |
| 381 | jsonrpc_request_start_(struct command *cmd, |
| 382 | const char *method, |
| 383 | const char *id_prefix, |
| 384 | const char *filter, |
| 385 | struct command_result *(*cb)(struct command *command, |
| 386 | const char *methodname, |
| 387 | const char *buf, |
| 388 | const jsmntok_t *result, |
| 389 | void *arg), |
| 390 | struct command_result *(*errcb)(struct command *command, |
| 391 | const char *methodname, |
| 392 | const char *buf, |
| 393 | const jsmntok_t *result, |
| 394 | void *arg), |
| 395 | void *arg) |
| 396 | { |
| 397 | struct out_req *out; |
| 398 | |
| 399 | assert(cmd); |
| 400 | out = tal(cmd, struct out_req); |
| 401 | out->method = tal_strdup(out, method); |
| 402 | out->id = json_id(out, cmd->plugin, method, id_prefix ? id_prefix : cmd->id); |
| 403 | out->cmd = cmd; |
| 404 | out->cb = cb; |
| 405 | out->errcb = errcb; |
| 406 | out->arg = arg; |
| 407 | strmap_add(&cmd->plugin->out_reqs, out->id, out); |
| 408 | tal_add_destructor2(out, destroy_out_req, cmd->plugin); |
| 409 | |
| 410 | out->js = new_json_stream(NULL, cmd, NULL); |
| 411 | json_object_start(out->js, NULL); |
| 412 | json_add_string(out->js, "jsonrpc", "2.0"); |
| 413 | json_add_id(out->js, out->id); |
| 414 | json_add_string(out->js, "method", method); |
| 415 | if (filter) { |
| 416 | /* This is raw JSON, so paste, don't escape! */ |
| 417 | size_t len = strlen(filter); |
| 418 | char *p = json_out_member_direct(out->js->jout, "filter", len); |
| 419 | memcpy(p, filter, len); |
| 420 | } |
| 421 | if (out->errcb) |
| 422 | json_object_start(out->js, "params"); |
| 423 | |
| 424 | return out; |
| 425 | } |
| 426 | |
| 427 | const struct feature_set *plugin_feature_set(const struct plugin *p) |
| 428 | { |
nothing calls this directly
no test coverage detected