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

Function plugin_hook_call_

lightningd/plugin_hook.c:247–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
248 const char *cmd_id TAKES,
249 tal_t *cb_arg STEALS)
250{
251 struct plugin_hook_request *ph_req;
252 struct plugin_hook_call_link *link;
253 if (tal_count(hook->hooks)) {
254 /* If we have a plugin that has registered for this
255 * hook, serialize and call it */
256 /* FIXME: technically this is a leak, but we don't
257 * currently have a list to store these. We might want
258 * to eventually to inspect in-flight requests. */
259 ph_req = notleak(tal(hook->hooks, struct plugin_hook_request));
260 ph_req->hook = hook;
261 ph_req->cb_arg = tal_steal(ph_req, cb_arg);
262 ph_req->db = ld->wallet->db;
263 ph_req->ld = ld;
264 if (cmd_id)
265 ph_req->cmd_id = tal_strdup(ph_req, cmd_id);
266 else
267 ph_req->cmd_id = NULL;
268
269 list_head_init(&ph_req->call_chain);
270 for (size_t i=0; i<tal_count(hook->hooks); i++) {
271 /* We allocate this off of the plugin so we get notified if the plugin dies. */
272 link = tal(hook->hooks[i]->plugin,
273 struct plugin_hook_call_link);
274 link->plugin = hook->hooks[i]->plugin;
275 link->req = ph_req;
276 tal_add_destructor(link, plugin_hook_killed);
277 list_add_tail(&ph_req->call_chain, &link->list);
278 }
279 plugin_hook_call_next(ph_req);
280 return false;
281 } else {
282 /* If no plugin has registered for this hook, just
283 * call the callback with a NULL result. Saves us the
284 * roundtrip to the serializer and deserializer. If we
285 * were expecting a default response it should have
286 * been part of the `cb_arg`. */
287 hook->final_cb(cb_arg);
288 return true;
289 }
290}
291
292/* We open-code this, because it's just different and special enough to be
293 * annoying, and to make it clear that it's totally synchronous. */

Callers

nothing calls this directly

Calls 2

list_head_initFunction · 0.85
plugin_hook_call_nextFunction · 0.85

Tested by

no test coverage detected