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

Function plugin_hook_callback

lightningd/plugin_hook.c:157–226  ·  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

155 * it to the hook callback.
156 */
157static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
158 const jsmntok_t *idtok,
159 struct plugin_hook_request *r)
160{
161 const jsmntok_t *resulttok;
162 struct db *db = r->db;
163 struct plugin_hook_call_link *last, *it;
164 bool in_transaction = false;
165
166 /* Pop the head off the call chain and continue with the next */
167 last = list_pop(&r->call_chain, struct plugin_hook_call_link, list);
168 assert(last != NULL);
169 tal_del_destructor(last, plugin_hook_killed);
170 tal_free(last);
171
172 /* Actually, if it dies during shutdown, *don't* process result! */
173 if (!buffer && r->ld->state == LD_STATE_SHUTDOWN) {
174 log_debug(r->ld->log,
175 "Abandoning plugin hook call due to shutdown");
176 return;
177 }
178
179 log_debug(r->ld->log, "Plugin %s returned from %s hook call",
180 r->plugin->shortname, r->hook->name);
181
182 if (buffer) {
183 resulttok = json_get_member(buffer, toks, "result");
184
185 if (!resulttok)
186 fatal("Plugin for %s returned non-result response %.*s",
187 r->hook->name, toks->end - toks->start,
188 buffer + toks->start);
189
190 db_begin_transaction(db);
191 if (!r->hook->deserialize_cb(r->cb_arg, buffer,
192 resulttok)) {
193 tal_free(r->cb_arg);
194 db_commit_transaction(db);
195 goto cleanup;
196 }
197 in_transaction = true;
198 } else {
199 /* plugin died */
200 resulttok = NULL;
201 }
202
203 if (!list_empty(&r->call_chain)) {
204 if (in_transaction)
205 db_commit_transaction(db);
206 plugin_hook_call_next(r);
207 return;
208 }
209
210 /* We optimize for the case where we already called deserialize_cb */
211 if (!in_transaction)
212 db_begin_transaction(db);
213 r->hook->final_cb(r->cb_arg);
214 db_commit_transaction(db);

Callers 1

plugin_hook_killedFunction · 0.85

Calls 5

tal_freeFunction · 0.85
plugin_hook_call_nextFunction · 0.85
fatalFunction · 0.70
json_get_memberFunction · 0.50
db_commit_transactionFunction · 0.50

Tested by

no test coverage detected