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

Function hook_gives_failmsg

lightningd/invoice.c:236–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236static const u8 *hook_gives_failmsg(const tal_t *ctx,
237 struct lightningd *ld,
238 const struct htlc_in *hin,
239 const char *buffer,
240 const jsmntok_t *toks)
241{
242 const jsmntok_t *resulttok;
243 const jsmntok_t *t;
244 unsigned int val;
245
246 /* No plugin registered on hook at all? */
247 if (!buffer)
248 return NULL;
249
250 resulttok = json_get_member(buffer, toks, "result");
251 if (resulttok) {
252 if (json_tok_streq(buffer, resulttok, "continue")) {
253 return NULL;
254 } else if (json_tok_streq(buffer, resulttok, "reject")) {
255 return failmsg_incorrect_or_unknown(ctx, ld, hin);
256 } else
257 fatal("Invalid invoice_payment hook result: %.*s",
258 toks[0].end - toks[0].start, buffer);
259 }
260
261 t = json_get_member(buffer, toks, "failure_message");
262 if (t) {
263 const u8 *failmsg = json_tok_bin_from_hex(ctx, buffer, t);
264 if (!failmsg)
265 fatal("Invalid invoice_payment_hook failure_message: %.*s",
266 toks[0].end - toks[1].start, buffer);
267 return failmsg;
268 }
269
270 if (!deprecated_apis)
271 return NULL;
272
273 t = json_get_member(buffer, toks, "failure_code");
274 if (!t) {
275 static bool warned = false;
276 if (!warned) {
277 warned = true;
278 log_unusual(ld->log,
279 "Plugin did not return object with "
280 "'result' or 'failure_message' fields. "
281 "This is now deprecated and you should "
282 "return {'result': 'continue' } or "
283 "{'result': 'reject'} or "
284 "{'failure_message'... instead.");
285 }
286 return failmsg_incorrect_or_unknown(ctx, ld, hin);
287 }
288
289 if (!json_to_number(buffer, t, &val))
290 fatal("Invalid invoice_payment_hook failure_code: %.*s",
291 toks[0].end - toks[1].start, buffer);
292
293 if (val == WIRE_TEMPORARY_NODE_FAILURE)

Callers 1

Calls 6

fatalFunction · 0.70
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50
json_tok_bin_from_hexFunction · 0.50
json_to_numberFunction · 0.50

Tested by

no test coverage detected