Send request, return response, set resp/len to reponse */
| 771 | |
| 772 | /* Send request, return response, set resp/len to reponse */ |
| 773 | static const jsmntok_t *sync_req(const tal_t *ctx, |
| 774 | struct plugin *plugin, |
| 775 | const char *method, |
| 776 | const struct json_out *params TAKES, |
| 777 | const char **resp) |
| 778 | { |
| 779 | struct json_out *jout = json_out_new(tmpctx); |
| 780 | const char *id = json_id(tmpctx, plugin, "init/", method); |
| 781 | |
| 782 | json_out_start(jout, NULL, '{'); |
| 783 | json_out_addstr(jout, "jsonrpc", "2.0"); |
| 784 | /* Copy in id *literally* */ |
| 785 | memcpy(json_out_member_direct(jout, "id", strlen(id)), id, strlen(id)); |
| 786 | json_out_addstr(jout, "method", method); |
| 787 | if (params) |
| 788 | json_out_add_splice(jout, "params", params); |
| 789 | else { |
| 790 | json_out_start(jout, "params", '{'); |
| 791 | json_out_end(jout, '}'); |
| 792 | } |
| 793 | tal_free_if_taken(params); |
| 794 | |
| 795 | /* If we're past init, we may need a new fd (the old one |
| 796 | * is being used for async comms). */ |
| 797 | if (plugin->sync_fd == -1) { |
| 798 | plugin->sync_fd = rpc_open(plugin); |
| 799 | if (!plugin->sync_io) |
| 800 | plugin->sync_io = jsonrpc_io_new(plugin); |
| 801 | } |
| 802 | |
| 803 | finish_and_send_json(plugin->sync_fd, jout); |
| 804 | |
| 805 | return read_sync_rpc_reply(ctx, plugin, method, resp); |
| 806 | } |
| 807 | |
| 808 | const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx, |
| 809 | struct command *cmd, |
no test coverage detected