| 411 | |
| 412 | |
| 413 | static bool |
| 414 | hook_extract_psbt(const tal_t *ctx, struct subd *dualopend, const char *buffer, |
| 415 | const jsmntok_t *toks, char *hook_name, |
| 416 | bool allow_empty, |
| 417 | struct wally_psbt **out) |
| 418 | { |
| 419 | if (!buffer) |
| 420 | fatal("Plugin must return a valid response to %s", hook_name); |
| 421 | |
| 422 | const jsmntok_t *t = json_get_member(buffer, toks, "result"); |
| 423 | if (!t) |
| 424 | fatal("Plugin must return a 'result' to %s" |
| 425 | "%.*s", hook_name, toks[0].end - toks[0].start, |
| 426 | buffer + toks[0].start); |
| 427 | |
| 428 | if (!json_tok_streq(buffer, t, "continue")) { |
| 429 | /* dualopend might have closed if we're on the signed round */ |
| 430 | if (dualopend) { |
| 431 | char *errmsg = "Client error. Unable to continue"; |
| 432 | subd_send_msg(dualopend, |
| 433 | take(towire_dualopend_fail(NULL, errmsg))); |
| 434 | } |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | const jsmntok_t *psbt_tok = json_get_member(buffer, toks, "psbt"); |
| 439 | if (!psbt_tok) { |
| 440 | if (!allow_empty) |
| 441 | fatal("Plugin must return a 'psbt' to a 'continue'd" |
| 442 | "%s %.*s", hook_name, |
| 443 | toks[0].end - toks[0].start, |
| 444 | buffer + toks[0].start); |
| 445 | *out = NULL; |
| 446 | return true; |
| 447 | } |
| 448 | |
| 449 | *out = json_to_psbt(ctx, buffer, psbt_tok); |
| 450 | if (!*out) |
| 451 | fatal("Plugin must return a valid 'psbt' to a 'continue'd" |
| 452 | "%s %.*s", hook_name, |
| 453 | toks[0].end - toks[0].start, |
| 454 | buffer + toks[0].start); |
| 455 | |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | /* The field is *always* assumed msats, as that's the unit |
| 460 | * amount we're transitioning our API over to. A 'xxxsat' |
no test coverage detected