diff --git a/lightningd/notification.c b/lightningd/notification.c index 4877805d5..841482a42 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -285,14 +285,14 @@ void notify_sendpay_failure(struct lightningd *ld, int pay_errcode, const u8 *onionreply, const struct routing_failure *fail, - char *errmsg) + const char *errmsg) { void (*serialize)(struct json_stream *, const struct wallet_payment *, int, const u8 *, const struct routing_failure *, - char *) = sendpay_failure_notification_gen.serialize; + const char *) = sendpay_failure_notification_gen.serialize; struct jsonrpc_notification *n = jsonrpc_notification_start(NULL, "sendpay_failure"); diff --git a/lightningd/notification.h b/lightningd/notification.h index 95026d08e..5ff809e22 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -63,6 +63,6 @@ void notify_sendpay_failure(struct lightningd *ld, int pay_errcode, const u8 *onionreply, const struct routing_failure *fail, - char *errmsg); + const char *errmsg); #endif /* LIGHTNING_LIGHTNINGD_NOTIFICATION_H */ diff --git a/lightningd/pay.c b/lightningd/pay.c index cd21140ab..1f99a65fc 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -191,6 +191,21 @@ void json_sendpay_fail_fields(struct json_stream *js, fail->msg); } +static const char *sendpay_errmsg_fmt(const tal_t *ctx, int pay_errcode, + const struct routing_failure *fail, + const char *details) +{ + char *errmsg; + if (pay_errcode == PAY_UNPARSEABLE_ONION) + errmsg = "Malformed error reply"; + else { + assert(fail); + errmsg = tal_fmt(ctx, "failed: %s (%s)", + onion_type_name(fail->failcode), details); + } + return errmsg; +} + /* onionreply used if pay_errcode == PAY_UNPARSEABLE_ONION */ static struct command_result * sendpay_fail(struct command *cmd, @@ -201,16 +216,8 @@ sendpay_fail(struct command *cmd, const char *details) { struct json_stream *data; - char *errmsg; - - if (pay_errcode == PAY_UNPARSEABLE_ONION) - errmsg = "Malformed error reply"; - else { - assert(fail); - errmsg = tal_fmt(tmpctx, "failed: %s (%s)", - onion_type_name(fail->failcode), - details); - } + const char *errmsg = + sendpay_errmsg_fmt(tmpctx, pay_errcode, fail, details); notify_sendpay_failure(cmd->ld, payment,