| 332 | } |
| 333 | |
| 334 | static const u8 *hook_extract_shutdown_script(struct subd* dualopend, |
| 335 | const char *buffer, |
| 336 | const jsmntok_t *toks) |
| 337 | { |
| 338 | const u8 *close_to_script; |
| 339 | enum address_parse_result parse_res; |
| 340 | |
| 341 | if (!buffer) |
| 342 | return NULL; |
| 343 | |
| 344 | const jsmntok_t *t = json_get_member(buffer, toks, "result"); |
| 345 | if (!t) |
| 346 | fatal("Plugin must return a 'result'" |
| 347 | "%.*s", toks[0].end - toks[0].start, |
| 348 | buffer + toks[0].start); |
| 349 | |
| 350 | if (!json_tok_streq(buffer, t, "continue")) { |
| 351 | char *errmsg = "Client error. Unable to continue"; |
| 352 | subd_send_msg(dualopend, |
| 353 | take(towire_dualopend_fail(NULL, errmsg))); |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | const jsmntok_t *close_to_tok = json_get_member(buffer, toks, "close_to"); |
| 358 | if (!close_to_tok) |
| 359 | return NULL; |
| 360 | |
| 361 | parse_res = json_to_address_scriptpubkey(tmpctx, chainparams, buffer, |
| 362 | close_to_tok, &close_to_script); |
| 363 | switch (parse_res) { |
| 364 | case ADDRESS_PARSE_UNRECOGNIZED: |
| 365 | fatal("Plugin returned an invalid response to the" |
| 366 | " openchannel2.close_to hook: %.*s", |
| 367 | t->end - t->start, buffer + t->start); |
| 368 | case ADDRESS_PARSE_WRONG_NETWORK: |
| 369 | fatal("Plugin returned invalid response to the" |
| 370 | " openchannel2.close_to hook: address %s is" |
| 371 | " not on network %s", |
| 372 | tal_hex(NULL, close_to_script), |
| 373 | chainparams->network_name); |
| 374 | case ADDRESS_PARSE_SUCCESS: |
| 375 | return close_to_script; |
| 376 | } |
| 377 | |
| 378 | return NULL; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | static bool |
no test coverage detected