* Callback when a plugin answers to the htlc_accepted hook */
| 1058 | * Callback when a plugin answers to the htlc_accepted hook |
| 1059 | */ |
| 1060 | static 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); |
nothing calls this directly
no test coverage detected