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