MCPcopy Create free account
hub / github.com/ElementsProject/lightning / openchannel_hook_deserialize

Function openchannel_hook_deserialize

lightningd/opening_control.c:768–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
openchannel_hook_finalFunction · 0.85
tal_hexFunction · 0.85
json_to_satFunction · 0.85
fatalFunction · 0.70
json_strdupFunction · 0.50
json_to_u32Function · 0.50
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected