* Callback when a plugin answers to the htlc_accepted hook */
| 896 | * Callback when a plugin answers to the htlc_accepted hook |
| 897 | */ |
| 898 | static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *request, |
| 899 | const char *buffer, |
| 900 | const jsmntok_t *toks) |
| 901 | { |
| 902 | struct route_step *rs = request->route_step; |
| 903 | struct htlc_in *hin = request->hin; |
| 904 | struct lightningd *ld = request->ld; |
| 905 | struct preimage payment_preimage; |
| 906 | const jsmntok_t *resulttok, *paykeytok, *payloadtok, *fwdtok; |
| 907 | u8 *payload, *failonion; |
| 908 | |
| 909 | if (!toks || !buffer) |
| 910 | return true; |
| 911 | |
| 912 | resulttok = json_get_member(buffer, toks, "result"); |
| 913 | |
| 914 | /* If the result is "continue" we can just return NULL since |
| 915 | * this is the default behavior for this hook anyway */ |
| 916 | if (!resulttok) { |
| 917 | fatal("Plugin return value does not contain 'result' key %s", |
| 918 | json_strdup(tmpctx, buffer, toks)); |
| 919 | } |
| 920 | |
| 921 | payloadtok = json_get_member(buffer, toks, "payload"); |
| 922 | if (payloadtok) { |
| 923 | payload = json_tok_bin_from_hex(rs, buffer, payloadtok); |
| 924 | if (!payload) |
| 925 | fatal("Bad payload for htlc_accepted" |
| 926 | " hook: %.*s", |
| 927 | payloadtok->end - payloadtok->start, |
| 928 | buffer + payloadtok->start); |
| 929 | tal_free(request->payload); |
| 930 | tal_free(rs->raw_payload); |
| 931 | |
| 932 | rs->raw_payload = prepend_length(rs, take(payload)); |
| 933 | request->payload = onion_decode(request, rs, |
| 934 | hin->blinding, &hin->blinding_ss, |
| 935 | ld->accept_extra_tlv_types, |
| 936 | &request->failtlvtype, |
| 937 | &request->failtlvpos); |
| 938 | } else |
| 939 | payload = NULL; |
| 940 | |
| 941 | fwdtok = json_get_member(buffer, toks, "forward_to"); |
| 942 | if (fwdtok) { |
| 943 | tal_free(request->fwd_channel_id); |
| 944 | request->fwd_channel_id = tal(request, struct channel_id); |
| 945 | if (!json_to_channel_id(buffer, fwdtok, |
| 946 | request->fwd_channel_id)) { |
| 947 | fatal("Bad forward_to for htlc_accepted" |
| 948 | " hook: %.*s", |
| 949 | fwdtok->end - fwdtok->start, |
| 950 | buffer + fwdtok->start); |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | if (json_tok_streq(buffer, resulttok, "continue")) { |
| 955 | return true; |
nothing calls this directly
no test coverage detected