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

Function htlc_accepted_hook_deserialize

lightningd/peer_htlcs.c:1016–1192  ·  view source on GitHub ↗

* Callback when a plugin answers to the htlc_accepted hook */

Source from the content-addressed store, hash-verified

1014 * Callback when a plugin answers to the htlc_accepted hook
1015 */
1016static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *request,
1017 const char *buffer,
1018 const jsmntok_t *toks)
1019{
1020 struct route_step *rs = request->route_step;
1021 struct htlc_in *hin = request->hin;
1022 struct lightningd *ld = request->ld;
1023 struct preimage payment_preimage;
1024 const jsmntok_t *resulttok, *paykeytok, *payloadtok, *fwdtok, *extra_tlvs_tok,
1025 *invmsattok;
1026 u8 *failonion, *raw_tlvs;
1027
1028 if (!toks || !buffer)
1029 return true;
1030
1031 resulttok = json_get_member(buffer, toks, "result");
1032
1033 /* If the result is "continue" we can just return NULL since
1034 * this is the default behavior for this hook anyway */
1035 if (!resulttok) {
1036 fatal("Plugin return value does not contain 'result' key %s",
1037 json_strdup(tmpctx, buffer, toks));
1038 }
1039
1040 invmsattok = json_get_member(buffer, toks, "invoice_msat");
1041 if (invmsattok) {
1042 tal_free(request->invoice_msat);
1043 request->invoice_msat = tal(request, struct amount_msat);
1044 if (!json_to_msat(buffer, invmsattok, request->invoice_msat)) {
1045 fatal("Bad invoice_msat for htlc_accepted hook: %.*s",
1046 invmsattok->end - invmsattok->start,
1047 buffer + invmsattok->start);
1048 }
1049 }
1050
1051 extra_tlvs_tok = json_get_member(buffer, toks, "extra_tlvs");
1052 if (extra_tlvs_tok) {
1053 size_t max;
1054 struct tlv_update_add_htlc_tlvs *check_extra_tlvs;
1055
1056 raw_tlvs = json_tok_bin_from_hex(tmpctx, buffer,
1057 extra_tlvs_tok);
1058 if (!raw_tlvs)
1059 fatal("Bad custom tlvs for htlc_accepted"
1060 " hook: %.*s",
1061 extra_tlvs_tok->end - extra_tlvs_tok->start,
1062 buffer + extra_tlvs_tok->start);
1063
1064 max = tal_bytelen(raw_tlvs);
1065
1066 /* We check if the custom tlvs are still valid BOLT#1 tlvs.
1067 * As these are appended to forwarded htlcs we check for valid
1068 * update_add_htlc_tlvs (restricts to known even types).
1069 * NOTE: We may be less strict and allow unknown evens .*/
1070 const u8 *cursor = raw_tlvs;
1071 check_extra_tlvs = fromwire_tlv_update_add_htlc_tlvs(tmpctx,
1072 &cursor,
1073 &max);

Callers

nothing calls this directly

Calls 15

json_get_memberFunction · 0.85
tal_freeFunction · 0.85
tal_bytelenFunction · 0.85
tal_hexFunction · 0.85
prepend_lengthFunction · 0.85
onion_decodeFunction · 0.85
json_tok_streqFunction · 0.85
fail_in_htlcFunction · 0.85
json_to_preimageFunction · 0.85
fatalFunction · 0.70
local_fail_in_htlcFunction · 0.70

Tested by

no test coverage detected