| 380 | |
| 381 | |
| 382 | static bool |
| 383 | hook_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' |
no test coverage detected