| 362 | } |
| 363 | |
| 364 | static const u8 *hook_extract_shutdown_script(struct subd* dualopend, |
| 365 | const char *buffer, |
| 366 | const jsmntok_t *toks) |
| 367 | { |
| 368 | const u8 *close_to_script; |
| 369 | enum address_parse_result parse_res; |
| 370 | |
| 371 | if (!buffer) |
| 372 | return NULL; |
| 373 | |
| 374 | const jsmntok_t *t = json_get_member(buffer, toks, "result"); |
| 375 | if (!t) |
| 376 | fatal("Plugin must return a 'result'" |
| 377 | "%.*s", toks[0].end - toks[0].start, |
| 378 | buffer + toks[0].start); |
| 379 | |
| 380 | if (!json_tok_streq(buffer, t, "continue")) { |
| 381 | char *errmsg = "Client error. Unable to continue"; |
| 382 | subd_send_msg(dualopend, |
| 383 | take(towire_dualopend_fail(NULL, errmsg))); |
| 384 | return NULL; |
| 385 | } |
| 386 | |
| 387 | const jsmntok_t *close_to_tok = json_get_member(buffer, toks, "close_to"); |
| 388 | if (!close_to_tok) |
| 389 | return NULL; |
| 390 | |
| 391 | parse_res = json_to_address_scriptpubkey(tmpctx, chainparams, buffer, |
| 392 | close_to_tok, &close_to_script); |
| 393 | switch (parse_res) { |
| 394 | case ADDRESS_PARSE_UNRECOGNIZED: |
| 395 | fatal("Plugin returned an invalid response to the" |
| 396 | " openchannel2.close_to hook: %.*s", |
| 397 | t->end - t->start, buffer + t->start); |
| 398 | case ADDRESS_PARSE_WRONG_NETWORK: |
| 399 | fatal("Plugin returned invalid response to the" |
| 400 | " openchannel2.close_to hook: address %s is" |
| 401 | " not on network %s", |
| 402 | tal_hex(NULL, close_to_script), |
| 403 | chainparams->network_name); |
| 404 | case ADDRESS_PARSE_SUCCESS: |
| 405 | return close_to_script; |
| 406 | } |
| 407 | |
| 408 | return NULL; |
| 409 | } |
| 410 | |
| 411 | |
| 412 | static bool |
no test coverage detected