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

Function plugin_hook_callback

lightningd/plugin_hook.c:253–300  ·  view source on GitHub ↗

* Callback to be passed to the jsonrpc_request. * * Unbundles the arguments, deserializes the response and dispatches * it to the hook callback. */

Source from the content-addressed store, hash-verified

251 * it to the hook callback.
252 */
253static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
254 const jsmntok_t *idtok,
255 struct plugin_hook_request *ph_req)
256{
257 const jsmntok_t *resulttok;
258 const struct hook_instance *h;
259 enum jsonrpc_errcode ecode;
260
261 assert(ph_req->hook_index < tal_count(ph_req->hook->hooks));
262 /* NULL if it vanished */
263 h = ph_req->hook->hooks[ph_req->hook_index];
264
265 /* destructor NULLs out hooks[], but we get called first at the moment.
266 * We handle either */
267 ecode = 0;
268 json_scan(tmpctx, buffer, toks, "{error:{code:%}}",
269 JSON_SCAN(json_to_jsonrpc_errcode, &ecode));
270 if (ecode == PLUGIN_TERMINATED)
271 h = NULL;
272
273 /* We really only handle plugins dying: other errors are fatal. */
274 if (h) {
275 log_trace(ph_req->ld->log,
276 "Plugin %s returned from %s hook call",
277 h->plugin->shortname, ph_req->hook->name);
278 resulttok = json_get_member(buffer, toks, "result");
279 if (!resulttok)
280 fatal("Plugin %s for %s returned non-result response %.*s",
281 h->plugin->shortname,
282 ph_req->hook->name, toks->end - toks->start,
283 buffer + toks->start);
284
285 dev_save_plugin_io_in(h->plugin->plugins, "hook_in",
286 ph_req->hook->name,
287 buffer, toks);
288 if (!ph_req->hook->deserialize_cb(ph_req->cb_arg,
289 buffer, resulttok)) {
290 tal_free(ph_req->cb_arg);
291 tal_free(ph_req);
292 return;
293 }
294 } else {
295 log_debug(ph_req->ld->log, "Plugin died from %s hook call",
296 ph_req->hook->name);
297 }
298
299 plugin_hook_call_next(ph_req);
300}
301
302static bool hook_callable(const struct hook_instance *hook,
303 const char *strfilterfield,

Callers

nothing calls this directly

Calls 6

json_get_memberFunction · 0.85
dev_save_plugin_io_inFunction · 0.85
tal_freeFunction · 0.85
plugin_hook_call_nextFunction · 0.85
fatalFunction · 0.70
json_scanFunction · 0.50

Tested by

no test coverage detected