| 716 | } |
| 717 | |
| 718 | static bool |
| 719 | openchannel_hook_deserialize(struct openchannel_hook_payload *payload, |
| 720 | const char *buffer, |
| 721 | const jsmntok_t *toks) |
| 722 | { |
| 723 | struct subd *openingd = payload->openingd; |
| 724 | |
| 725 | /* already rejected by prior plugin hook in the chain */ |
| 726 | if (payload->errmsg != NULL) |
| 727 | return true; |
| 728 | |
| 729 | if (!toks || !buffer) |
| 730 | return true; |
| 731 | |
| 732 | const jsmntok_t *t_result = json_get_member(buffer, toks, "result"); |
| 733 | const jsmntok_t *t_errmsg = json_get_member(buffer, toks, "error_message"); |
| 734 | const jsmntok_t *t_closeto = json_get_member(buffer, toks, "close_to"); |
| 735 | const jsmntok_t *t_mindepth = json_get_member(buffer, toks, "mindepth"); |
| 736 | const jsmntok_t *t_reserve = json_get_member(buffer, toks, "reserve"); |
| 737 | |
| 738 | if (!t_result) |
| 739 | fatal("Plugin returned an invalid response to the" |
| 740 | " openchannel hook: %.*s", |
| 741 | toks[0].end - toks[0].start, buffer + toks[0].start); |
| 742 | |
| 743 | /* reject */ |
| 744 | if (json_tok_streq(buffer, t_result, "reject")) { |
| 745 | payload->errmsg = ""; |
| 746 | if (t_errmsg) |
| 747 | payload->errmsg = json_strdup(payload, buffer, t_errmsg); |
| 748 | log_debug(openingd->ld->log, |
| 749 | "openchannel hook rejects and says '%s'", |
| 750 | payload->errmsg); |
| 751 | if (t_closeto) |
| 752 | fatal("Plugin rejected openchannel but also set close_to"); |
| 753 | openchannel_hook_final(payload); |
| 754 | return false; |
| 755 | } else if (!json_tok_streq(buffer, t_result, "continue")) { |
| 756 | fatal("Plugin returned an invalid result for the " |
| 757 | "openchannel hook: %.*s", |
| 758 | t_result->end - t_result->start, buffer + t_result->start); |
| 759 | } |
| 760 | |
| 761 | /* Check for a valid 'close_to' address passed back */ |
| 762 | if (t_closeto) { |
| 763 | /* First plugin can set close_to. Log others. */ |
| 764 | if (payload->our_upfront_shutdown_script != NULL) { |
| 765 | log_broken(openingd->ld->log, |
| 766 | "openchannel hook close_to address was" |
| 767 | " already set by other plugin. Ignoring!"); |
| 768 | return true; |
| 769 | } |
| 770 | switch (json_to_address_scriptpubkey(tmpctx, chainparams, |
| 771 | buffer, t_closeto, |
| 772 | &payload->our_upfront_shutdown_script)) { |
| 773 | case ADDRESS_PARSE_UNRECOGNIZED: |
| 774 | fatal("Plugin returned an invalid response to" |
| 775 | " the openchannel.close_to hook: %.*s", |
nothing calls this directly
no test coverage detected