| 753 | } |
| 754 | |
| 755 | static bool |
| 756 | openchannel_hook_deserialize(struct openchannel_hook_payload *payload, |
| 757 | const char *buffer, |
| 758 | const jsmntok_t *toks) |
| 759 | { |
| 760 | struct subd *openingd = payload->openingd; |
| 761 | |
| 762 | /* already rejected by prior plugin hook in the chain */ |
| 763 | if (payload->errmsg != NULL) |
| 764 | return true; |
| 765 | |
| 766 | if (!toks || !buffer) |
| 767 | return true; |
| 768 | |
| 769 | const jsmntok_t *t_result = json_get_member(buffer, toks, "result"); |
| 770 | const jsmntok_t *t_errmsg = json_get_member(buffer, toks, "error_message"); |
| 771 | const jsmntok_t *t_closeto = json_get_member(buffer, toks, "close_to"); |
| 772 | const jsmntok_t *t_mindepth = json_get_member(buffer, toks, "mindepth"); |
| 773 | const jsmntok_t *t_reserve = json_get_member(buffer, toks, "reserve"); |
| 774 | |
| 775 | if (!t_result) |
| 776 | fatal("Plugin returned an invalid response to the" |
| 777 | " openchannel hook: %.*s", |
| 778 | toks[0].end - toks[0].start, buffer + toks[0].start); |
| 779 | |
| 780 | /* reject */ |
| 781 | if (json_tok_streq(buffer, t_result, "reject")) { |
| 782 | payload->errmsg = ""; |
| 783 | if (t_errmsg) |
| 784 | payload->errmsg = json_strdup(payload, buffer, t_errmsg); |
| 785 | log_debug(openingd->ld->log, |
| 786 | "openchannel hook rejects and says '%s'", |
| 787 | payload->errmsg); |
| 788 | if (t_closeto) |
| 789 | fatal("Plugin rejected openchannel but also set close_to"); |
| 790 | openchannel_hook_final(payload); |
| 791 | return false; |
| 792 | } else if (!json_tok_streq(buffer, t_result, "continue")) { |
| 793 | fatal("Plugin returned an invalid result for the " |
| 794 | "openchannel hook: %.*s", |
| 795 | t_result->end - t_result->start, buffer + t_result->start); |
| 796 | } |
| 797 | |
| 798 | /* Check for a valid 'close_to' address passed back */ |
| 799 | if (t_closeto) { |
| 800 | /* First plugin can set close_to. Log others. */ |
| 801 | if (payload->our_upfront_shutdown_script != NULL) { |
| 802 | log_broken(openingd->ld->log, |
| 803 | "openchannel hook close_to address was" |
| 804 | " already set by other plugin. Ignoring!"); |
| 805 | return true; |
| 806 | } |
| 807 | switch (json_to_address_scriptpubkey(tmpctx, chainparams, |
| 808 | buffer, t_closeto, |
| 809 | &payload->our_upfront_shutdown_script)) { |
| 810 | case ADDRESS_PARSE_UNRECOGNIZED: |
| 811 | fatal("Plugin returned an invalid response to" |
| 812 | " the openchannel.close_to hook: %.*s", |
nothing calls this directly
no test coverage detected