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