| 909 | } |
| 910 | |
| 911 | static void update_knowledge_from_error(struct command *aux_cmd, |
| 912 | const char *buf, |
| 913 | const jsmntok_t *error, |
| 914 | struct attempt *attempt) |
| 915 | { |
| 916 | const jsmntok_t *tok; |
| 917 | struct onionreply *reply; |
| 918 | struct out_req *req; |
| 919 | const u8 *replymsg; |
| 920 | int index; |
| 921 | enum onion_wire failcode; |
| 922 | bool from_final; |
| 923 | const char *failcode_name, *errmsg, *description; |
| 924 | enum jsonrpc_errcode ecode; |
| 925 | |
| 926 | tok = json_get_member(buf, error, "code"); |
| 927 | if (!tok || !json_to_jsonrpc_errcode(buf, tok, &ecode)) |
| 928 | plugin_err(aux_cmd->plugin, "Invalid injectpaymentonion result '%.*s'", |
| 929 | json_tok_full_len(error), json_tok_full(buf, error)); |
| 930 | |
| 931 | if (ecode == PAY_INJECTPAYMENTONION_ALREADY_PAID) { |
| 932 | /* pay was OK when this happened, so we fake it up. */ |
| 933 | if (attempt->payment->pay_compat && attempt->payment->cmd) { |
| 934 | payment_already_paid(attempt->payment); |
| 935 | return; |
| 936 | } |
| 937 | payment_give_up(aux_cmd, attempt->payment, |
| 938 | PAY_INJECTPAYMENTONION_ALREADY_PAID, |
| 939 | "Already paid this invoice successfully"); |
| 940 | return; |
| 941 | } |
| 942 | if (ecode != PAY_INJECTPAYMENTONION_FAILED) { |
| 943 | payment_give_up(aux_cmd, attempt->payment, |
| 944 | PLUGIN_ERROR, |
| 945 | "Unexpected injectpaymentonion error %i: %.*s", |
| 946 | ecode, |
| 947 | json_tok_full_len(error), |
| 948 | json_tok_full(buf, error)); |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | tok = json_get_member(buf, error, "data"); |
| 953 | if (!tok) |
| 954 | plugin_err(aux_cmd->plugin, "Invalid injectpaymentonion result '%.*s'", |
| 955 | json_tok_full_len(error), json_tok_full(buf, error)); |
| 956 | tok = json_get_member(buf, tok, "onionreply"); |
| 957 | if (!tok) |
| 958 | plugin_err(aux_cmd->plugin, "Invalid injectpaymentonion result '%.*s'", |
| 959 | json_tok_full_len(error), json_tok_full(buf, error)); |
| 960 | reply = new_onionreply(tmpctx, take(json_tok_bin_from_hex(NULL, buf, tok))); |
| 961 | |
| 962 | replymsg = unwrap_onionreply(tmpctx, |
| 963 | attempt->shared_secrets, |
| 964 | tal_count(attempt->shared_secrets), |
| 965 | reply, |
| 966 | &index); |
| 967 | |
| 968 | /* Garbled? Blame random hop. */ |
no test coverage detected