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