| 29 | }; |
| 30 | |
| 31 | static struct command_result *WARN_UNUSED_RESULT |
| 32 | fail_invreq_level(struct command *cmd, |
| 33 | const struct invreq *invreq, |
| 34 | enum log_level l, |
| 35 | const char *fmt, va_list ap) |
| 36 | { |
| 37 | char *full_fmt, *msg; |
| 38 | struct tlv_onionmsg_payload *payload; |
| 39 | struct tlv_invoice_error *err; |
| 40 | |
| 41 | full_fmt = tal_fmt(tmpctx, "Failed invoice_request"); |
| 42 | if (invreq->invreq) { |
| 43 | tal_append_fmt(&full_fmt, " %s", |
| 44 | invrequest_encode(tmpctx, invreq->invreq)); |
| 45 | if (invreq->invreq->offer_id) |
| 46 | tal_append_fmt(&full_fmt, " for offer %s", |
| 47 | type_to_string(tmpctx, struct sha256, |
| 48 | invreq->invreq->offer_id)); |
| 49 | } |
| 50 | tal_append_fmt(&full_fmt, ": %s", fmt); |
| 51 | |
| 52 | msg = tal_vfmt(tmpctx, full_fmt, ap); |
| 53 | plugin_log(cmd->plugin, l, "%s", msg); |
| 54 | |
| 55 | /* Don't send back internal error details. */ |
| 56 | if (l == LOG_BROKEN) |
| 57 | msg = "Internal error"; |
| 58 | |
| 59 | err = tlv_invoice_error_new(cmd); |
| 60 | /* Remove NUL terminator */ |
| 61 | err->error = tal_dup_arr(err, char, msg, strlen(msg), 0); |
| 62 | /* FIXME: Add suggested_value / erroneous_field! */ |
| 63 | |
| 64 | payload = tlv_onionmsg_payload_new(tmpctx); |
| 65 | payload->invoice_error = tal_arr(payload, u8, 0); |
| 66 | towire_tlv_invoice_error(&payload->invoice_error, err); |
| 67 | return send_onion_reply(cmd, invreq->reply_path, payload); |
| 68 | } |
| 69 | |
| 70 | static struct command_result *WARN_UNUSED_RESULT PRINTF_FMT(3,4) |
| 71 | fail_invreq(struct command *cmd, |
no test coverage detected