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

Function hook_extract_psbt

lightningd/dual_open_control.c:382–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380
381
382static bool
383hook_extract_psbt(const tal_t *ctx, struct subd *dualopend, const char *buffer,
384 const jsmntok_t *toks, char *hook_name,
385 bool allow_empty,
386 struct wally_psbt **out)
387{
388 if (!buffer)
389 fatal("Plugin must return a valid response to %s", hook_name);
390
391 const jsmntok_t *t = json_get_member(buffer, toks, "result");
392 if (!t)
393 fatal("Plugin must return a 'result' to %s"
394 "%.*s", hook_name, toks[0].end - toks[0].start,
395 buffer + toks[0].start);
396
397 if (!json_tok_streq(buffer, t, "continue")) {
398 /* dualopend might have closed if we're on the signed round */
399 if (dualopend) {
400 char *errmsg = "Client error. Unable to continue";
401 subd_send_msg(dualopend,
402 take(towire_dualopend_fail(NULL, errmsg)));
403 }
404 return false;
405 }
406
407 const jsmntok_t *psbt_tok = json_get_member(buffer, toks, "psbt");
408 if (!psbt_tok) {
409 if (!allow_empty)
410 fatal("Plugin must return a 'psbt' to a 'continue'd"
411 "%s %.*s", hook_name,
412 toks[0].end - toks[0].start,
413 buffer + toks[0].start);
414 *out = NULL;
415 return true;
416 }
417
418 *out = json_to_psbt(ctx, buffer, psbt_tok);
419 if (!*out)
420 fatal("Plugin must return a valid 'psbt' to a 'continue'd"
421 "%s %.*s", hook_name,
422 toks[0].end - toks[0].start,
423 buffer + toks[0].start);
424
425 return true;
426}
427
428/* The field is *always* assumed msats, as that's the unit
429 * amount we're transitioning our API over to. A 'xxxsat'

Calls 5

json_to_psbtFunction · 0.85
fatalFunction · 0.70
subd_send_msgFunction · 0.70
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50

Tested by

no test coverage detected