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

Function sync_req

plugins/libplugin.c:783–816  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

781
782/* Send request, return response, set resp/len to reponse */
783static 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
818const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
819 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