| 20 | }; |
| 21 | |
| 22 | static struct command_result *WARN_UNUSED_RESULT |
| 23 | fail_inv_level(struct command *cmd, |
| 24 | const struct inv *inv, |
| 25 | enum log_level l, |
| 26 | const char *fmt, va_list ap) |
| 27 | { |
| 28 | char *full_fmt, *msg; |
| 29 | struct tlv_onionmsg_payload *payload; |
| 30 | struct tlv_invoice_error *err; |
| 31 | |
| 32 | full_fmt = tal_fmt(tmpctx, "Failed invoice"); |
| 33 | if (inv->inv) { |
| 34 | tal_append_fmt(&full_fmt, " %s", |
| 35 | invoice_encode(tmpctx, inv->inv)); |
| 36 | if (inv->inv->offer_id) |
| 37 | tal_append_fmt(&full_fmt, " for offer %s", |
| 38 | type_to_string(tmpctx, struct sha256, |
| 39 | inv->inv->offer_id)); |
| 40 | } |
| 41 | tal_append_fmt(&full_fmt, ": %s", fmt); |
| 42 | |
| 43 | msg = tal_vfmt(tmpctx, full_fmt, ap); |
| 44 | plugin_log(cmd->plugin, l, "%s", msg); |
| 45 | |
| 46 | /* Only reply if they gave us a path */ |
| 47 | if (!inv->reply_path) |
| 48 | return command_hook_success(cmd); |
| 49 | |
| 50 | /* Don't send back internal error details. */ |
| 51 | if (l == LOG_BROKEN) |
| 52 | msg = "Internal error"; |
| 53 | |
| 54 | err = tlv_invoice_error_new(cmd); |
| 55 | /* Remove NUL terminator */ |
| 56 | err->error = tal_dup_arr(err, char, msg, strlen(msg), 0); |
| 57 | /* FIXME: Add suggested_value / erroneous_field! */ |
| 58 | |
| 59 | payload = tlv_onionmsg_payload_new(tmpctx); |
| 60 | payload->invoice_error = tal_arr(payload, u8, 0); |
| 61 | towire_tlv_invoice_error(&payload->invoice_error, err); |
| 62 | return send_onion_reply(cmd, inv->reply_path, payload); |
| 63 | } |
| 64 | |
| 65 | static struct command_result *WARN_UNUSED_RESULT |
| 66 | fail_inv(struct command *cmd, |
no test coverage detected