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

Function htlc_accepted_hook_deserialize

lightningd/peer_htlcs.c:1060–1236  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1058 * Callback when a plugin answers to the htlc_accepted hook
1059 */
1060static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *request,
1061 const char *buffer,
1062 const jsmntok_t *toks)
1063{
1064 struct route_step *rs = request->route_step;
1065 struct htlc_in *hin = request->hin;
1066 struct lightningd *ld = request->ld;
1067 struct preimage payment_preimage;
1068 const jsmntok_t *resulttok, *paykeytok, *payloadtok, *fwdtok, *extra_tlvs_tok,
1069 *invmsattok;
1070 u8 *failonion, *raw_tlvs;
1071
1072 if (!toks || !buffer)
1073 return true;
1074
1075 resulttok = json_get_member(buffer, toks, "result");
1076
1077 /* If the result is "continue" we can just return NULL since
1078 * this is the default behavior for this hook anyway */
1079 if (!resulttok) {
1080 fatal("Plugin return value does not contain 'result' key %s",
1081 json_strdup(tmpctx, buffer, toks));
1082 }
1083
1084 invmsattok = json_get_member(buffer, toks, "invoice_msat");
1085 if (invmsattok) {
1086 tal_free(request->invoice_msat);
1087 request->invoice_msat = tal(request, struct amount_msat);
1088 if (!json_to_msat(buffer, invmsattok, request->invoice_msat)) {
1089 fatal("Bad invoice_msat for htlc_accepted hook: %.*s",
1090 invmsattok->end - invmsattok->start,
1091 buffer + invmsattok->start);
1092 }
1093 }
1094
1095 extra_tlvs_tok = json_get_member(buffer, toks, "extra_tlvs");
1096 if (extra_tlvs_tok) {
1097 size_t max;
1098 struct tlv_update_add_htlc_tlvs *check_extra_tlvs;
1099
1100 raw_tlvs = json_tok_bin_from_hex(tmpctx, buffer,
1101 extra_tlvs_tok);
1102 if (!raw_tlvs)
1103 fatal("Bad custom tlvs for htlc_accepted"
1104 " hook: %.*s",
1105 extra_tlvs_tok->end - extra_tlvs_tok->start,
1106 buffer + extra_tlvs_tok->start);
1107
1108 max = tal_bytelen(raw_tlvs);
1109
1110 /* We check if the custom tlvs are still valid BOLT#1 tlvs.
1111 * As these are appended to forwarded htlcs we check for valid
1112 * update_add_htlc_tlvs (restricts to known even types).
1113 * NOTE: We may be less strict and allow unknown evens .*/
1114 const u8 *cursor = raw_tlvs;
1115 check_extra_tlvs = fromwire_tlv_update_add_htlc_tlvs(tmpctx,
1116 &cursor,
1117 &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