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

Function sync_req

plugins/libplugin.c:773–806  ·  view source on GitHub ↗

Send request, return response, set resp/len to reponse */

Source from the content-addressed store, hash-verified

771
772/* Send request, return response, set resp/len to reponse */
773static 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
808const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
809 struct command *cmd,

Callers 3

jsonrpc_request_syncFunction · 0.85
rpc_scan_coreFunction · 0.85
rpc_enable_batchingFunction · 0.85

Calls 12

json_out_newFunction · 0.85
json_idFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_member_directFunction · 0.85
json_out_add_spliceFunction · 0.85
json_out_endFunction · 0.85
tal_free_if_takenFunction · 0.85
rpc_openFunction · 0.85
jsonrpc_io_newFunction · 0.85
finish_and_send_jsonFunction · 0.85
read_sync_rpc_replyFunction · 0.85

Tested by

no test coverage detected